mirror of
https://github.com/dylanaraps/shfm.git
synced 2026-11-03 13:18:34 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
696318e947 | ||
|
|
9a968b2c48 | ||
|
|
25d4f809d7 | ||
|
|
01ae386143 | ||
|
|
1bbd788ee0 | ||
|
|
7b21d545b3 | ||
|
|
ec27f90096 | ||
|
|
8920178753 | ||
|
|
b8efa71b97 | ||
|
|
e9fbd754ce | ||
|
|
6849998609 | ||
|
|
2a70030c02 | ||
|
|
8ad3756a1c | ||
|
|
2e3fc777b4 | ||
|
|
0868399d04 | ||
|
|
fa04365aa2 | ||
|
|
33ce6cce78 | ||
|
|
e55cdf00ac | ||
|
|
efd8a9a233 | ||
|
|
ab3a6932fe | ||
|
|
0bd79a5f00 | ||
|
|
0b12c5397b | ||
|
|
d1c1439fa8 | ||
|
|
b9f475ac6b | ||
|
|
9741e308d5 | ||
|
|
e5fbeb04a0 | ||
|
|
16d1bd77f7 |
No files matched your search
@@ -32,13 +32,24 @@ g - go to top
|
|||||||
G - go to bottom
|
G - go to bottom
|
||||||
q - quit
|
q - quit
|
||||||
: - cd to <input>
|
: - cd to <input>
|
||||||
/ - search current directory *<input>*
|
/ - search current directory <input>*
|
||||||
- - go to last directory
|
- - go to last directory
|
||||||
~ - go home
|
~ - go home
|
||||||
! - spawn shell
|
! - spawn shell
|
||||||
. - toggle hidden files
|
. - toggle hidden files
|
||||||
? - show help
|
? - show help
|
||||||
|
|
||||||
|
Also supported:
|
||||||
|
|
||||||
|
down arrow - down
|
||||||
|
up arrow - up
|
||||||
|
left arrow - go up level
|
||||||
|
right arrow - open file or directory
|
||||||
|
|
||||||
|
backspace - up
|
||||||
|
enter - open file or directory
|
||||||
|
|
||||||
|
|
||||||
todo
|
todo
|
||||||
________________________________________________________________________________
|
________________________________________________________________________________
|
||||||
|
|
||||||
@@ -65,13 +76,13 @@ rather flexible.
|
|||||||
# store pwd in var on exit
|
# store pwd in var on exit
|
||||||
var=$(shfm)
|
var=$(shfm)
|
||||||
|
|
||||||
# store pwd in a file one exit
|
# store pwd in a file on exit
|
||||||
shfm > file
|
shfm > file
|
||||||
|
|
||||||
For ease of use, a wrapper function can be added to your .shellrc (.bashrc, etc).
|
For ease of use, a wrapper function can be added to your .shellrc (.bashrc, etc).
|
||||||
|
|
||||||
shfm() {
|
shfm() {
|
||||||
cd "$(command shfm)"
|
cd "$(command shfm "$@")"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -164,9 +175,9 @@ ________________________________________________________________________________
|
|||||||
* VT100/ANSI escape sequences (widely available) are used in place of tput. A
|
* VT100/ANSI escape sequences (widely available) are used in place of tput. A
|
||||||
few non-VT100 sequences /are/ needed however.
|
few non-VT100 sequences /are/ needed however.
|
||||||
|
|
||||||
- IL vt102 \033[L: controls upwards scroll. (required)
|
- IL vt102 \033[L: upwards scroll. (required)
|
||||||
- ? xterm \033[?1049[lh]: controls alternate screen. (optional)
|
- xterm \033[?1049[lh]: alternate screen. (optional)
|
||||||
- DECTCEM vt520 \033[?25[lh]: controls cursor visibility. (optional)
|
- DECTCEM vt520 \033[?25[lh]: cursor visibility. (optional)
|
||||||
|
|
||||||
Why avoid tput?
|
Why avoid tput?
|
||||||
|
|
||||||
@@ -244,15 +255,6 @@ ________________________________________________________________________________
|
|||||||
- If input doesn't follow this sequence, 'esc' is reset to '0'.
|
- If input doesn't follow this sequence, 'esc' is reset to '0'.
|
||||||
|
|
||||||
|
|
||||||
* There is no usage of '[' or 'test'.
|
|
||||||
|
|
||||||
Despite these being commonly provided as "shell builtins" (part of the shell),
|
|
||||||
a lot of shells still use the external utilities from the coreutils. All usage
|
|
||||||
of these has been replaced with 'case' as it is always a "shell keyword".
|
|
||||||
|
|
||||||
This is one of the approaches taken to reduce the need for anything external.
|
|
||||||
|
|
||||||
|
|
||||||
* Filename escaping works via looping over a string char by char.
|
* Filename escaping works via looping over a string char by char.
|
||||||
|
|
||||||
I didn't think this was possible in POSIX shell until I needed to do this in
|
I didn't think this was possible in POSIX shell until I needed to do this in
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ esc() {
|
|||||||
term_setup() {
|
term_setup() {
|
||||||
stty=$(stty -g)
|
stty=$(stty -g)
|
||||||
stty -icanon -echo
|
stty -icanon -echo
|
||||||
|
esc screen_alt h
|
||||||
esc DECAWM l
|
esc DECAWM l
|
||||||
esc DECTCEM l
|
esc DECTCEM l
|
||||||
esc ED2
|
esc ED2
|
||||||
@@ -31,10 +32,11 @@ term_setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
term_reset() {
|
term_reset() {
|
||||||
esc DECAWM h
|
esc DECAWM h >&2
|
||||||
esc DECTCEM h >&2
|
esc DECTCEM h >&2
|
||||||
esc ED2 >&2
|
esc ED2 >&2
|
||||||
esc DECSTBM
|
esc DECSTBM >&2
|
||||||
|
esc screen_alt l >&2
|
||||||
stty "$stty"
|
stty "$stty"
|
||||||
|
|
||||||
# needed for cd-on-exit
|
# needed for cd-on-exit
|
||||||
@@ -88,14 +90,15 @@ term_scroll_up() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cmd_run() {
|
cmd_run() {
|
||||||
esc screen_alt h
|
stty "$stty"
|
||||||
esc DECTCEM h
|
esc DECTCEM h
|
||||||
esc DECSTBM
|
esc DECSTBM
|
||||||
|
esc ED2
|
||||||
"$@" ||:
|
"$@" ||:
|
||||||
esc DECSTBM 1 "$((LINES - 2))"
|
esc DECSTBM 1 "$((LINES - 2))"
|
||||||
esc screen_alt l
|
|
||||||
esc DECTCEM l
|
esc DECTCEM l
|
||||||
esc CUP "$y2"
|
stty -icanon -echo
|
||||||
|
hist=2
|
||||||
}
|
}
|
||||||
|
|
||||||
file_escape() {
|
file_escape() {
|
||||||
@@ -118,7 +121,7 @@ hist_search() {
|
|||||||
|
|
||||||
for file do
|
for file do
|
||||||
case ${PWD%%/}/$file in
|
case ${PWD%%/}/$file in
|
||||||
"$old_pwd") y=$j y2=$((j > bottom ? mid : j)) cur=$file
|
"$old_pwd") y=$j y2=$((j >= bottom ? mid : j)) cur=$file
|
||||||
esac
|
esac
|
||||||
|
|
||||||
j=$((j + 1))
|
j=$((j + 1))
|
||||||
@@ -133,13 +136,21 @@ list_print() {
|
|||||||
end=$((bottom + 1))
|
end=$((bottom + 1))
|
||||||
mid=$((bottom / 4 < 5 ? 1 : bottom / 4))
|
mid=$((bottom / 4 < 5 ? 1 : bottom / 4))
|
||||||
|
|
||||||
|
case $# in
|
||||||
|
1) [ -e "$1" ] || [ "$1" = 'no results' ] || set -- empty
|
||||||
|
esac
|
||||||
|
|
||||||
case $hist in
|
case $hist in
|
||||||
1)
|
2) # redraw after cmd run
|
||||||
|
shift "$((y > y2 ? y - y2 : 0))"
|
||||||
|
;;
|
||||||
|
|
||||||
|
1) # redraw after go-to-parent
|
||||||
hist_search "$@"
|
hist_search "$@"
|
||||||
shift "$((y >= bottom ? y - mid : 0))"
|
shift "$((y >= bottom ? y - mid : 0))"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*) # everything else
|
||||||
shift "$((y >= bottom ? y - bottom : 0))"
|
shift "$((y >= bottom ? y - bottom : 0))"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@@ -159,7 +170,7 @@ list_print() {
|
|||||||
i=$((i + 1))
|
i=$((i + 1))
|
||||||
done
|
done
|
||||||
|
|
||||||
esc CUP "$((y > bottom ? y2 : y))"
|
esc CUP "$((y > y2 ? y2 : y))"
|
||||||
}
|
}
|
||||||
|
|
||||||
redraw() {
|
redraw() {
|
||||||
@@ -183,7 +194,7 @@ status_line() {
|
|||||||
*) printf %s "$ltype"
|
*) printf %s "$ltype"
|
||||||
esac
|
esac
|
||||||
|
|
||||||
esc SGR
|
esc SGR 0 0
|
||||||
esc DECRC
|
esc DECRC
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,10 +236,11 @@ line_print() {
|
|||||||
|
|
||||||
line_format() {
|
line_format() {
|
||||||
file_escape "$1"
|
file_escape "$1"
|
||||||
esc EL0
|
[ -d "$1" ] && esc SGR 1 31
|
||||||
printf %s "$safe"
|
printf %s "$safe"
|
||||||
[ -d "$1" ] && printf /
|
[ -d "$1" ] && printf /
|
||||||
esc SGR
|
esc SGR 0 0
|
||||||
|
esc EL0
|
||||||
printf '\r'
|
printf '\r'
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,7 +254,7 @@ main() {
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
-v|--version)
|
-v|--version)
|
||||||
printf 'shfm 0.4\n'
|
printf 'shfm 0.4.2\n'
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
|
|
||||||
@@ -277,13 +289,14 @@ main() {
|
|||||||
;;
|
;;
|
||||||
|
|
||||||
l?|C2|"$esc") # ARROW RIGHT
|
l?|C2|"$esc") # ARROW RIGHT
|
||||||
if [ -d "$cur" ] && cd "$cur" >/dev/null 2>&1; then
|
if [ -d "$cur" ] && cd -- "$cur" >/dev/null 2>&1; then
|
||||||
set -- *
|
set -- *
|
||||||
y=1 y2=1 cur=$1 ltype=
|
y=1 y2=1 cur=$1 ltype=
|
||||||
redraw "$@"
|
redraw "$@"
|
||||||
|
|
||||||
elif [ -e "$cur" ]; then
|
elif [ -e "$cur" ]; then
|
||||||
cmd_run "${SHFM_OPENER:="${EDITOR:=vi}"}" "$cur"
|
cmd_run "${SHFM_OPENER:="${EDITOR:=vi}"}" "$cur"
|
||||||
|
redraw "$@"
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
@@ -312,13 +325,14 @@ main() {
|
|||||||
G?)
|
G?)
|
||||||
y=$#
|
y=$#
|
||||||
y2=$(($# < bottom ? $# : bottom))
|
y2=$(($# < bottom ? $# : bottom))
|
||||||
|
line_print "$y" "$@"
|
||||||
redraw "$@"
|
redraw "$@"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
.?)
|
.?)
|
||||||
case ${hidden:=1} in
|
case ${hidden:=1} in
|
||||||
1) hidden=0; set -- .[!.]* ;;
|
1) hidden=0; set -- .* ;;
|
||||||
*) hidden=1; set -- * ;;
|
0) hidden=1; set -- *
|
||||||
esac
|
esac
|
||||||
|
|
||||||
y=1 y2=1 cur=$1
|
y=1 y2=1 cur=$1
|
||||||
@@ -335,7 +349,7 @@ main() {
|
|||||||
'~/'*) ans=$HOME/${ans#"~/"}
|
'~/'*) ans=$HOME/${ans#"~/"}
|
||||||
esac
|
esac
|
||||||
|
|
||||||
cd "${ans:="$0"}" >/dev/null 2>&1|| continue
|
cd -- "${ans:="$0"}" >/dev/null 2>&1|| continue
|
||||||
set -- *
|
set -- *
|
||||||
y=1 y2=1 cur=$1
|
y=1 y2=1 cur=$1
|
||||||
redraw "$@"
|
redraw "$@"
|
||||||
@@ -343,14 +357,24 @@ main() {
|
|||||||
|
|
||||||
/?)
|
/?)
|
||||||
prompt / r
|
prompt / r
|
||||||
set -- "$ans"*
|
|
||||||
|
IFS=
|
||||||
|
# globbing intentional, word splitting is disabled.
|
||||||
|
# shellcheck disable=2086
|
||||||
|
set -- $ans*
|
||||||
|
unset IFS
|
||||||
|
|
||||||
|
case $1$# in
|
||||||
|
"$ans*1") set -- 'no results'
|
||||||
|
esac
|
||||||
|
|
||||||
y=1 y2=1 cur=$1 ltype="search $PWD/$ans*"
|
y=1 y2=1 cur=$1 ltype="search $PWD/$ans*"
|
||||||
redraw "$@"
|
redraw "$@"
|
||||||
status_line "$#"
|
status_line "$#"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
-?)
|
-?)
|
||||||
cd "$OLDPWD" >/dev/null 2>&1|| continue
|
cd -- "$OLDPWD" >/dev/null 2>&1|| continue
|
||||||
set -- *
|
set -- *
|
||||||
y=1 y2=1 cur=$1
|
y=1 y2=1 cur=$1
|
||||||
redraw "$@"
|
redraw "$@"
|
||||||
@@ -367,6 +391,7 @@ main() {
|
|||||||
export SHFM_LEVEL
|
export SHFM_LEVEL
|
||||||
SHFM_LEVEL=$((SHFM_LEVEL + 1))
|
SHFM_LEVEL=$((SHFM_LEVEL + 1))
|
||||||
cmd_run "${SHELL:=/bin/sh}"
|
cmd_run "${SHELL:=/bin/sh}"
|
||||||
|
redraw "$@"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
\??)
|
\??)
|
||||||
@@ -390,9 +415,7 @@ main() {
|
|||||||
status_line "$#"
|
status_line "$#"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
q?)
|
q?) exit 0 ;;
|
||||||
exit 0
|
|
||||||
;;
|
|
||||||
|
|
||||||
# handle keys which emit escape sequences
|
# handle keys which emit escape sequences
|
||||||
"$esc_c"*) esc=1 ;;
|
"$esc_c"*) esc=1 ;;
|
||||||
|
|||||||
Reference in new issue
Block a user