config/shell: various tweaks

This commit is contained in:
xeruf 2021-11-25 13:57:02 +01:00
parent 634b39ed9c
commit b7227a1ab5
7 changed files with 60 additions and 54 deletions

View File

@ -7,43 +7,43 @@ cdd() { cd "$@" 2>/dev/null || cd "$(dirname "$1")" "${@:2}" }
# Go up a number of dirs # Go up a number of dirs
up() { up() {
if [[ $# < 1 ]] ; then if [[ $# < 1 ]] ; then
cd .. cd ..
else else
CDSTR="" CDSTR=""
for i in {1..$1} ; do for i in {1..$1} ; do
CDSTR="../$CDSTR" CDSTR="../$CDSTR"
done done
cd $CDSTR cd $CDSTR
fi fi
} }
# Switch directory & ls # Switch directory & ls
cl() { cl() {
builtin cd $1 builtin cd $1
ls --almost-all --group-directories-first --file-type ls --almost-all --group-directories-first --file-type
} }
# cd but search for data dirs and ls in new dir # cd but search for data dirs and ls in new dir
cd() { cd() {
if test -d "$DATA" && test "${1:--}" != "-" -a ! -d "$1" -a $# -eq 1 if test -d "$DATA" && test "${1:--}" != "-" -a ! -d "$1" -a $# -eq 1
then then
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 "$1" &&
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
code=$? && test $code -eq 141 || return $code code=$? && test $code -eq 141 || return $code
fi fi
} }
# LOCATE # LOCATE
alias fselect='fzf -0 -1 --reverse --height=30% | while read f; do test -d "$f" && cd "$f" || b "$f"; done' alias fselect='fzf -0 -1 --reverse --height=30% | while read f; do test -d "$f" && cd "$f" || b "$f"; done'
loci() { loci() {
locate --all --ignore-case --basename --existing "$@" | locate --all --ignore-case --basename --existing "$@" |
command grep --extended-regexp --ignore-case --color=always $(echo "$|${@:$#}" | sed 's/ /|/g') | fselect command grep --extended-regexp --ignore-case --color=always $(echo "$|${@:$#}" | sed 's/ /|/g') | fselect
} }
alias loc='noglob loci' alias loc='noglob loci'
alias uloc='noglob sudo updatedb && loci' alias uloc='noglob sudo updatedb && loci'
@ -56,17 +56,19 @@ alias loca='noglob sudo updatedb --prunenames "" -o /var/lib/mlocate/all.db && l
# ZOXIDE # ZOXIDE
alias c=z alias c=z
d() { d() {
test "$1" != "-" -a ! -d "$1" -a $# -eq 1 || { cd "$@" && return } test "$1" != "-" -a ! -d "$1" -a $# -eq 1 || { cd "$@" && return }
local query="$(zf "$@")" local query="$(zf "$@")"
# First find out whether there is an obvious match # First find out whether there is an obvious match
# (score at least ten times above runner-up and score above 20) # (score at least ten times above runner-up and score above 20)
# If not select with fzf, using locate to find extra options # If not select with fzf, using locate to find extra options
cd "$(if test -n "$query" && expr "$(echo "$query" | head -1 | cut -d' ' -f1)" \> 20 \& $(echo "$query" | sed 'N;s|/.* \([0-9]\)|> 10 * \1|;q' | sed 's| */.*||') >/dev/null #2>&1 cd "$(if test -n "$query" &&
then echo "$query" | head -1 expr "$(echo "$query" | head -1 | cut -d' ' -f1)" \> 20 \& \
else test -n "$query" && echo "$query"; locz "$@" $(echo "$query" | sed 'N;s|/.* \([0-9]\)|> 10 * \1|;q' | sed 's| */.*||') >/dev/null #2>&1
fi | zfz)" then echo "$query" | head -1
else test -n "$query" && echo "$query"; locz "$@"
fi | zfz)"
} }
di() { di() {
test "$1" = "-" || local dir=$({ zf "$@"; locz "$@" } | zfz) test "$1" = "-" || local dir=$({ zf "$@"; locz "$@" } | zfz)
cd "${dir:-$1}" cd "${dir:-$1}"
} }

View File

@ -26,17 +26,12 @@ which lsb_release >/dev/null && export DIST=$(lsb_release --id | cut -d' ' -f2)
unalias rd 2>/dev/null unalias rd 2>/dev/null
# System helpers {{{1 # System help {{{1
alias h='help' alias h='help'
compdef help=man compdef help=man
alias info='info --vi-keys' alias info='info --vi-keys'
alias v=edit
alias println='printf "\n"'
alias dedup='awk '"'"'!a[$0]++'"'"
# Shows source code for command, resolving nested aliases # Shows source code for command, resolving nested aliases
wh() { wh() {
res=$(which "$@") res=$(which "$@")
@ -157,16 +152,21 @@ alias jcj='jcl -o json-pretty -u'
# Applications {{{1 # Applications {{{1
alias u='topgrade' # Shorthands
alias v='edit'
alias u='topgrade --only emacs --yes; topgrade --disable emacs'
alias st='synct' alias st='synct'
alias expr='noglob expr' alias expr='noglob expr'
alias lst='( last; last -f /var/log/wtmp.1 ) | grep -v "pts/" | tac | less +G' # Shortcuts
alias lar='last | tac'
alias calc='rlwrap -a bc -l'
alias logoff="loginctl terminate-user $USER" alias logoff="loginctl terminate-user $USER"
blues() { bluedevil-sendfile $(echo "$@" | xargs -n 1 realpath | xargs -n 1 echo -n " --files") } alias calc='rlwrap -a bc -l'
# Process
alias println='printf "\n"'
alias dedup='awk '"'"'!a[$0]++'"'"
alias lar='last | tac'
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"
@ -318,7 +318,7 @@ mvln() {
# Move into an xdg dir (default XDG_DATA_HOME) and create a symlink # Move into an xdg dir (default XDG_DATA_HOME) and create a symlink
mvx() { mvx() {
mvln "$1" "${2:-$XDG_DATA_HOME}/${1#.}" mvln "$1" "${2:-$XDG_DATA_HOME}/${1#.}"
yadm add "$1" ".config/$1" yadm add "$1" ".config/$1" 2>/dev/null
} }

3
.local/bin/scripts/blues Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
# Send given files via bluetooth
bluedevil-sendfile $(echo "$@" | xargs -n 1 realpath | xargs -n 1 echo -n " --files")

View File

@ -9,7 +9,7 @@ case $1 in
info --vi-keys $(test $last != zsh && echo --index-search=$last) zsh || LESS="$LESS +/^ *$last *\\[" man zshall;; info --vi-keys $(test $last != zsh && echo --index-search=$last) zsh || LESS="$LESS +/^ *$last *\\[" man zshall;;
(vlc) unbuffer vlc --full-help "${@:2}" | $paginate;; (vlc) unbuffer vlc --full-help "${@:2}" | $paginate;;
(gh|chordpro) $@ --help | $paginate;; (gh|chordpro) $@ --help | $paginate;;
(caddy) $1 help ${@:2} | $paginate;; (caddy|stretchly) $1 help ${@:2} | $paginate;;
(*) man "$@" || { info "$1" -w | grep -v "manpages" && pinfo "$@"; } || { "$@" --help || "$@" -help; } 2>&1 | ${PAGER:-less} || which "$@";; (*) man "$@" || { info "$1" -w | grep -v "manpages" && pinfo "$@"; } || { "$@" --help || "$@" -help; } 2>&1 | ${PAGER:-less} || which "$@";;
esac esac
docs="/usr/share/doc/$1" docs="/usr/share/doc/$1"

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# Install pre-commit, ignoring globally set core.hooksPath # Install pre-commit, ignoring globally set core.hooksPath
git config --unset core.hooksPath git config --unset-all core.hooksPath
GIT_CONFIG_GLOBAL=/dev/null pre-commit install GIT_CONFIG_GLOBAL=/dev/null pre-commit install
GIT_CONFIG_GLOBAL=/dev/null pre-commit install -t pre-push GIT_CONFIG_GLOBAL=/dev/null pre-commit install -t pre-push
git config --add core.hooksPath .git/hooks git config --add core.hooksPath .git/hooks

View File

@ -1,6 +1,6 @@
#!/bin/sh -e #!/bin/sh -e
# Move roam files into subfolders # Move roam files into subfolders
cd $DATA/2-standards/notes cd $DATA/2-standards/box
find . -mindepth 1 -type d -printf '%f\n' | find . -mindepth 1 -type d -printf '%f\n' |
while read dir; do while read dir; do
grep -l --directories=skip "#+filetags: :$dir" * | grep -l --directories=skip "#+filetags: :$dir" * |

View File

@ -1,10 +1,11 @@
#!/bin/sh #!/bin/sh
while true while true
do case $1 in do case $1 in
(-o) out=$2; shift 2;; (-o) out="$2"; shift 2;;
(-q) quality=$2; shift 2;; (-q) quality="$2"; shift 2;;
(*) break;; (*) break;;
esac esac
done done
magick '$@' -strip -interlace Plane -define jpeg:dct-method=float -sampling-factor 4:2:0 -gaussian-blur 0.05 -quality "${quality:-85}" "$out" test $# -eq 0 && echo "Usage: $0 [-q quality (default 85)] [-o outfile] <images...>" && exit 1
magick "$@" -strip -interlace Plane -define jpeg:dct-method=float -sampling-factor 4:2:0 -gaussian-blur 0.05 -quality "${quality:-85}" "$out"