Wrap macos-only config behind platform detection

This commit is contained in:
Yan Lin 2025-08-29 21:23:13 +02:00
parent d03e84b14a
commit 6691d3c037
6 changed files with 85 additions and 61 deletions

View file

@ -1,4 +1,4 @@
{ config, pkgs, ... }:
{ config, pkgs, lib, ... }:
let
projectsConfig = import ../config/projects.nix { homeDirectory = config.home.homeDirectory; };
@ -21,16 +21,18 @@ in
shellAliases = {
ll = "ls -alF";
zi = "z -i"; # Interactive selection with fzf
preview = "open -a Preview";
slide = "open -a SlidePilot";
pixel = "open -a 'Pixelmator Pro'";
inkscape = "open -a Inkscape";
# Nix helpers
hm = "home-manager";
hms = "home-manager switch --flake ~/.config/nix#yanlin";
hms-offline = "home-manager switch --flake ~/.config/nix#yanlin --option substitute false";
} // lib.optionalAttrs pkgs.stdenv.isDarwin {
# macOS-specific app aliases
preview = "open -a Preview";
slide = "open -a SlidePilot";
pixel = "open -a 'Pixelmator Pro'";
inkscape = "open -a Inkscape";
};
initContent = ''
@ -115,29 +117,31 @@ in
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"
# Function to search and open all macOS applications (macOS only)
${lib.optionalString pkgs.stdenv.isDarwin ''
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
fi
}
}
''}
# Interactive project launcher with fzf
function proj() {