config/shell: little helper fixes

- add xtrace
- fix cd with arg number != 1
This commit is contained in:
xeruf 2021-12-11 02:01:01 +01:00
parent 2c0e42dfa4
commit f8da1fe449
3 changed files with 23 additions and 14 deletions

View File

@ -31,7 +31,7 @@ cd() {
dir=$(fd --no-ignore --glob "$1*" "$DATA" --maxdepth 2 --type d --max-results 1) dir=$(fd --no-ignore --glob "$1*" "$DATA" --maxdepth 2 --type d --max-results 1)
test -n "$dir" && cd "$dir" test -n "$dir" && cd "$dir"
else else
builtin cd "$1" && builtin cd "$@" &&
command ls --literal --file-type --color=always --format=vertical -U -w $COLUMNS | command ls --literal --file-type --color=always --format=vertical -U -w $COLUMNS |
#pr -4 -l1 -W $COLUMNS -S" " | #pr -4 -l1 -W $COLUMNS -S" " |
head -3 head -3

View File

@ -33,6 +33,12 @@ alias h='help'
compdef help=man compdef help=man
alias info='info --vi-keys' alias info='info --vi-keys'
xtrace() {
set -x
"$@"
set +x
}
# Shows source code for command, resolving nested aliases # Shows source code for command, resolving nested aliases
wh() { wh() {
res=$(which "$@") res=$(which "$@")
@ -164,7 +170,7 @@ alias kc='kdeconnect-cli --refresh && kdeconnect-cli --list-devices'
# Shortcuts # Shortcuts
alias logoff="loginctl terminate-user $USER" alias logoff="loginctl terminate-user $USER"
alias calc='rlwrap -a bc -l' alias calb='rlwrap -a bc -l'
alias dt='python -c "import time;print(time.asctime(time.localtime()))"' alias dt='python -c "import time;print(time.asctime(time.localtime()))"'
# Process # Process
@ -175,7 +181,11 @@ alias lst='( last; last -f /var/log/wtmp.1 ) | grep -v "pts/" | tac | less +G'
# Remote # Remote
alias delta="sc restart openvpn-client@deltaPeak.service" alias delta="sc restart openvpn-client@deltaPeak.service"
alias sshl="lemonade server -allow 127.0.0.1 & kitty +kitten ssh -R 2489:127.0.0.1:2489" sshl() {
lemonade server -allow 127.0.0.1 &
ssh-copy-id -i "$(ssh -G "$1" | grep "^identityfile " | head -1 | cut -d " " -f2- | sed "s|^~|$HOME|")" "$1"
kitty +kitten ssh -R 2489:127.0.0.1:2489 "$@"
}
# Listen to loopback of mic # Listen to loopback of mic
alias listen='pactl load-module module-loopback; echo "Press Enter to stop"; read; pactl unload-module module-loopback' alias listen='pactl load-module module-loopback; echo "Press Enter to stop"; read; pactl unload-module module-loopback'
@ -206,7 +216,6 @@ alias hx='sudo hexedit --maximize --color'
# Paginated hexyl # Paginated hexyl
hex() { hexyl "$@" | "${PAGER:-less}" } hex() { hexyl "$@" | "${PAGER:-less}" }
alias dic="cat $XDG_DATA_HOME/dictcc/dict.txt | sed '/#/d;/&/d;/^$/d' | fzf --tiebreak=length --bind='alt-bspace:clear-query'" alias dic="cat $XDG_DATA_HOME/dictcc/dict.txt | sed '/#/d;/&/d;/^$/d' | fzf --tiebreak=length --bind='alt-bspace:clear-query'"
alias dict="rlwrap rdictcc -d $XDG_DATA_HOME/dictcc" alias dict="rlwrap rdictcc -d $XDG_DATA_HOME/dictcc"
alias dictu="dict -i $XDG_DATA_HOME/dictcc/dict.txt" alias dictu="dict -i $XDG_DATA_HOME/dictcc/dict.txt"
@ -282,8 +291,8 @@ fi
lowercase_transliterate="y/A-Z /a-z-/" lowercase_transliterate="y/A-Z /a-z-/"
which perl-rename >/dev/null && which perl-rename >/dev/null &&
alias lowercase="perl-rename -iv '$lowercase_transliterate'" || alias lowercase="perl-rename -iv '$lowercase_transliterate'" ||
alias lowercase="rename -iv '$lowercase_transliterate'" alias lowercase="rename -iv '$lowercase_transliterate'"
# rsync directory properly - suffix both dirs with / to act on contents # rsync directory properly - suffix both dirs with / to act on contents
alias rcn='rsync -v --recursive --human-readable --links --dry-run' alias rcn='rsync -v --recursive --human-readable --links --dry-run'
@ -340,12 +349,12 @@ mkcd() {
# Other stuff {{{1 # Other stuff {{{1
umoul() { umoul() {
arg="${1:-$PWD}" arg="${1:-$PWD}"
mountpoint="$(test -d "$arg" && realpath "$arg" || echo "${XDG_RUNTIME_DIR}/mnt/$arg")" mountpoint="$(test -d "$arg" && realpath "$arg" || echo "${XDG_RUNTIME_DIR}/mnt/$arg")"
mountpoint "$mountpoint" 2>/dev/null || test -b "$mountpoint" || mountpoint "$mountpoint" 2>/dev/null || test -b "$mountpoint" ||
mountpoint="$(mount --show-labels | grep "$arg" | cut -d' ' -f3)" mountpoint="$(mount --show-labels | grep "$arg" | cut -d' ' -f3)"
case "$PWD" in ("$mountpoint"*) cd "$(dirname $mountpoint)";; esac case "$PWD" in ("$mountpoint"*) cd "$(dirname $mountpoint)";; esac
moul -u "$mountpoint" moul -u "$mountpoint"
} }
resetdocker() { resetdocker() {

View File

@ -5,13 +5,13 @@ for f in "$@"
do do
test -w "$f" && elevate="" || elevate=sudo test -w "$f" && elevate="" || elevate=sudo
if test -d "$f"; then if test -d "$f"; then
find "$f" -maxdepth 4 -not -name ".stfolder" -empty -printf "Removing empty %p\n" -delete
if test -e "$f/.git" || test -e "$f/packed-refs" if test -e "$f/.git" || test -e "$f/packed-refs"
then echo -n "Force delete git project $f? " then echo -n "Force delete git project $f? "
read answer read answer
test "$answer" = "y" && test "$answer" = "y" &&
$elevate rm -rf "$f" $elevate rm -rf "$f"
else find "$f" -maxdepth 4 -not -name ".stfolder" -empty -printf "Removing empty %p\n" -delete else test -e "$f" &&
test -e "$f" &&
echo -n "$f ($(ls -A $f | head -3 | paste -s -d' ')) " >&2 && echo -n "$f ($(ls -A $f | head -3 | paste -s -d' ')) " >&2 &&
$elevate rm -rI "$f" $elevate rm -rI "$f"
fi fi