From 959bf773cb442d3b911c170823e50836262cd7a0 Mon Sep 17 00:00:00 2001 From: Yan Lin Date: Wed, 27 Aug 2025 22:28:30 +0200 Subject: [PATCH] Add macos app search function --- modules/zsh.nix | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/modules/zsh.nix b/modules/zsh.nix index e19bc56..8a8f7dc 100644 --- a/modules/zsh.nix +++ b/modules/zsh.nix @@ -21,22 +21,10 @@ in shellAliases = { ll = "ls -alF"; zi = "z -i"; # Interactive selection with fzf - firefox = "open -a Firefox"; preview = "open -a Preview"; - iina = "open -a IINA"; - dict = "open -a 'WordWeb Pro'"; slide = "open -a SlidePilot"; - ovito = "open -a Ovito"; - appcleaner = "open -a AppCleaner"; - wechat = "open -a WeChat"; - message = "open -a Messages"; - tmeet = "open -a TencentMeeting"; pixel = "open -a 'Pixelmator Pro'"; - keepass = "open -a KeePassXC"; inkscape = "open -a Inkscape"; - powerpoint = "open -a 'Microsoft PowerPoint'"; - word = "open -a 'Microsoft Word'"; - excel = "open -a 'Microsoft Excel'"; # Nix helpers hm = "home-manager"; @@ -119,6 +107,30 @@ in [[ -d "$target" ]] && cd "$target" || cd "$(dirname "$target")" fi } + + # Function to search and open all macOS applications + function app() { + local app_path + local file_to_open="$1" + + app_path=$( (find -L /Applications -name "*.app" -maxdepth 2 2>/dev/null; \ + find -L ~/Applications -name "*.app" -maxdepth 3 2>/dev/null; \ + find /System/Applications -name "*.app" -maxdepth 2 2>/dev/null; \ + find /System/Applications/Utilities -name "*.app" -maxdepth 1 2>/dev/null) | + sort | uniq | + fzf --header="Select app to open''${file_to_open:+ file: $file_to_open}" \ + --preview 'basename {} .app' \ + --preview-window=up:1 \ + --height=40%) + + if [[ -n "$app_path" ]]; then + if [[ -n "$file_to_open" ]]; then + open -a "$app_path" "$file_to_open" + else + open "$app_path" + fi + fi + } ''; };