aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremmett1 <emmett1.2miligrams@protonmail.com>2026-03-16 00:14:29 +0800
committeremmett1 <emmett1.2miligrams@protonmail.com>2026-03-16 00:14:29 +0800
commit1e6fdd9e29f77c955182920744c5c2be706eb3b0 (patch)
treede87165edb25a288f66870ec82a5a237897d2be9
parent12c85202f92282e7c92c3295c01f494bcbe13a95 (diff)
downloadsfm-1e6fdd9e29f77c955182920744c5c2be706eb3b0.tar.gz
sfm-1e6fdd9e29f77c955182920744c5c2be706eb3b0.zip
add function to run from target directory
-rwxr-xr-xsfm9
1 files changed, 7 insertions, 2 deletions
diff --git a/sfm b/sfm
index d35aac1..f08a055 100755
--- a/sfm
+++ b/sfm
@@ -1,5 +1,6 @@
#!/bin/sh
-# sfm - Simple File Manager in POSIX sh
+# sfm - Simple File Manager in POSIX sh (flicker-free)
+# version 0.3
# --- terminal control ---
tput_cmd() { command -v tput >/dev/null 2>&1 && tput "$@"; }
@@ -61,7 +62,11 @@ term_rows() { tput_cmd lines || echo 24; }
term_cols() { tput_cmd cols || echo 80; }
# --- state ---
-CWD="$PWD"; CWD=$(cd "$CWD" 2>/dev/null && pwd) || CWD="/"
+if [ -n "$1" ]; then
+ CWD=$(cd "$1" 2>/dev/null && pwd) || { printf 'sfm: %s: no such directory\n' "$1" >&2; exit 1; }
+else
+ CWD=$(cd "$PWD" 2>/dev/null && pwd) || CWD="/"
+fi
SEL=0
OFFSET=0
PREV_SEL=0