bin: little script fixes

This commit is contained in:
xeruf 2022-02-10 15:59:41 +01:00
parent 6610e4edba
commit e8eeb04303
5 changed files with 17 additions and 12 deletions

View File

@ -9,7 +9,7 @@ if test "$1" = "f"
lsblk --output name,size,fsavail,fsuse%,mountpoint$outcols,label,fstype$(test "${cols:-0}" -gt 120 && echo ',uuid') $width $cols |
while read line
do p=$(echo "$line" | sed 's|.* \([[:digit:]]\+\)%.*|\1|;t;c0')
printf "$(expr "$line" : " " >/dev/null || echo "\033[$(test -z "$first" && echo "4" || expr "5;31" \& "$p" \> 98 \| "31" \& "$p" \> 97 \| "33" \& "$p" \> 94 \| "35" \& "$p" \> 90)m")%s\n" "$line"
printf "$(expr "$line" : " " >/dev/null || echo "\033[$(test -z "$first" && echo "4" || expr "5;31" \& "$p" \> 98 \| "31" \& "$p" \> 97 \| "33" \& "$p" \> 94 \| "35" \& "$p" \> 90)m")%s\033[39m\n" "$line"
first=1
done
fi

View File

@ -4,7 +4,8 @@
# optdepends: highlight(dotfiles)
paginate="${PAGER:-less} +Gg"
test "$1" = "-d" && browse=1 && shift
# TODO resolve aliases
# TODO resolve aliases in 'h' alias
# TODO call 'wh' on scripts instead
case $1 in
(zsh|zmv) # https://unix.stackexchange.com/questions/19290/zmv-for-zsh-dry-runs-and-man-pages
for last; do true; done
@ -16,12 +17,14 @@ case $1 in
(plantuml) unbuffer "$@" -help | $paginate;;
(vlc) unbuffer vlc --full-help "${@:2}" | $paginate;;
(kdeconnect*) kdeconnect-cli --help-all "${@:2}" | $paginate;;
(pandoc) man pandoc; highlight "Extensions" && pandoc --list-extensions;;
(pandoc) man pandoc; highlight "Extensions" && pandoc --list-extensions | paste -s -d' ';;
(swaymsg) test $# -gt 1 && man sway "${@:2}" || man swaymsg;;
(swaymsg-*) man sway "${1#swaymsg-}";;
(*) man "$@" ||
{ info "$1" -w | grep -v "manpages" && pinfo "$@"; } ||
if which "$1" >/dev/null; then "$@" --help; "$@" -help; "$@" -h 2>&1 | $paginate; fi;;
if which "$1" >/dev/null
then "$@" --help || echo $? == 1 && "$@" -help || echo $? == 1 && "$@" -h 2>&1 | $paginate
fi;;
esac
docs="/usr/share/doc/$1"
if test -d "$docs"; then

View File

@ -12,7 +12,7 @@ do
test "$answer" = "y" &&
$elevate rm -rf "$f"
else
$elevate find "$f" -maxdepth 4 -not -name ".stfolder" -empty -printf "Removing empty %p\n" -delete
$elevate find "$f" -maxdepth $(expr 1 \& "$f" = "/" \| 4) -type d -o -type f -not -name ".stfolder" -empty -printf "Removing empty %p\n" -delete
test $# -eq 0 && exit $?
if test -e "$f"; then
echo -n "$f ($(ls -A "$f" | head -3 | paste -s -d' ')) " >&2 &&

View File

@ -1,17 +1,19 @@
#!/bin/sh
#!/bin/sh -e
# Lossy image compression using ImageMagick
# Tries to eliminate artifacts
# Eliminates artifacts and metadata
while true
do case $1 in
(-h|--help|"") echo "Usage: $0 [-q quality (default 85)] [-o outfile] [xRES] <images...>" && exit 2;;
(-o) out="$2"; shift 2;;
(-q) quality="$2"; shift 2;;
(x*) resolution="$1"; resize="-resize $resolution"; shift;;
(*) break;;
esac
done
out="${out:-$1-shrinked.jpg}"
test $# -eq 0 && echo "Usage: $0 [-q quality (default 85)] [-o outfile] <images...>" && exit 1
magick "$@" -auto-orient -strip -interlace Plane -define jpeg:dct-method=float -sampling-factor 4:2:0 -gaussian-blur 0.05 \
-quality "${quality:-85}" "$out"
out="${out:-$1${resolution:--shrinked}.jpg}"
magick "$@" -auto-orient -strip \
-interlace Plane -define jpeg:dct-method=float -sampling-factor 4:2:0 -gaussian-blur 0.05 \
-quality "${quality:-85}" $resize "$out"
printf "Shrinked $1(%s) to $out(%s) - reduced to %s%%\n" \
$(stat --format %s "$1" "$out" | numfmt --to=iec-i --suffix=B) \
$(stat --format %s "$out" "$1" | sed 'N;s|\n|*100/|' | bc)

View File

@ -6,7 +6,7 @@ print("\\033[XXm")
for i in range(30,37+1):
print("\033[%dm%d\t\t\033[%dm%d" % (i,i,i+60,i+60));
print("\033[39m\\033[49m - Reset colour")
print("\033[39m\\033[39m - Reset colour (0 to reset all)")
print("\\033[2K - Clear Line")
print("\\033[<L>;<C>H OR \\033[<L>;<C>f puts the cursor at line L and column C.")
print("\\033[<N>A Move the cursor up N lines")