Compare commits

...

26 Commits

Author SHA1 Message Date
dylan 696318e947
Merge pull request #26 from Sketch98/bug0
G keybind (end) wasn't setting $cur so it would open the wrong item.
2021-06-11 08:13:38 +00:00
dylan 9a968b2c48
Merge pull request #27 from Sketch98/bug1
fixed bug with search function. added double quotes to stop $ans from…
2021-06-11 08:13:13 +00:00
dylan 25d4f809d7
Merge pull request #31 from Sketch98/bug2
fixed bug when moving to parent...
2021-06-11 08:11:35 +00:00
Nathan Sketch 01ae386143 fixed bug when moving to parent when y position of old directory equals bottom 2021-04-17 10:23:22 -04:00
Nathan Sketch 1bbd788ee0 this bug this branch was meant to fix was caused by word splitting. surrounding
$ans in double quotes stopped that, but it also disabled globbing which is
desired. this commit switches to just disabling word splitting.
2021-01-07 09:45:12 -05:00
Nathan Sketch 7b21d545b3 fixed bug with search function. added double quotes to stop $ans from parameter
expanding and modified the logic for detecting an empty directory to stop it
from overriding the logic for displaying 'no results'.
2021-01-07 06:19:46 -05:00
Nathan Sketch ec27f90096 G keybind (end) wasn't setting $cur so it would open the wrong item.
line_print $y $@ always sets $cur correctly.
2021-01-07 04:45:53 -05:00
Dylan Araps 8920178753
shfm: fix glob issues with hidden files
Let's just allow '.' and '..' to appear in the list as
they are fully functional entries after all. Also removes
the need for a "no hidden files" message.
2020-09-24 15:18:34 +03:00
dylan b8efa71b97
Merge pull request #20 from chambln/master
Show '*' and '.[!.]*' if such files exist
2020-09-24 13:54:22 +03:00
dylan e9fbd754ce
Merge pull request #22 from Crestwave/master
added support for termux
2020-09-24 13:47:22 +03:00
Crestwave 6849998609 added support for termux 2020-09-24 16:41:22 +08:00
Gregory Chamberlain 2a70030c02 Show '*' and '.[!.]*' if such files exist 2020-09-24 01:21:44 +01:00
Dylan Araps 8ad3756a1c
docs: update 2020-08-12 10:15:56 +03:00
Dylan Araps 2e3fc777b4
fix 2020-08-11 22:48:02 +03:00
Dylan Araps 0868399d04
shfm: Fix cd when dir starts with - 2020-08-11 22:19:26 +03:00
Dylan Araps fa04365aa2
clearer empty dir, no results, etc. Closes #16 2020-08-08 10:04:44 +03:00
Dylan Araps 33ce6cce78
fixed tty issues. stopped using alt buf for keeping state. now used for its intended purpose. Closes #14 2020-08-07 16:55:21 +03:00
Dylan Araps e55cdf00ac
docs: update 2020-08-07 10:43:26 +03:00
Dylan Araps efd8a9a233
add back documentation for other keys. closes #13 2020-08-07 10:40:55 +03:00
Dylan Araps ab3a6932fe Merge branch 'master' of github.com:dylanaraps/shfm into master 2020-08-07 10:37:40 +03:00
Dylan Araps 0bd79a5f00
reset terminal temporarily when subcommands are run. Might fix #12 2020-08-07 10:36:39 +03:00
dylan 0b12c5397b
Merge pull request #11 from hhltk/patch-1
docs: Fix a typo in README
2020-08-07 01:28:59 +03:00
Henrik Aalto d1c1439fa8
fixed a typo
one exit -> on exit
2020-08-07 00:42:43 +03:00
Dylan Araps b9f475ac6b
bold and red dirs. Closes #10 2020-08-06 21:18:29 +03:00
Dylan Araps 9741e308d5
docs: update 2020-08-06 15:45:13 +03:00
Dylan Araps e5fbeb04a0
docs: update 2020-08-06 15:31:48 +03:00
2 changed files with 62 additions and 35 deletions

30
README
View File

@ -32,13 +32,24 @@ g - go to top
G - go to bottom
q - quit
: - cd to <input>
/ - search current directory *<input>*
/ - search current directory <input>*
- - go to last directory
~ - go home
! - spawn shell
. - toggle hidden files
? - 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
________________________________________________________________________________
@ -65,7 +76,7 @@ rather flexible.
# store pwd in var on exit
var=$(shfm)
# store pwd in a file one exit
# store pwd in a file on exit
shfm > file
For ease of use, a wrapper function can be added to your .shellrc (.bashrc, etc).
@ -164,9 +175,9 @@ ________________________________________________________________________________
* VT100/ANSI escape sequences (widely available) are used in place of tput. A
few non-VT100 sequences /are/ needed however.
- IL vt102 \033[L: controls upwards scroll. (required)
- ? xterm \033[?1049[lh]: controls alternate screen. (optional)
- DECTCEM vt520 \033[?25[lh]: controls cursor visibility. (optional)
- IL vt102 \033[L: upwards scroll. (required)
- xterm \033[?1049[lh]: alternate screen. (optional)
- DECTCEM vt520 \033[?25[lh]: cursor visibility. (optional)
Why avoid tput?
@ -244,15 +255,6 @@ ________________________________________________________________________________
- 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.
I didn't think this was possible in POSIX shell until I needed to do this in

67
shfm
View File

@ -24,6 +24,7 @@ esc() {
term_setup() {
stty=$(stty -g)
stty -icanon -echo
esc screen_alt h
esc DECAWM l
esc DECTCEM l
esc ED2
@ -31,10 +32,11 @@ term_setup() {
}
term_reset() {
esc DECAWM h >&2
esc DECTCEM h >&2
esc ED2 >&2
esc DECSTBM >&2
esc DECAWM h >&2
esc DECTCEM h >&2
esc ED2 >&2
esc DECSTBM >&2
esc screen_alt l >&2
stty "$stty"
# needed for cd-on-exit
@ -88,14 +90,15 @@ term_scroll_up() {
}
cmd_run() {
esc screen_alt h
stty "$stty"
esc DECTCEM h
esc DECSTBM
esc ED2
"$@" ||:
esc DECSTBM 1 "$((LINES - 2))"
esc screen_alt l
esc DECTCEM l
esc CUP "$y2"
stty -icanon -echo
hist=2
}
file_escape() {
@ -118,7 +121,7 @@ hist_search() {
for file do
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
j=$((j + 1))
@ -133,13 +136,21 @@ list_print() {
end=$((bottom + 1))
mid=$((bottom / 4 < 5 ? 1 : bottom / 4))
case $# in
1) [ -e "$1" ] || [ "$1" = 'no results' ] || set -- empty
esac
case $hist in
1)
2) # redraw after cmd run
shift "$((y > y2 ? y - y2 : 0))"
;;
1) # redraw after go-to-parent
hist_search "$@"
shift "$((y >= bottom ? y - mid : 0))"
;;
*)
*) # everything else
shift "$((y >= bottom ? y - bottom : 0))"
;;
esac
@ -159,7 +170,7 @@ list_print() {
i=$((i + 1))
done
esc CUP "$((y > bottom ? y2 : y))"
esc CUP "$((y > y2 ? y2 : y))"
}
redraw() {
@ -183,7 +194,7 @@ status_line() {
*) printf %s "$ltype"
esac
esc SGR
esc SGR 0 0
esc DECRC
}
@ -225,10 +236,11 @@ line_print() {
line_format() {
file_escape "$1"
esc EL0
[ -d "$1" ] && esc SGR 1 31
printf %s "$safe"
[ -d "$1" ] && printf /
esc SGR
esc SGR 0 0
esc EL0
printf '\r'
}
@ -242,7 +254,7 @@ main() {
;;
-v|--version)
printf 'shfm 0.4.1\n'
printf 'shfm 0.4.2\n'
exit 0
;;
@ -277,13 +289,14 @@ main() {
;;
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 -- *
y=1 y2=1 cur=$1 ltype=
redraw "$@"
elif [ -e "$cur" ]; then
cmd_run "${SHFM_OPENER:="${EDITOR:=vi}"}" "$cur"
redraw "$@"
fi
;;
@ -312,13 +325,14 @@ main() {
G?)
y=$#
y2=$(($# < bottom ? $# : bottom))
line_print "$y" "$@"
redraw "$@"
;;
.?)
case ${hidden:=1} in
1) hidden=0; set -- .[!.]* ;;
*) hidden=1; set -- * ;;
1) hidden=0; set -- .* ;;
0) hidden=1; set -- *
esac
y=1 y2=1 cur=$1
@ -335,7 +349,7 @@ main() {
'~/'*) ans=$HOME/${ans#"~/"}
esac
cd "${ans:="$0"}" >/dev/null 2>&1|| continue
cd -- "${ans:="$0"}" >/dev/null 2>&1|| continue
set -- *
y=1 y2=1 cur=$1
redraw "$@"
@ -343,14 +357,24 @@ main() {
/?)
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*"
redraw "$@"
status_line "$#"
;;
-?)
cd "$OLDPWD" >/dev/null 2>&1|| continue
cd -- "$OLDPWD" >/dev/null 2>&1|| continue
set -- *
y=1 y2=1 cur=$1
redraw "$@"
@ -367,6 +391,7 @@ main() {
export SHFM_LEVEL
SHFM_LEVEL=$((SHFM_LEVEL + 1))
cmd_run "${SHELL:=/bin/sh}"
redraw "$@"
;;
\??)