From d34b617cb3e75409b3350060f98385bea925f4bf Mon Sep 17 00:00:00 2001 From: huyixi Date: Thu, 9 Oct 2025 14:43:18 +0800 Subject: [PATCH] feat(analyze): open current directory in Finder via "O" key (#19) --- bin/analyze.sh | 20 +++++++++++++++++++- lib/common.sh | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/bin/analyze.sh b/bin/analyze.sh index 5aac442..7a61e1f 100755 --- a/bin/analyze.sh +++ b/bin/analyze.sh @@ -1610,6 +1610,7 @@ interactive_drill_down() { local need_scan=true local wait_for_calc=false # Don't wait on first load, let user press 'r' local temp_items="$TEMP_PREFIX.items" + local status_message="" # Cache variables to avoid recalculation local -a items=() @@ -1835,8 +1836,13 @@ interactive_drill_down() { output+=$'\n' fi + if [[ -n "$status_message" ]]; then + output+=" $status_message"$'\n\n' + status_message="" + fi + # Bottom help bar - output+=" ${GRAY}↑/↓${NC} Navigate ${GRAY}|${NC} ${GRAY}Enter${NC} Open ${GRAY}|${NC} ${GRAY}←${NC} Back ${GRAY}|${NC} ${GRAY}Del${NC} Delete ${GRAY}|${NC} ${GRAY}Q/ESC${NC} Quit"$'\n' + output+=" ${GRAY}↑/↓${NC} Navigate ${GRAY}|${NC} ${GRAY}Enter${NC} Open ${GRAY}|${NC} ${GRAY}←${NC} Back ${GRAY}|${NC} ${GRAY}Del${NC} Delete ${GRAY}|${NC} ${GRAY}O${NC} Finder ${GRAY}|${NC} ${GRAY}Q/ESC${NC} Quit"$'\n' # Output everything at once (single write = no flicker) printf "%b" "$output" >&2 @@ -1983,6 +1989,17 @@ interactive_drill_down() { return 1 # Return to menu fi ;; + "OPEN") + if command -v open >/dev/null 2>&1; then + if open "$current_path" >/dev/null 2>&1; then + status_message="${GREEN}✓${NC} Finder opened: ${GRAY}$current_path${NC}" + else + status_message="${YELLOW}Warning:${NC} Could not open ${GRAY}$current_path${NC}" + fi + else + status_message="${YELLOW}Warning:${NC} 'open' command not available" + fi + ;; "DELETE") # Delete selected item (file or directory) if [[ $cursor -lt ${#items[@]} ]]; then @@ -2285,6 +2302,7 @@ main() { echo " Enter / → Open selected folder" echo " ← Go back to parent directory" echo " Delete Delete selected file/folder (requires confirmation)" + echo " O Reveal current directory in Finder" echo " Q / ESC Quit the explorer" echo "" echo "Features:" diff --git a/lib/common.sh b/lib/common.sh index f2ceb75..29cdfc2 100755 --- a/lib/common.sh +++ b/lib/common.sh @@ -161,6 +161,7 @@ read_key() { 'd'|'D') echo "DELETE" ;; 'r'|'R') echo "RETRY" ;; '?') echo "HELP" ;; + 'o'|'O') echo "OPEN" ;; $'\x03') echo "QUIT" ;; # Ctrl+C $'\x7f'|$'\x08') echo "DELETE" ;; # Delete key (labeled "delete" on Mac, actually backspace) $'\x1b')