2023-06-02 15:52:22 +02:00
#!/usr/bin/env bash
2022-04-28 23:36:42 +02:00
if [ " $TERM " = = 'xterm-kitty' ] ; then
alias ssh = 'kitty +kitten ssh'
2023-05-19 15:13:26 +02:00
alias diff = 'kitty +kitten diff'
2022-04-28 23:36:42 +02:00
fi
2023-05-14 12:16:44 +02:00
DEFAULT_RSYNC = '--info=ALL --recursive --delay-updates --human-readable --links --hard-links --perms'
2022-04-28 23:36:42 +02:00
2022-05-12 13:26:00 +02:00
alias l = 'ls -l -v --all --human-readable --classify --group-directories-first' # -lvahF --group-directories-first
2023-05-19 18:33:49 +02:00
alias lt = = 'l --time-style=long-iso'
2022-04-28 23:36:42 +02:00
alias r = 'reset'
alias ..= 'cd ..'
alias refresh_bashrc = '. ~/.bashrc' # alternatively: 'source ~/.bashrc'
alias rsync_default = " rsync $DEFAULT_RSYNC --checksum "
2022-08-20 18:54:44 +02:00
# source /usr/share/bash-completion/completions/rsync
# complete -F _rsync rsync_default
2022-04-28 23:36:42 +02:00
alias rsync_backup = " rsync $DEFAULT_RSYNC --checksum --times --group --owner --delete "
2023-05-27 18:11:04 +02:00
alias rsync_move = " rsync $DEFAULT_RSYNC --checksum --remove-source-files "
2022-04-28 23:36:42 +02:00
alias rsync_update = " rsync $DEFAULT_RSYNC --update --times "
2022-08-20 18:54:44 +02:00
alias rsync_copy = " rsync $DEFAULT_RSYNC --ignore-times "
2023-07-30 09:52:07 +02:00
alias copy_link = 'cp --no-dereference --recursive --preserve=all --link' # not --force to make it optional
2022-04-28 23:36:42 +02:00
alias off = 'systemctl poweroff'
alias nnn = 'nnn -dHrR'
alias nn = 'n -dHrR'
alias c = 'clear'
2022-06-05 01:54:51 +02:00
alias sort_dirs_by_size = 'du --block-size=1K --human-readable --max-depth=1 | sort --human-numeric-sort --reverse' # 'du -kh --max-depth=1 | sort -hr'
2022-06-18 12:59:17 +02:00
alias sd = 'sudo ' # alias, so sudo can use aliases: "If the last character of the alias value is a blank, then the next command word following the alias is also checked for alias expansion."
2022-06-21 23:08:47 +02:00
alias mountdrive = 'udisksctl mount -b'
alias unmountdrive = 'udisksctl unmount -b'
alias fssizes = 'df -kh --output=size,used,avail,pcent,target | sort -hr'
alias dirsizes = 'du -kh --apparent-size --max-depth=1 | sort -hr'
2023-07-30 09:52:07 +02:00
# sed -ie 's/Beispiel/Ersetzung/' *.xml
# sed -Eie 's/(Beispiel)/\1Anhang/' *.xml
2023-08-20 14:49:07 +02:00
alias start_x11_vnc = " sudo x11vnc -auth guess -forever -loop -noxdamage -repeat -rfbauth $HOME /.vnc/passwd -rfbport 5900 -shared "
2023-07-30 09:52:07 +02:00
rsyncLink( ) {
source = $1 ;
linkSource = " $( realpath $source ) " ;
linkSource = ${ linkSource %/ } ; # cut off trailing "/"
shift;
dest = $1 ;
shift;
rsync $DEFAULT_RSYNC --one-file-system --link-dest= $linkSource $source $dest $* ;
}
2022-05-12 13:26:00 +02:00
2023-07-06 12:51:55 +02:00
updateSystem( ) {
executeAndNotify " doUpdateSystem $1 " "system updated" "system update failed"
}
doUpdateSystem( ) {
updatePackages $1 ;
updateFlatpak $1 ;
}
2023-06-02 15:52:22 +02:00
updateFlatpak( ) {
noconfirm =
if [ [ $1 = = "-y" ] ] ; then
noconfirm = "--assumeyes" ;
fi
executeAndNotify " doUpdateFlatpak $noconfirm " "flatpaks updated" "flatpak update failed" ;
}
doUpdateFlatpak( ) {
flatpak update $1 ;
2023-07-06 12:51:55 +02:00
flatpak remove --unused $1 ;
2023-06-02 15:52:22 +02:00
}
2022-05-12 13:26:00 +02:00
# executes command and notifies upon failure
execute( ) {
dir = " $( pwd ) " ;
dir = ${ dir ##*/ } ;
2023-07-06 12:51:55 +02:00
if [ [ -n " $2 " ] ] ; then
errLog = $2 ;
2022-05-12 13:26:00 +02:00
else
2023-07-06 12:51:55 +02:00
errLog = " execution of \" $1 \" failed " ;
2022-05-12 13:26:00 +02:00
fi
if ! $1 ; then
notifyError " $dir : $errLog " ;
return 1;
fi
}
# executes command and notifies upon success or failure
executeAndNotify ( ) {
dir = " $( pwd ) " ;
2023-07-30 09:52:07 +02:00
dir = ${ dir ##*/ } ; # cut off previous path (/path/to/foo.txt -> foo.txt)
2023-07-06 12:51:55 +02:00
if [ [ -n " $2 " ] ] ; then
winLog = $2 ;
2022-05-12 13:26:00 +02:00
else
2023-07-06 12:51:55 +02:00
winLog = " execution of \" $1 \" succeeded " ;
2022-05-12 13:26:00 +02:00
fi
if ! execute " $1 " " $3 " ; then # arguments in quotes so they are interpreted as ONE argument each by execute()
return 1;
fi
2023-07-06 12:51:55 +02:00
notifyInfo " $dir : $winLog " ;
2022-05-12 13:26:00 +02:00
}
# find file but don't print errors (e.g. can't access directory etc.)
finds ( ) {
2023-07-06 12:51:55 +02:00
find $* 2>/dev/null;
2023-05-14 12:50:14 +02:00
}
2022-05-12 13:26:00 +02:00
# sends a desktop-notification with an icon signalling an error
notifyError ( ) {
2023-07-06 12:51:55 +02:00
notify-send " $1 " --icon= data-warning;
2022-05-12 13:26:00 +02:00
}
# sends a desktop-notification with an icon signalling a simple information
notifyInfo ( ) {
2023-07-06 12:51:55 +02:00
notify-send " $1 " --icon= preferences-desktop-notification;
2022-05-12 13:26:00 +02:00
}