aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoremmett1 <me@emmett1.my>2026-05-31 00:08:51 +0800
committeremmett1 <me@emmett1.my>2026-05-31 00:08:51 +0800
commit0504dec9c7448aac74132054217e7bc3c437b424 (patch)
treecea970fd70d0599fd1d1358c2de1379074df8176
parentf85d1af121f3009ee823d68091303e1862451caa (diff)
downloadsfm-0504dec9c7448aac74132054217e7bc3c437b424.tar.gz
sfm-0504dec9c7448aac74132054217e7bc3c437b424.zip
info mode now shows info boxv0.6
-rwxr-xr-xsfm96
1 files changed, 88 insertions, 8 deletions
diff --git a/sfm b/sfm
index e5ee6ef..032b6e5 100755
--- a/sfm
+++ b/sfm
@@ -1407,14 +1407,94 @@ do_info() {
[ -z "$entry" ] && return
_name="${entry%@}"; _name="${_name%/}"
target="${CWD}/${_name}"
- # permissions + type
- _perm=$(ls -ld "$target" 2>/dev/null | awk '{print $1}')
- # size (human readable via du, fallback to ls)
- _size=$(du -sh "$target" 2>/dev/null | cut -f1)
- [ -z "$_size" ] && _size=$(ls -lh "$target" 2>/dev/null | awk '{print $5}')
- # modification date
- _date=$(ls -ld "$target" 2>/dev/null | awk '{print $6, $7, $8}')
- INFO_MSG="${_perm} ${_size} ${_date}"
+
+ # gather info
+ _info_perm=$(ls -ld "$target" 2>/dev/null | awk '{print $1}')
+ _info_owner=$(ls -ld "$target" 2>/dev/null | awk '{print $3}')
+ _info_group=$(ls -ld "$target" 2>/dev/null | awk '{print $4}')
+ _info_size=$(du -sh "$target" 2>/dev/null | cut -f1)
+ [ -z "$_info_size" ] && _info_size=$(ls -lh "$target" 2>/dev/null | awk '{print $5}')
+ _info_date=$(ls -ld "$target" 2>/dev/null | awk '{print $6, $7, $8}')
+
+ case "$entry" in
+ */) _info_type="directory" ;;
+ *@) _info_type="symlink -> $(ls -ld "$target" 2>/dev/null | awk '{print $NF}')" ;;
+ *) _info_type="file"
+ if [ -x "$target" ]; then _info_type="executable"; fi ;;
+ esac
+
+ _info_lines=""
+ _info_lines="${_info_lines}Name: ${_name}
+"
+ _info_lines="${_info_lines}Type: ${_info_type}
+"
+ _info_lines="${_info_lines}Perm: ${_info_perm}
+"
+ _info_lines="${_info_lines}Owner: ${_info_owner}:${_info_group}
+"
+ _info_lines="${_info_lines}Size: ${_info_size}
+"
+ _info_lines="${_info_lines}Mod: ${_info_date}
+"
+
+ # measure longest line
+ _maxw=0
+ _info_rest="$_info_lines"
+ while [ -n "$_info_rest" ]; do
+ _info_l="${_info_rest%%
+*}"
+ [ "${#_info_l}" -gt "$_maxw" ] && _maxw=${#_info_l}
+ _info_next="${_info_rest#*
+}"
+ [ "$_info_next" = "$_info_rest" ] && break
+ _info_rest="$_info_next"
+ done
+
+ _info_h=8 # 6 data rows + top + bottom
+ ROWS=$(term_rows); COLS=$(term_cols)
+ _iw=$((_maxw + 2)); [ "$_iw" -lt 20 ] && _iw=20
+ _bw=$((_iw + 2)); [ "$_bw" -gt "$COLS" ] && _bw=$COLS && _iw=$((_bw - 2))
+ _ix=$(( (COLS - _bw) / 2 )); [ "$_ix" -lt 0 ] && _ix=0
+ _iy=$(( (ROWS - _info_h) / 2 )); [ "$_iy" -lt 1 ] && _iy=1
+ _hl=$(printf '%*s' "$_iw" '' | tr ' ' '-')
+
+ # draw
+ goto "$_iy" "$_ix"
+ printf '%s+%s+%s' "${BOLD}${CYAN}" "$_hl" "${RESET}"
+ goto "$((_iy+1))" "$_ix"
+ _title=" FILE INFO"
+ _tpad=$((_iw - ${#_title}))
+ [ "$_tpad" -lt 0 ] && _tpad=0
+ printf '%s|%s%s%s%s|%s' "${BOLD}${CYAN}" "${RESET}" "$_title" "$(printf '%*s' "$_tpad" '')" "${BOLD}${CYAN}" "${RESET}"
+ goto "$((_iy+2))" "$_ix"
+ printf '%s|%s|%s' "${BOLD}${CYAN}" "$_hl" "${RESET}"
+
+ _ri=3
+ _info_rest="$_info_lines"
+ while [ -n "$_info_rest" ]; do
+ _info_l="${_info_rest%%
+*}"
+ _info_next="${_info_rest#*
+}"
+ [ "$_info_next" = "$_info_rest" ] && break
+ _info_rest="$_info_next"
+ [ -z "$_info_l" ] && continue
+ goto "$((_iy+_ri))" "$_ix"
+ _lpad=$((_iw - ${#_info_l}))
+ [ "$_lpad" -lt 0 ] && _lpad=0
+ printf '%s|%s%s%s%s|%s' "${BOLD}${CYAN}" "${RESET}" "$_info_l" "$(printf '%*s' "$_lpad" '')" "${BOLD}${CYAN}" "${RESET}"
+ _ri=$((_ri + 1))
+ done
+
+ goto "$((_iy+_ri))" "$_ix"
+ printf '%s+%s+%s' "${BOLD}${CYAN}" "$_hl" "${RESET}"
+
+ # wait for key
+ IFS= read -r -n1 _infok 2>/dev/null || IFS= read -r _infok
+ case "$_infok" in
+ "$(printf '\033')")
+ IFS= read -r -n5 -t 0.1 _infoseq 2>/dev/null || _infoseq="" ;;
+ esac
NEED_FULL_REDRAW=1
}