2 Commits
Author SHA1 Message Date
emmett1 6b729ffe8a updated panel mode 2026-03-28 07:54:42 +08:00
emmett1 25a329aba9 added opener script support 2026-03-28 00:08:08 +08:00
2 changed files with 118 additions and 58 deletions
+26 -1
View File
@@ -87,11 +87,34 @@ Press P to toggle the preview pane on the right side of the screen.
The list pane takes the left half, preview takes the right half. The list pane takes the left half, preview takes the right half.
Text files Shows file contents line by line Text files Shows file contents line by line
Directories Shows entry count Directories Shows directory contents
Symlinks Shows link target Symlinks Shows link target
Binary files Shows file size Binary files Shows file size
CUSTOM OPENER
-------------
sfm checks for a user-defined opener script at:
~/.config/sfm/opener
If the file exists and is executable, sfm passes the selected file
path to it instead of using the built-in smart opener. Example:
#!/bin/sh
case "$1" in
*.jpg|*.jpeg) imv "$1" ;;
*.mp4) mpv "$1" ;;
*.html|*.pdf) firefox "$1" ;;
*) echo "no program set for this file type" ;;
esac
Make it executable: chmod +x ~/.config/sfm/opener
If the opener script does not exist, sfm falls back to its built-in
smart opener automatically.
FILE OPERATIONS FILE OPERATIONS
--------------- ---------------
r Rename selected entry r Rename selected entry
@@ -182,4 +205,6 @@ it back to the desired location.
DATA FILES DATA FILES
---------- ----------
~/.config/sfm/bookmarks Saved bookmarks (one path per line) ~/.config/sfm/bookmarks Saved bookmarks (one path per line)
~/.config/sfm/opener Custom file opener script (optional)
~/.local/share/sfm-trash/ Trashed files ~/.local/share/sfm-trash/ Trashed files
+40 -5
View File
@@ -1,5 +1,6 @@
#!/bin/sh #!/bin/sh
# sfm - Simple File Manager in POSIX sh # sfm - Simple File Manager in POSIX sh (flicker-free)
# version 0.4
# --- terminal control --- # --- terminal control ---
tput_cmd() { command -v tput >/dev/null 2>&1 && tput "$@"; } tput_cmd() { command -v tput >/dev/null 2>&1 && tput "$@"; }
@@ -456,10 +457,36 @@ draw_preview() {
case "$entry" in case "$entry" in
*/) */)
# directory: show entry count # directory: list contents
_dc=$(ls -1 "$_path" 2>/dev/null | wc -l | tr -d '[:space:]') _max_lines=$((_rows - 3))
goto 2 "$_px" _pr=2
printf '%s[dir] %s items%s' "${CYAN}" "${_dc}" "${RESET}" for _de in "$_path"/*/; do
[ "$_pr" -gt $((_rows - 1)) ] && break
[ -d "$_de" ] || continue
_dn="${_de%/}"; _dn="${_dn##*/}"
[ "$_dn" = "*" ] && continue
_dl=" ${_dn}/"
[ "${#_dl}" -gt "$((_pw - 1))" ] && _dl="$(printf '%s' "$_dl" | cut -c1-$((_pw-2)))~"
goto "$_pr" "$_px"
printf '%s%s%s' "${GREEN}${BOLD}" "$_dl" "${RESET}"
_pr=$((_pr + 1))
done
for _fe in "$_path"/*; do
[ "$_pr" -gt $((_rows - 1)) ] && break
[ -e "$_fe" ] || continue
[ -d "$_fe" ] && continue
_fn="${_fe##*/}"
[ "$_fn" = "*" ] && continue
_fl=" ${_fn}"
[ "${#_fl}" -gt "$((_pw - 1))" ] && _fl="$(printf '%s' "$_fl" | cut -c1-$((_pw-2)))~"
goto "$_pr" "$_px"
printf '%s%s%s' "${WHITE}" "$_fl" "${RESET}"
_pr=$((_pr + 1))
done
if [ "$_pr" -eq 2 ]; then
goto 2 "$_px"
printf '%s(empty)%s' "${WHITE}" "${RESET}"
fi
;; ;;
*@) *@)
# symlink # symlink
@@ -679,6 +706,14 @@ _run_gui() { "$@" >/dev/null 2>&1 & }
open_file() { open_file() {
_f="$1" _f="$1"
# use user opener script if it exists and is executable
_opener="${XDG_CONFIG_HOME:-$HOME/.config}/sfm/opener"
if [ -x "$_opener" ]; then
"$_opener" "$_f"
return
fi
_ext="${_f##*.}" _ext="${_f##*.}"
_ext=$(printf '%s' "$_ext" | tr '[:upper:]' '[:lower:]') _ext=$(printf '%s' "$_ext" | tr '[:upper:]' '[:lower:]')