diff options
| author | emmett1 <emmett1.2miligrams@protonmail.com> | 2026-03-16 00:14:29 +0800 |
|---|---|---|
| committer | emmett1 <emmett1.2miligrams@protonmail.com> | 2026-03-16 00:14:29 +0800 |
| commit | 1e6fdd9e29f77c955182920744c5c2be706eb3b0 (patch) | |
| tree | de87165edb25a288f66870ec82a5a237897d2be9 | |
| parent | 12c85202f92282e7c92c3295c01f494bcbe13a95 (diff) | |
| download | sfm-1e6fdd9e29f77c955182920744c5c2be706eb3b0.tar.gz sfm-1e6fdd9e29f77c955182920744c5c2be706eb3b0.zip | |
add function to run from target directory
| -rwxr-xr-x | sfm | 9 |
1 files changed, 7 insertions, 2 deletions
@@ -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 |