This commit is contained in:
Dylan Araps committed 2020-08-03 23:33:13 +03:00
1 parent 436543fb8e
commit 5a384d86e0
2 files changed
+83 -32

No files matched your search

+77 -4
View File
@@ -12,8 +12,7 @@ ________________________________________________________________________________
* really nice escape sequence handling for keys which emit '\033[<stuff>'. Not * really nice escape sequence handling for keys which emit '\033[<stuff>'. Not
based on read timeouts. Based on tracking position within sequences. based on read timeouts. Based on tracking position within sequences.
* has no dependencies other than a POSIX shell and POSIX coreutils (for printf, * no dependencies other than a POSIX shell and POSIX (printf, dd, [ and stty)
[, etc if not builtin).
* movement uses vim-like keybinds (hjkl). * movement uses vim-like keybinds (hjkl).
@@ -26,8 +25,8 @@ ________________________________________________________________________________
- [x] store list somehow. - [x] store list somehow.
- [ ] search - [ ] search
- [ ] prompts - [ ] prompts
- [ ] opener - [x] opener
- [ ] resize (POSIX shell winch is not asynchronous during read + SIGWINCH?) - [x] resize
keybinds keybinds
@@ -40,3 +39,77 @@ h - go up level
g - go to top g - go to top
G - go to bottom G - go to bottom
q - quit q - quit
opener
________________________________________________________________________________
opening files in different applications (based on mime-type or file extension)
can be achieved via an environment variable (SHFM_OPENER) set to the location of
a small external script. The default for all files will be '$EDITOR' (and if
that is unset, 'vi').
The script receives a single argument, the full path to the selected file.
The opener script is also useful on the command-line.
Example scripts:
#!/bin/sh -e
#
# open file in application based on file extension
case $1 in
*.mp3|*.flac|*.wav)
mpv --no-video "$1"
;;
*.mp4|*.mkv|*.webm)
mpv "$1"
;;
*.png|*.gif||*.jpg|*.jpe|*.jpeg)
gimp "$1"
;;
*.html|*.pdf)
firefox "$1"
;;
# all other files
*)
"${EDITOR:=vi}" "$1"
;;
esac
#!/bin/sh -e
#
# open file in application based on mime-type
mime_type=$(file -bi)
case $mime_type in
audio/*)
mpv --no-video "$1"
;;
video/*)
mpv "$1"
;;
image/*)
gimp "$1"
;;
text/html*|application/pdf*)
firefox "$1"
;;
text/*|)
"${EDITOR:=vi}" "$1"
;;
*)
printf 'unknown mime-type %s\n' "$mime_type"
;;
esac
+6 -28
View File
@@ -28,9 +28,8 @@ hist_search() {
j=1 j=1
for file do for file do
[ "${PWD%%/}/$file" = "$old_pwd" ] && { [ "${PWD%%/}/$file" = "$old_pwd" ] &&
y=$j y2=$((j > bottom ? bottom : j)) y=$j y2=$((j > bottom ? bottom : j))
}
j=$((j + 1)) j=$((j + 1))
done done
@@ -61,10 +60,6 @@ list_print() {
printf '\033[%sH' "$((y > bottom ? bottom : y))" printf '\033[%sH' "$((y > bottom ? bottom : y))"
} }
list_reset() {
y=1 y2=1
}
redraw() { redraw() {
list_print "$@" list_print "$@"
status_line "$PWD ($y/$#)" status_line "$PWD ($y/$#)"
@@ -75,20 +70,6 @@ status_line() {
"$LINES" "$COLUMNS" "$1" "$LINES" "$COLUMNS" "$1"
} }
open_ext() {
# todo envar whatever
case $1 in
*.mp3|*.mp4|*.mkv|*.webm|*.flac|\
*.jpg|*.png|*.gif|*.jpeg|*.jpe)
mpv "$1"
;;
*)
"${EDITOR:=vi}" "$1"
;;
esac
}
print_line() { print_line() {
offset=$1 offset=$1
@@ -112,11 +93,11 @@ main() {
term_resize term_resize
term_setup term_setup
list_reset y=1 y2=1
redraw "$@" redraw "$@"
trap 'term_reset' EXIT INT trap 'term_reset' EXIT INT
trap 'term_resize; term_setup; list_reset; redraw "$@"' WINCH trap 'term_resize; term_setup; y=1 y2=1; redraw "$@"' WINCH
while key=$(dd ibs=1 count=1 2>/dev/null); do while key=$(dd ibs=1 count=1 2>/dev/null); do
case $key${esc:=0} in case $key${esc:=0} in
@@ -155,11 +136,9 @@ main() {
l?|C2) # ARROW RIGHT l?|C2) # ARROW RIGHT
if cd "$cur"; then if cd "$cur"; then
set -- * set -- *
list_reset y=1 y2=1
else else
term_reset "${SHFM_OPENER:="${EDITOR:=vi}"}" "$cur"
open_ext "$cur"
term_setup
fi fi
redraw "$@" redraw "$@"
@@ -169,8 +148,7 @@ main() {
old_pwd=$PWD old_pwd=$PWD
cd .. || continue cd .. || continue
set -- * set -- *
list_reset y=1 y2=1 hist=1
hist=1
redraw "$@" redraw "$@"
;; ;;