Skip to content

Instantly share code, notes, and snippets.

@webstrand
Created September 3, 2023 06:08
Show Gist options
  • Select an option

  • Save webstrand/347dbc34722fd5cecfb86e84be9c6e10 to your computer and use it in GitHub Desktop.

Select an option

Save webstrand/347dbc34722fd5cecfb86e84be9c6e10 to your computer and use it in GitHub Desktop.
Bash script to find and launch .desktop files with dmenu (currently broken)
#!/bin/bash
set -euo pipefail
IFS=$'\n\t'
shopt -s lastpipe
IFS=':' read -ra data_dirs <<< "${XDG_DATA_HOME:-$HOME/.local/share}${XDG_DATA_DIRS:+:$XDG_DATA_DIRS}";
locale lang_ab country_ab2 charmap | readarray -t locale;
declare -A dictionary;
fd --unrestricted --type file --extension desktop . "${data_dirs[@]/%/\/applications}" --print0 |
xargs -0 rg --multiline "\[Desktop Entry\][^\[]+^(Name(\[${locale[0]}(_${locale[1]}(\.${locale[2]})?)?\])?=.*)" --null --only-matching --replace '$1' -- |
while IFS= read -r -d '' file && IFS= read -r -d '=' field && IFS= read -r -d $'\n' value; do
dictionary["$value"]=$file;
done;
echo "${!dictionary[*]}" | dmenu -i -f | IFS= read target;
exec xdg-open ${dictionary[$target]};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment