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