bin: parameter handling improvements
This commit is contained in:
parent
6b2cc865a6
commit
1bb28f6efe
|
@ -31,14 +31,14 @@ yzf() {
|
||||||
# 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
|
case "$1" in (-y*) rm -rf "$cache_dir"; shift; param=$1;; esac
|
||||||
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=$(
|
pkg=$(
|
||||||
( cat "$list_cache" 2>/dev/null ||
|
( cat "$list_cache" 2>/dev/null ||
|
||||||
{ pacman --color=always -Sl "$@"; yay --color=always -Sl aur "$@" } |
|
{ $(test $param && echo sudo) pacman --color=always -Sl $param "$@"; yay --color=always -Sl aur $param "$@" } |
|
||||||
sed 's/ [^ ]*unknown-version[^ ]*//' | tee "$list_cache" ) |
|
sed 's/ [^ ]*unknown-version[^ ]*//' | tee "$list_cache" ) |
|
||||||
yzf 2 --tiebreak=chunk,index --preview="cat $preview_cache 2>/dev/null | grep -v 'Querying' | grep . || yay --color always -Si {2} | tee $preview_cache"
|
yzf 2 --tiebreak=chunk,index --preview="cat $preview_cache 2>/dev/null | grep -v 'Querying' | grep . || yay --color always -Si {2} | tee $preview_cache"
|
||||||
)
|
)
|
||||||
|
|
|
@ -80,6 +80,7 @@ alias c=z
|
||||||
# Listing for quick directory switcher based on zoxide and fzf
|
# Listing for quick directory switcher based on zoxide and fzf
|
||||||
alias zoxide-list='noglob zoxide query -sl'
|
alias zoxide-list='noglob zoxide query -sl'
|
||||||
__zx_ls="ls --almost-all --color --human-readable --group-directories-first --file-type"
|
__zx_ls="ls --almost-all --color --human-readable --group-directories-first --file-type"
|
||||||
|
# Check fzf features first
|
||||||
alias fzf-dir="fzf -0 -1 --tiebreak=chunk,end,length \
|
alias fzf-dir="fzf -0 -1 --tiebreak=chunk,end,length \
|
||||||
--preview-window=30% --preview='$__zx_ls {}' \
|
--preview-window=30% --preview='$__zx_ls {}' \
|
||||||
--height=80% --reverse --keep-right"
|
--height=80% --reverse --keep-right"
|
||||||
|
|
|
@ -373,7 +373,6 @@ hex() { hexyl "$@" | "${PAGER:-less}"; }
|
||||||
|
|
||||||
export DICT="$XDG_DATA_HOME/dictcc"
|
export DICT="$XDG_DATA_HOME/dictcc"
|
||||||
dic() {
|
dic() {
|
||||||
# TODO tiebreak=chunk
|
|
||||||
result=$(cat $DICT/dict.txt | sed '/#/d;/&/d;/^$/d' | fzf --tiebreak=chunk,length --bind='alt-bspace:clear-query' --print-query --query="$1") &&
|
result=$(cat $DICT/dict.txt | sed '/#/d;/&/d;/^$/d' | fzf --tiebreak=chunk,length --bind='alt-bspace:clear-query' --print-query --query="$1") &&
|
||||||
dic "$(echo "$result" | tail -1 | sed 's/\t/\n/g' | grep --invert-match --ignore-case "$(echo "$result" | head -1)" | head -1 | sed 's/ \W.*//')"
|
dic "$(echo "$result" | tail -1 | sed 's/\t/\n/g' | grep --invert-match --ignore-case "$(echo "$result" | head -1)" | head -1 | sed 's/ \W.*//')"
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,16 +65,18 @@ for arg; do
|
||||||
fi
|
fi
|
||||||
# amount of columns in a grid
|
# amount of columns in a grid
|
||||||
grid=$(expr $(tput cols) / \( 25 - \( $# / 2 \) \& $# \< 30 \| 5 \))
|
grid=$(expr $(tput cols) / \( 25 - \( $# / 2 \) \& $# \< 30 \| 5 \))
|
||||||
tmpfile="$prefix/$(basename "$arg")"
|
tmpfile="$prefix/$(basename "$arg")_$(dd "if=$arg" bs=512 count=10 2>/dev/null | md5sum | tr -d ' ')"
|
||||||
mkdir -p "$prefix"
|
mkdir -p "$prefix"
|
||||||
case "$mime" in
|
case "$mime" in
|
||||||
(*\ application/pdf\;*)
|
(*\ application/pdf\;*)
|
||||||
echo Converting "$arg"
|
|
||||||
grid=$(expr $(tput cols) \* $# / $(tput lines))
|
grid=$(expr $(tput cols) \* $# / $(tput lines))
|
||||||
grid=$(expr 3 \& $grid \< 3 \| $grid)
|
grid=$(expr 3 \& $grid \< 3 \| $grid)
|
||||||
#limit=$(expr $grid \& \( $grid \> 3 \| $# \> 1 \) \| $grid '*' 2)
|
#limit=$(expr $grid \& \( $grid \> 3 \| $# \> 1 \) \| $grid '*' 2)
|
||||||
limit=$grid
|
limit=$grid
|
||||||
test -f "$tmpfile-1.ppm" || pdftoppm -forcenum -r 70 "$arg" "$tmpfile" -l $limit
|
if ! test -f "$tmpfile-1.ppm"
|
||||||
|
then echo Converting "$arg"
|
||||||
|
pdftoppm -forcenum -r 70 "$arg" "$tmpfile" -l $limit
|
||||||
|
fi
|
||||||
find "$prefix" -path "$tmpfile*.ppm" | sort | head -$limit | xargs -d'\n' timg -W --grid=$grid
|
find "$prefix" -path "$tmpfile*.ppm" | sort | head -$limit | xargs -d'\n' timg -W --grid=$grid
|
||||||
;;
|
;;
|
||||||
(*\ application/*document*|*.xlsx:\ *)
|
(*\ application/*document*|*.xlsx:\ *)
|
||||||
|
@ -152,7 +154,7 @@ if test "$timg"; then
|
||||||
if which timg >/dev/null
|
if which timg >/dev/null
|
||||||
then $elevate timg $(test "$timga" && echo "-V") --rotate=exif -g $(tput cols)x$(expr $(tput lines) / 2) \
|
then $elevate timg $(test "$timga" && echo "-V") --rotate=exif -g $(tput cols)x$(expr $(tput lines) / 2) \
|
||||||
$(test $# -gt 1 &&
|
$(test $# -gt 1 &&
|
||||||
echo "-t0.2 --center $(test $# -lt 20 && echo "--title") --grid=$((grid < $# ? grid : $#))x2") \
|
echo "-t0.2 --auto-crop --center $(test $# -lt 20 && echo "--title") --grid=$((grid < $# ? grid : $#))x2") \
|
||||||
"${timg[@]}" "${timga[@]}" 2>/dev/null || true
|
"${timg[@]}" "${timga[@]}" 2>/dev/null || true
|
||||||
else for img in "${timg[@]}"
|
else for img in "${timg[@]}"
|
||||||
do catimg -H $(expr $(tput lines) / 2) $img
|
do catimg -H $(expr $(tput lines) / 2) $img
|
||||||
|
|
|
@ -21,10 +21,13 @@ done
|
||||||
find "$dir" -maxdepth 2 -not -name ".stfolder" -empty -printf "Removing empty %p\n" -delete
|
find "$dir" -maxdepth 2 -not -name ".stfolder" -empty -printf "Removing empty %p\n" -delete
|
||||||
find -L -maxdepth 2 -type l -printf "Removing broken symlink %p\n" -delete 2>/dev/null
|
find -L -maxdepth 2 -type l -printf "Removing broken symlink %p\n" -delete 2>/dev/null
|
||||||
|
|
||||||
|
test -d /mnt/data/backups/mobile/ &&
|
||||||
|
mv -v $DATA/4*/backups/mobile/signal-* /mnt/data/backups/mobile/ 2>/dev/null
|
||||||
|
|
||||||
highlight "y :: recursively remove empty folders and files"
|
highlight "y :: recursively remove empty folders and files"
|
||||||
if [[ $1 =~ "y" ]]; then
|
if [[ $1 =~ "y" ]]; then
|
||||||
find -name '.thumbnails' -printf "Pre-cleaning %p\n" -exec rm -r {} +
|
find -name '.thumbnails' -printf "Pre-cleaning %p\n" -exec rm -r {} +
|
||||||
find \( -name ".stfolder" -o -name ".*keep" -o -name ".git" -o -name "tmp" -o -name ".nomedia" \) -prune -o -empty -printf "Removing empty %p\n" -exec rm -d {} +
|
find \( -name ".stfolder" -o -name ".*keep" -o -name ".git" -o -name "tmp" -o -name ".nomedia" -o -name "__init__.py" -o -name "instalee" \) -prune -o -empty -printf "Removing empty %p\n" -exec rm -d {} +
|
||||||
fi
|
fi
|
||||||
|
|
||||||
highlight "e :: remove downloaded emacs packages (rebuild takes minutes!)"
|
highlight "e :: remove downloaded emacs packages (rebuild takes minutes!)"
|
||||||
|
|
|
@ -33,7 +33,7 @@ case "$command" in
|
||||||
git aur commit -a "$@"
|
git aur commit -a "$@"
|
||||||
git push;;
|
git push;;
|
||||||
(clean)
|
(clean)
|
||||||
find "$aurdir" -mindepth 2 -maxdepth 2 \( -iname "*.pkg.tar.*" -o -iname "*.zip" -o -type d -not -name ".*" \) \
|
find "$aurdir" -mindepth 2 -maxdepth 2 \( -iname "*.pkg.tar.*" -o -iname "*.zip" -o -name "*.tar.gz" -o -type d -not -name ".*" \) \
|
||||||
-print -exec sudo rm -rI {} +;;
|
-print -exec sudo rm -rI {} +;;
|
||||||
(*) echo "Unknown command! Available: $commands"; exit 3;;
|
(*) echo "Unknown command! Available: $commands"; exit 3;;
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -19,7 +19,7 @@ cmd="$1"
|
||||||
case "$cmd" in
|
case "$cmd" in
|
||||||
# TODO extract help in standard format from scripts
|
# TODO extract help in standard format from scripts
|
||||||
(hunt|rdoc|gh|chordpro|bat|pdfjam|reflector|topgrade|r128gain|7z|kubectl|diffr|docker|jrnl|difft|wiked-diff) unbuffer "$@" --help | $paginate;;
|
(hunt|rdoc|gh|chordpro|bat|pdfjam|reflector|topgrade|r128gain|7z|kubectl|diffr|docker|jrnl|difft|wiked-diff) unbuffer "$@" --help | $paginate;;
|
||||||
(caddy|stretchly|go|fossil) test "$cmd" = "fossil" -a $# -eq 1 && repo="$(locate -b -l 1 "fossil*.fossil")" && fossil ui "$repo" && exit
|
(caddy|stretchly|go|fossil|flutter) test "$cmd" = "fossil" -a $# -eq 1 && repo="$(locate -b -l 1 "fossil*.fossil")" && fossil ui "$repo" && exit
|
||||||
# TODO view fossil ui in terminal
|
# TODO view fossil ui in terminal
|
||||||
shift
|
shift
|
||||||
"$cmd" help "$@" | $paginate;;
|
"$cmd" help "$@" | $paginate;;
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
#!/bin/sh -e
|
||||||
|
# LaTeX fixed
|
||||||
|
dir=/tmp/latexmk
|
||||||
|
filename="$(basename "${1%.tex}.pdf")"
|
||||||
|
TEXMF="" pdflatex -shell-escape -recorder -output-directory="$dir" "$@"
|
||||||
|
mv -v "$dir/$filename" .
|
||||||
|
b "$filename"
|
Loading…
Reference in New Issue