config/shell/arch: indent with tabs and use star-args for yas

This commit is contained in:
xeruf 2021-12-10 16:01:21 +01:00
parent 77fd546800
commit f32325d02b
2 changed files with 34 additions and 29 deletions

View File

@ -10,44 +10,48 @@ alias yau='yay -Syu --nobatchinstall'
# Helper function to integrate yay and fzf # Helper function to integrate yay and fzf
yzf() { yzf() {
pos=$1 pos=$1
shift shift
sed "s/ /\t/g" | sed "s/ /\t/g" |
fzf --nth=$pos --multi --history="${FZF_HISTDIR:-$XDG_STATE_HOME/fzf}/history-yzf$pos" \ fzf --nth=$pos --multi --history="${FZF_HISTDIR:-$XDG_STATE_HOME/fzf}/history-yzf$pos" \
--preview-window=60%,border-left \ --preview-window=60%,border-left \
--bind="double-click:execute(xdg-open 'https://archlinux.org/packages/{$pos}'),alt-enter:execute(xdg-open 'https://aur.archlinux.org/packages?K={$pos}&SB=p&SO=d&PP=100')" \ --bind="double-click:execute(xdg-open 'https://archlinux.org/packages/{$pos}'),alt-enter:execute(xdg-open 'https://aur.archlinux.org/packages?K={$pos}&SB=p&SO=d&PP=100')" \
"$@" | cut -f$pos | xargs "$@" | cut -f$pos | xargs
} }
# Dev note: print -s adds a shell history entry # Dev note: print -s adds a shell history entry
# List installable packages into fzf and install selection # List installable packages into fzf and install selection
yas() { yas() {
cache_dir="/tmp/yas-$USER" cache_dir="/tmp/yas-$USER"
test "$1" = "-y" && rm -rf "$cache_dir" && shift test "$1" = "-y" && rm -rf "$cache_dir" && shift
mkdir -p "$cache_dir" mkdir -p "$cache_dir"
preview_cache="$cache_dir/preview_{2}" preview_cache="$cache_dir/preview_{2}"
list_cache="$cache_dir/list" list_cache="$cache_dir/list$*"
{ test "$(cat "$list_cache$@" | wc -l)" -lt 50000 && rm "$list_cache$@"; } 2>/dev/null { test "$(cat "$list_cache" | wc -l)" -lt 50000 && rm "$list_cache"; } 2>/dev/null
pkg=$( (cat "$list_cache$@" 2>/dev/null || { pacman --color=always -Sl "$@"; yay --color=always -Sl aur "$@" } | sed 's/ [^ ]*unknown-version[^ ]*//' | tee "$list_cache$@") | pkg=$(
yzf 2 --tiebreak=index --preview="cat $preview_cache 2>/dev/null | grep -v 'Querying' | grep . || yay --color always -Si {2} | tee $preview_cache") ( cat "$list_cache" 2>/dev/null ||
if test -n "$pkg" { pacman --color=always -Sl "$@"; yay --color=always -Sl aur "$@" } |
then echo "Installing $pkg..." sed 's/ [^ ]*unknown-version[^ ]*//' | tee "$list_cache" ) |
cmd="yay -S $pkg" yzf 2 --tiebreak=index --preview="cat $preview_cache 2>/dev/null | grep -v 'Querying' | grep . || yay --color always -Si {2} | tee $preview_cache"
print -s "$cmd" )
eval "$cmd" || yay -Sy $pkg if test -n "$pkg"
rehash then echo "Installing $pkg..."
fi cmd="yay -S $pkg"
print -s "$cmd"
eval "$cmd" || yay -Sy $pkg
rehash
fi
} }
# List installed packages into fzf and remove selection # List installed packages into fzf and remove selection
# Tip: use -e to list only explicitly installed packages # Tip: use -e to list only explicitly installed packages
yar() { yar() {
pkg=$(yay --color=always -Q "$@" | yzf 1 --tiebreak=length --preview="yay --color always -Qli {1}") pkg=$(yay --color=always -Q "$@" | yzf 1 --tiebreak=length --preview="yay --color always -Qli {1}")
if test -n "$pkg" if test -n "$pkg"
then echo "Removing $pkg..." then echo "Removing $pkg..."
cmd="yay -R --cascade --recursive $pkg" cmd="yay -R --cascade --recursive $pkg"
print -s "$cmd" print -s "$cmd"
eval "$cmd" eval "$cmd"
fi fi
} }

View File

@ -1,6 +1,7 @@
#!/bin/sh #!/bin/sh
{ {
echo "$# Args: $@" echo "$# Args: $@"
#echo "Starred: $*"
#echo "${@:-default}" | sed 's/\w\+/\0-w/g' #echo "${@:-default}" | sed 's/\w\+/\0-w/g'
for last; do true; done for last; do true; done
echo "Last arg: $last" echo "Last arg: $last"