Skip to content

Instantly share code, notes, and snippets.

@naranyala
Created September 6, 2023 08:07
Show Gist options
  • Save naranyala/f0927d2433a4b45b33231364471876ab to your computer and use it in GitHub Desktop.
Save naranyala/f0927d2433a4b45b33231364471876ab to your computer and use it in GitHub Desktop.
toggle rofi launcher to direct search in custom sites
#!/bin/bash
# Declare a custom array of websites
declare -A websites
websites["Google-Search"]="https://www.google.com/search?q=%s"
websites["Stack-Overflow"]="https://stackoverflow.com/search?q=%s"
websites["Youtube"]="https://www.youtube.com/results?search_query=%s"
websites["GitHub"]="https://github.com/search?q=%s"
websites["Twitter"]="https://twitter.com/search?q=%s"
websites["Hacker-News"]="https://hn.algolia.com/?query=%s"
websites["Google-Images"]="https://www.google.com/search?tbm=isch&q=%s"
# Use Rofi to select a custom website
selected_website=$(echo "${!websites[@]}" | tr ' ' '\n' | rofi -dmenu -p "Custom Web Search:")
# Prompt the user for a search query
if [ -n "$selected_website" ]; then
search_query=$(rofi -dmenu -p "Search $selected_website:")
# Construct and open the search URL with xdg-open
if [ -n "$search_query" ]; then
search_url="${websites[$selected_website]//%s/$search_query}"
xdg-open "$search_url"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment