2025.03.10 23:27:11 (alma.cmoser.eu)

This commit is contained in:
Christian Moser 2025-03-10 23:27:11 +01:00
parent 01ba953e1c
commit e7f791f9f0
Failed to extract signature
7 changed files with 469 additions and 1 deletions

View File

@ -1,3 +1,22 @@
# bashrcd # bashrcd
Scripts for ~/.basshrc.d Scripts for *~/.basshrc.d*
## Installation
Clone this repository to ~/.bashrc.d.
```
git clone https://git.mydevel.at/chris/bashrcd.git ~/.bashrc.d
```
Add following code to your ~/.bashrc file:
```
if [ -d ~/.bashrc.d ]; then
for i in `ls ~/.bashrc.d/*.sh ~/.bashrc.d/*.bash`; do
[ -f "$i" ] && . "$i"
done
fi
```

180
git.sh Normal file
View File

@ -0,0 +1,180 @@
# vim: syn=sh ts=4 sts=4 sw=4 smartindent autoindent expandtab ff=unix
git-initialize() {
USAGE="git-initialize -u USER -e EMAIL [-b DEFAULT_BRANCH] [-S SSH_KEY] [-s SSH_COMMAND]"
args=$( getopt "b:e:s:S:u:" $* )
if [ $? -ne 0 ]; then
echo "$USAGE"
return 2
fi
local default_branch=main
local user="$USER"
local email=""
local ssh_key=""
local ssh_command=""
set -- $args
while :; do
case "$1" in
-b)
local default_branch="$2"
shift; shift
;;
-e)
local email="$2"
shift; shift
;;
-S)
local ssh_key="$2"
shift; shift
;;
-s)
local ssh_command="$2"
shift; shift
;;
-u)
local user="$2"
shift; shift
;;
--)
shift; break
;;
esac
done
if [ -z "$email" ]; then
read -p "Email: " __git_email__
local email=$__git_email__
unset __git_email__
fi
signingkey=$( gpgsm --list-secret-keys | egrep '(key usage|ID)' | grep -v CertifyID |grep -B 1 digitalSignature | awk '/ID/ {print $2}' )
git config --global user.name "$user"
git config --global user.email "$email"
git config --global init.defaultBranch "$default_branch"
if [ -n "$ssh_command" ]; then
git config --global core.sshCommand "$ssh_command"
elif [ -n "$ssh_key" ]; then
git config --global core.sshCommand "ssh -i \"$ssh_key\""
fi
}
git-init-smime() {
USAGE="git-init-smime [-cgh] CERT_ID"
args=$( getopt "cCgh" $* )
if [ $? -ne 0 ]; then
echo $USAGE
return 2
fi
set -- $args
local sign_commits=""
local global=""
while :; do
case "$1" in
-C)
local sign_commits=NO
shift
;;
-c)
local sign_commits=YES
shift
;;
-g)
local global="--global"
shift
;;
-h)
cat << EOF
git-init-smime HELP
SYNOPSIS
$USAGE
OPTIONS
-C Disable automatic signing of commits.
[DEFAULT: no change]
-c Enable automatic signing of commits.
[DEFAULT: no change]
-g Set global GIT options.
-h Print this help message and exit.
EOF
shift; return
;;
--)
shift; break
;;
esac
done
if [ -z "$1" ]; then
echo "No CERT_ID given! Obtain the ID with \"gpgsm --list-secret-keys\"" >&2
echo "$USAGE"
return 2
fi
git config $global user.signingkey "$1"
git config $global gpg.format x509
if [ "$sign_commits" = "YES" ]; then
git config $global commit.gpgsign true
elif [ "$sign_commits" = "NO" ]; then
git config $global commit.gpgsign false
fi
}
git-init-gpg() {
echo TODO
}
git-commit-timestamp() {
winver=$(which winver)
if [ -n "$WINVER" ]; then
local hostname="$(hostname)"
else
local hostname="$(hostname)"
fi
local msg="$(date "+%Y.%m.%d %H:%M:%S") ($hostname)"
git commit -m "$msg"
}
git-push-all() {
local branch="$(git branch --show-current)"
for __remote in $(git remote show); do
git push "$__remote" "$branch"
done
unset __remote
}
git-tags-push() {
for remote in $(git remote show); do
git push --tags "$remote"
done
}
git-mktag() {
if [ $# -lt 1 ]; then
echo "No tags given!" >&2
echo "SYNOPSIS:"
echo " git-mkttag <TAG_NAME> ..."
fi
while [ $# -gt 0 ]; do
git tag "$1"
shift
done
git-tags-push
}
# ALIASES
alias gitdc='git-commit-timestamp'
alias gpa='git-push-all'
alias gittp='git-tags-push'
alias gitmt='git-mktag'
alias gitcb='git branch --show-current'

14
password-store.sh Normal file
View File

@ -0,0 +1,14 @@
# vim: syn=sh ts=4 sts=4 sw=4 smartindent expandtab autoindent ff=unix
if [ -n "`which pass`" ]; then
pass-push-all() {
for __pass_remote__ in $(pass git remote); do
pass git push $__pass_remote__ main
done
}
alias 'pass-pa'='pass-push-all'
alias passpa='pass-push-all'
fi

38
ps1.bash Normal file
View File

@ -0,0 +1,38 @@
_ps_color_reset='\[\e[0m\]'
_ps_color_user='\[\e[01;38;5;118m\]'
_ps_color_host='\[\e[01;38;5;35m\]'
_ps_color_msystem='\[\e[01;38;5;147m\]'
_ps_color_path='\[\e[01;38;5;226m\]'
_ps_color_git='\[\e[01;38;5;75m\]'
_ps_color_date='\[\e[01;38;5;015m\]'
_ps_color_symbol='\[\e[01;38;5;187m\]'
_ps1_git_branch() {
branch="$(git branch --show-current 2>/dev/null)"
if [ -n "$branch" ]; then
echo "${branch}"
else
echo "---"
fi
}
PROMPT_COMMAND='PS1_CMD1=$(_ps1_git_branch);PS1_CMD2=$(date "+%d.%m.%Y %H:%M:%S")'
if [ -n "$MSYSTEM" ]; then
export PS1='\[\e]0;\w\a\]\n'"$_ps_color_user"'${USER#DESKTOP+}'"$_ps_color_symbol"'@'"$_ps_color_host"'\h '"$_ps_color_msystem"'$MSYSTEM '"$_ps_color_path"'\w'"$_ps_color_symbol"'<'"$_ps_color_git"'${PS1_CMD1}'"$_ps_color_symbol"'>\n['"$_ps_color_date"'${PS1_CMD2}'"$_ps_color_symbol"']$ '"$_ps_color_reset"
else
export PS1='\[\e]0;\w\a\]\n'"$_ps_color_user"'\u'"$_ps_color_symbol"'@'"$_ps_color_host"'\H '"$_ps_color_path"'\w'"$_ps_color_symbol"'<'"$_ps_color_git"'${PS1_CMD1}'"$_ps_color_symbol"'>\n['"$_ps_color_date"'${PS1_CMD2}'"$_ps_color_symbol"']$ '"$_ps_color_reset"
fi
unset _ps_color_reset
unset _ps_color_user
unset _ps_color_host
unset _ps_color_msystem
unset _ps_color_path
unset _ps_color_git
unset _ps_color_date
unset _ps_color_symbol

162
ssh.sh Normal file
View File

@ -0,0 +1,162 @@
# vim: syn=sh ts=4 sts=4 sw=4 autoindent smartindent expandtab ff=unix
ssh-init-host() {
scp -r ${HOME}/.ssh $1:.ssh
ssh $1 << EOF
for i in \$(find .ssh); do
if [ -d "\$i" ]; then
chmod 0700 "\$i"
else
chmod 0600 "\$i"
fi
done
exit
EOF
}
ssh-wait() {
local usage="ssh-wait [-h] |[-n <RETRIES> -t <TIMEOUT>] USER@HOST"
local usage="ssh-wait [-h] |[-n <RETRIES> -t <TIMEOUT>] USER@HOST"
local n=0
local timeout=5
local args=`getopt "hn:t:" $*`
if [ $? -ne 0 ]; then
echo "USAGE: $usage"
return 2
fi
set -- $args
while :; do
case "$1" in
-h)
cat << EOF
ssh-wait
Wait for an ssh connection to establish.
SYNOPSIS
$usage
OPTIONS
-h Print this help an exit
-n RETRIES Number of retries. (default: 0)
Set to "0" for infinite retries.
-t TIMEOUT Timeout in seconds between retries. (default: 5)
EOF
return 0
;;
-n)
local n=$2
shift; shift
;;
-t)
local timeout=$2
shift; shift
;;
--)
shift
break
;;
esac
done
if [ $# -lt 1 ]; then
echo "No HOST to connect given!" >&2
return 2
fi
if [ $# -gt 1 ]; then
echo "WARNING too many hosts to connect given! Using only the first one!" >&2
fi
local count=0
echo "Trying to connect to \"$1\" ..."
while [ $n -eq 0 -o $count -lt $n ]; do
local count=$(( $count + 1))
echo "exit" | ssh "$1"
if [ $? -eq 0 ]; then
echo "CONNECTION ESTABLISHED!"
return 0
fi
echo "CONNECTING FAILED!"
if [ $n -eq 0 -o $n -lt $count ]; then
echo "Retrying to connect ..."
sleep $timeout
fi
done
return 1
}
ssh-wait-connect() {
local usage="ssh-wait-connect [-h] |[-n <RETRIES> -t <TIMEOUT>] USER@HOST"
local n=0
local timeout=5
local args=`getopt "hn:t:" $*`
if [ $? -ne 0 ]; then
echo "USAGE: $usage"
return 2
fi
set -- $args
while :; do
case "$1" in
-h)
cat << EOF
ssh-wait
Wait for an ssh connection to establish.
SYNOPSIS
$usage
OPTIONS
-h Print this help an exit
-n RETRIES Number of retries. (default: 0)
Set to "0" for infinite retries.
-t TIMEOUT Timeout in seconds between retries. (default: 5)
EOF
return 0
;;
-n)
local n=$2
shift; shift
;;
-t)
local timeout=$2
shift; shift
;;
--)
shift
break
;;
esac
done
if [ $# -lt 1 ]; then
echo "No HOST to connect given!" >&2
return 2
fi
if [ $# -gt 1 ]; then
echo "WARNING too many hosts to connect given! Using only the first one!" >&2
fi
local count=0
echo "Trying to connect to \"$1\" ..."
while [ $n -eq 0 -o $count -lt $n ]; do
local count=$(( $count + 1))
ssh "$1"
if [ $? -ne 0 ]; then
echo "CONNECTING FAILED!"
if [ $n -eq 0 -o $n -lt $count ]; then
echo "Retrying to connect ..."
sleep $timeout
fi
else
return 0
fi
done
return 1
}

41
symfony.sh Normal file
View File

@ -0,0 +1,41 @@
# vim: syn=sh ts=4 sts=4 sw=4 smartindent autoindent expandtab
symfony-make-apikey() {
if [ $# -gt 0 ]; then
local key_len="$1"
else
local key_len=60
fi
api_key=$(python << EOF
import random
import struct
import sys
import os
sys.stdin.reconfigure(encoding='utf-8')
sys.stdout.reconfigure(encoding='utf-8')
seedstr = os.urandom(8)
seed = struct.unpack('@Q',seedstr)[0]
randchars='1234567890abcdefghijklmnopqrstABCDEFGHIJKLMNOPQRST*!+-_#$%&/([]){}?'
rstr=""
random.seed(seed)
for i in range($key_len):
rstr+=randchars[random.randrange(0,len(randchars),1)]
print(rstr)
EOF
)
if [ -f /dev/clipboard ]; then
echo -n "$api_key" > /dev/clipborad
fi
echo "$api_key"
}

14
vim.sh Normal file
View File

@ -0,0 +1,14 @@
if [ -n "$( which nvim )" ]; then
alias vim=nvim
alias edit=nvim
alias svim='sudo nvim'
elif [ -n "$( which vim )" ]; then
alias nvim=vim
alias edit=vim
alias svim='sudo vim'
else
alias nvim=nano
alias edit=nano
alias vim=nano
alias svim='sudo nano'
fi