Files
NixOS-Configs/home/hypr/quickshell/scripts/get_apps.sh

67 lines
2.6 KiB
Bash
Executable File

#!/usr/bin/env bash
# Scans .desktop files and outputs JSON array of apps
dirs=(
"/run/current-system/sw/share/applications"
"$HOME/.nix-profile/share/applications"
"$HOME/.local/share/applications"
"/usr/share/applications"
)
declare -A seen
apps="["
first=true
# Add default curated Mac/system apps first
curated=(
'{"name":"Finder","exec":"foot -e sh -c \"cd ~; lf || yazi || ls -la; exec zsh\"","icon":"finder","comment":"File Manager"}'
'{"name":"Terminal","exec":"foot","icon":"terminal","comment":"Command Line Interface"}'
'{"name":"Brave Browser","exec":"brave","icon":"browser","comment":"Web Browser"}'
'{"name":"Neovim","exec":"foot -e nvim","icon":"code","comment":"Text & Code Editor"}'
'{"name":"System Preferences","exec":"pavucontrol","icon":"preferences","comment":"Audio & System Settings"}'
'{"name":"Activity Monitor","exec":"foot -e btop","icon":"preferences","comment":"Resource Monitor"}'
'{"name":"Lock Screen","exec":"hyprlock","icon":"preferences","comment":"Lock current session"}'
'{"name":"Restart System","exec":"systemctl reboot","icon":"preferences","comment":"Reboot NixOS"}'
'{"name":"Shut Down","exec":"systemctl poweroff","icon":"preferences","comment":"Power off computer"}'
)
for app in "${curated[@]}"; do
if [ "$first" = true ]; then
apps="$apps$app"
first=false
else
apps="$apps,$app"
fi
done
for dir in "${dirs[@]}"; do
if [ -d "$dir" ]; then
for f in "$dir"/*.desktop; do
[ -e "$f" ] || continue
# Check NoDisplay
if grep -q "^NoDisplay=true" "$f" 2>/dev/null; then
continue
fi
name=$(grep -m 1 "^Name=" "$f" 2>/dev/null | cut -d= -f2- | tr -d '\r\n')
exec_cmd=$(grep -m 1 "^Exec=" "$f" 2>/dev/null | cut -d= -f2- | sed -E 's/%[fFuUdDnNickvm]//g' | tr -d '\r\n')
icon=$(grep -m 1 "^Icon=" "$f" 2>/dev/null | cut -d= -f2- | tr -d '\r\n')
comment=$(grep -m 1 "^Comment=" "$f" 2>/dev/null | cut -d= -f2- | tr -d '\r\n')
if [ -n "$name" ] && [ -n "$exec_cmd" ] && [ -z "${seen[$name]}" ]; then
seen[$name]=1
# Escape quotes
name_esc=$(echo "$name" | sed 's/"/\\"/g')
exec_esc=$(echo "$exec_cmd" | sed 's/"/\\"/g')
icon_esc=$(echo "$icon" | sed 's/"/\\"/g')
comment_esc=$(echo "$comment" | sed 's/"/\\"/g')
entry="{\"name\":\"$name_esc\",\"exec\":\"$exec_esc\",\"icon\":\"$icon_esc\",\"comment\":\"$comment_esc\"}"
apps="$apps,$entry"
fi
done
fi
done
apps="$apps]"
echo "$apps"