Last active
April 11, 2025 11:57
-
-
Save mary-ext/da91d01efeb6a17bb25b30eda9cb326c to your computer and use it in GitHub Desktop.
fuzzel script for choosing which browser to open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# display name to command mapping | |
declare -A browsers=( | |
["Firefox Developer Edition"]="firefox-developer-edition" | |
["Chrome Canary"]="google-chrome-canary" | |
["Brave"]="brave" | |
["Brave Nightly"]="brave-nightly" | |
) | |
if [ "$#" -gt 1 ]; then | |
echo "usage: $(basename "$0") [URL]" >&2 | |
exit 1 | |
fi | |
# take first argument as URL | |
url="" | |
if [ "$#" -eq 1 ]; then | |
url="$1" | |
fi | |
prompt_text="Open: " | |
if [ -n "$url" ]; then | |
prompt_text="Open URL with: " | |
fi | |
# convert the browser values into a newline delimited string | |
options=$(printf "%s\n" "${!browsers[@]}" | sort) | |
# pass the options into fuzzel | |
chosen_name=$(echo -e "$options" | fuzzel -d -p "$prompt_text") | |
exit_status=$? | |
if [ $exit_status -ne 0 ] || [ -z "$chosen_name" ]; then | |
echo "browser selection cancelled" | |
exit 0 | |
fi | |
if [[ -v browsers["$chosen_name"] ]]; then | |
browser_command="${browsers[$chosen_name]}" | |
else | |
# this shouldn't happen though | |
echo "invalid browser selection '$chosen_name'" >&2 | |
exit 1 | |
fi | |
if [ -n "$url" ]; then | |
echo "opening '$chosen_name' with URL: $url" | |
"$browser_command" "$url" >/dev/null 2>&1 & | |
else | |
echo "opening '$chosen_name'" | |
"$browser_command" >/dev/null 2>&1 & | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment