fuzzel-run-or-search.sh 574 B

12345678910111213141516
  1. #!/bin/bash
  2. # Run a command, or fall back to a web search if it isn't one.
  3. # fuzzel --dmenu prints the typed string as-is when nothing matches,
  4. # which is what makes the search fallback work.
  5. result=$(compgen -c | sort -u | fuzzel --dmenu --prompt "🔍 ")
  6. [ -z "$result" ] && exit 0
  7. if command -v "${result%% *}" &>/dev/null; then
  8. exec $result
  9. else
  10. query=$(python3 -c "import urllib.parse, sys; print(urllib.parse.quote_plus(sys.argv[1]))" "$result")
  11. xdg-open "https://duckduckgo.com/?q=$query" &
  12. sleep 0.5
  13. swaymsg '[app_id="google-chrome"] focus'
  14. fi