aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xsfm37
1 files changed, 32 insertions, 5 deletions
diff --git a/sfm b/sfm
index af14f78..8970070 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.4
# --- terminal control ---
tput_cmd() { command -v tput >/dev/null 2>&1 && tput "$@"; }
@@ -456,10 +457,36 @@ draw_preview() {
case "$entry" in
*/)
- # directory: show entry count
- _dc=$(ls -1 "$_path" 2>/dev/null | wc -l | tr -d '[:space:]')
- goto 2 "$_px"
- printf '%s[dir] %s items%s' "${CYAN}" "${_dc}" "${RESET}"
+ # directory: list contents
+ _max_lines=$((_rows - 3))
+ _pr=2
+ 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