5 # vt100 (IL is vt102) (DECTCEM is vt520)
6 CUD) printf '%s[%sB' "$esc_c" "$2" ;; # cursor down
7 CUP) printf '%s[%s;%sH' "$esc_c" "$2" "$3" ;; # cursor home
8 CUU) printf '%s[%sA' "$esc_c" "$2" ;; # cursor up
9 DECAWM) printf '%s[?7%s' "$esc_c" "$2" ;; # line wrap
10 DECRC) printf '%s8' "$esc_c" ;; # cursor restore
11 DECSC) printf '%s7' "$esc_c" ;; # cursor save
12 DECSTBM) printf '%s[%s;%sr' "$esc_c" "$2" "$3" ;; # scroll region
13 DECTCEM) printf '%s[?25%s' "$esc_c" "$2" ;; # cursor visible
14 ED[0-2]) printf '%s[%sJ' "$esc_c" "${1#ED}" ;; # clear screen
15 EL[0-2]) printf '%s[%sK' "$esc_c" "${1#EL}" ;; # clear line
16 IL) printf '%s[%sL' "$esc_c" "$2" ;; # insert line
17 SGR) printf '%s[%s;%sm' "$esc_c" "$2" "$3" ;; # colors
19 # xterm (since 1988, supported widely)
20 screen_alt) printf '%s[?1049%s' "$esc_c" "$2" ;; # alternate buffer
31 esc DECSTBM 1 "$((LINES - 2))"
42 # needed for cd-on-exit
43 printf '%s\n' "$PWD" >&1
47 # false-positive, behavior intentional, globbing is disabled.
48 # shellcheck disable=2046
51 set +f -- $(stty size)
56 # space for status_line
66 y2=$((y2 + 1 < bottom ? y2 + 1 : bottom))
68 line_print "$((y - 1))" "$@"
81 line_print "$((y + 1))" "$@"
85 *) esc CUU; y2=$((y2 > 1 ? y2 - 1 : 1))
98 esc DECSTBM 1 "$((LINES - 2))"
107 # loop over string char by char
108 while c=${tmp%"${tmp#?}"}; do
111 [[:cntrl:]]) safe=$safe\? ;;
123 case ${PWD%%/}/$file in
124 "$old_pwd") y=$j y2=$((j > bottom ? mid : j)) cur=$file
137 mid=$((bottom / 4 < 5 ? 1 : bottom / 4))
140 1) [ -e "$1" ] || set -- empty
144 2) # redraw after cmd run
145 shift "$((y > y2 ? y - y2 : 0))"
148 1) # redraw after go-to-parent
150 shift "$((y >= bottom ? y - mid : 0))"
154 shift "$((y >= bottom ? y - bottom : 0))"
173 esc CUP "$((y > y2 ? y2 : y))"
186 root) esc SGR 31 7 ;;
190 printf '%*s\r%s ' "$COLUMNS" "" "($y/$1)"
193 '') printf %s "$PWD" ;;
194 *) printf %s "$ltype"
218 status_line "($y/$#) $PWD"
239 [ -d "$1" ] && esc SGR 1 31
241 [ -d "$1" ] && printf /
252 printf 'shfm -[hv] <starting dir>\n'
257 printf 'shfm 0.4.2\n'
266 esc_c=$(printf '\033')
267 bs_char=$(printf '\177')
275 trap 'term_reset' EXIT INT
276 trap 'term_resize; term_setup; y=1 y2=1; redraw "$@"' WINCH
281 while key=$(dd ibs=1 count=1 2>/dev/null); do
282 case $key${esc:=0} in
288 term_scroll_down "$@"
291 l?|C2|"$esc") # ARROW RIGHT
292 if [ -d "$cur" ] && cd -- "$cur" >/dev/null 2>&1; then
294 y=1 y2=1 cur=$1 ltype=
297 elif [ -e "$cur" ]; then
298 cmd_run "${SHFM_OPENER:="${EDITOR:=vi}"}" "$cur"
303 h?|D2|"$bs_char"?) # ARROW LEFT
307 '') cd .. || continue ;;
312 y=1 y2=1 cur=$1 hist=1
327 y2=$(($# < bottom ? $# : bottom))
333 1) hidden=0; set -- .* ;;
334 0) hidden=1; set -- *
344 # false positive, behavior intentional
345 # shellcheck disable=2088
348 '~/'*) ans=$HOME/${ans#"~/"}
351 cd -- "${ans:="$0"}" >/dev/null 2>&1|| continue
360 # word splitting and globbing intentional
361 # shellcheck disable=2086
365 "$ans*1") set -- 'no results'
368 y=1 y2=1 cur=$1 ltype="search $PWD/$ans*"
374 cd -- "$OLDPWD" >/dev/null 2>&1|| continue
389 SHFM_LEVEL=$((SHFM_LEVEL + 1))
390 cmd_run "${SHELL:=/bin/sh}"
397 'l - open file or directory' \
402 ': - cd to <input>' \
403 '/ - search current directory <input>*' \
404 '- - go to last directory' \
407 '. - toggle hidden files' \
410 y=1 y2=1 cur=$1 ltype=keybinds
417 # handle keys which emit escape sequences
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list