added mini version (todo: automate minification)

This commit is contained in:
Dylan Araps 2020-08-04 22:00:55 +03:00
parent fc2ceed8f0
commit c34a9fc1ce
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E
1 changed files with 2 additions and 0 deletions

2
devel/shfm-mini Executable file
View File

@ -0,0 +1,2 @@
#!/bin/sh
e() { case $1 in CUD)printf '%s[%sB' "$w" "$2";;CUP)printf '%s[%s;%sH' "$w" "$2" "$3";;CUU)printf '%s[%sA' "$w" "$2";;AW)printf '%s[?7%s' "$w" "$2";;DC)printf '%s8' "$w";;DECSC)printf '%s7' "$w";;BM)printf '%s[%s;%sr' "$w" "$2" "$3";;ED[0-2])printf '%s[%sJ' "$w" "${1#ED}";;EL[0-2])printf '%s[%sK' "$w" "${1#EL}";;IL)printf '%s[%sL' "$w" "$2";;SGR)printf '%s[%s;%sm' "$w" "$2" "$3";;DE)printf '%s[?25%s' "$w" "$2";;SA)printf '%s[?1049%s' "$w" "$2";esac;};T() { x=$(stty -g);stty -icanon -echo;e AW l;e DE l;e ED2;e BM 1 "$((li-2))";};R() { e AW h;e DE h;e ED2;e BM;stty "$x";};Y() { set -f;set +f -- $(stty size);li=$1 co=$2 B=$((li-2));};D() { case $((y-$#)) in -*)y=$((y+1)) z=$((z+1<B?z+1:B));L "$((y-1))" "$@";printf '\n';L "$y" "$@";E "($y/$#) $PWD";esac;};S() { case $y in -*|0|1);;*)y=$((y-1));L "$((y+1))" "$@";case $z in 1)e IL;;*)e CUU;z=$((z>1?z-1:1));esac;L "$y" "$@";E "($y/$#) $PWD";esac;};C() { e SA h;e DE h;e BM;"$@";e BM 1 "$((li-2))";e SA l;e DE l;e CUP "$z";};V() { q=$1 s=;while c=${q%"${q#?}"};do case $c in [[:print:]])s=$s$c;;'')return;;*)s=$s\?;esac;q=${q#?};done;};H() { h=0 j=1;for f do case ${PWD%%/}/$f in "$O") y=$j z=$((j>B?m:j)) K=$f;esac;j=$((j+1));done;};J() { e ED2; e CUP;i=1 C=$((B+1)) m=$((B/4<5?1:B/4));case $h in 1)H "$@";shift "$((y>=B?y-m:0))";;*)shift "$((y>=B?y-B:0))";esac; for f do case $i in "$z")e SGR 34 7;esac;case $((i-C)) in -*)A "$f";e CUD;esac;i=$((i+1));done;e CUP "$((y>B?z:y))";};X() { J "$@";E "($y/$#) $PWD";};E() { e DECSC;e CUP "$li";e SGR 31 7;printf '%-*s' "$co" "$1";e SGR;e DC;};I() { e DECSC;e CUP "$li";printf %s "$1";e DE h;e EL0;case $2 in r)stty icanon echo;read -r Q||:;stty -icanon -echo;esac;e DC;e DE l;E "($y/$#) $PWD";};L() { b=$1;case $b in "$y") e SGR 34 7;esac;shift "$b";case $b in "$y")K=$1;esac;A "$1";};A() { V "$1";e EL0;printf %s "$s";test -d "$1"&&printf /;e SGR;printf '\r';};main() { set -e;case $1 in -v)printf '%s 0.2\n' "${0##*/}";exit 0;esac;w=$(printf '\033') C=$(printf '\177');cd "${1:-"$PWD"}";set -- *;K=$1;Y;T;trap R EXIT INT;trap 'Y;T;y=1 z=1;X "$@"' WINCH;y=1 z=1;X "$@";while key=$(dd ibs=1 count=1 2>/dev/null); do case $key${esc:=0} in k?|A2)S "$@";;j?|B2)D "$@";;l?|C2|"$esc") if cd "$K" >/dev/null 2>&1; then set -- *;y=1 z=1 K=$1 SE=0;X "$@";else C "${SHFM_OPENER:="${EDITOR:=vi}"}" "$K";fi;;h?|D2|"$C"?)O=$PWD;case $SE in 1) SE=0;;*)cd ..||continue;esac;set -- *; y=1 z=1 K=$1 h=1;X "$@";;g?)case $y in 1)continue;esac;y=1 z=1 K=$1;X "$@";;G?)y=$# z=$(($# < B ? $# : B));X "$@";;.?)case ${HI:=1} in 1)HI=0;set -- .[!.]*;;*)HI=1;set -- *;esac;y=1 z=1 K=$1;X "$@";;:?)I "cd: " r;cd "${Q:="$0"}" >/dev/null 2>&1|| continue;set -- *;y=1 z=1 K=$1;X "$@";;/?)I / r;set -- *"$Q"*;y=1 z=1 K=$1 SE=1;X "$@";E "($y/$#) search $Q";;-?)cd "$OLDPWD" >/dev/null 2>&1||continue;set -- *;y=1 z=1 K=$1;X "$@";;\~?)cd||continue;set -- *;y=1 z=1 K=$1;X "$@";;\!?)export SHFM_LEVEL;SHFM_LEVEL=$((SHFM_LEVEL+1));C "${SHELL:=/bin/sh}";;q?)exit 0;;"$w"*)esc=1;;'[1')esc=2;;*)esc=0;esac;done;};main "$@"