summaryrefslogtreecommitdiffstats
path: root/local/bin/dmenu-webshortcuts.sh
blob: e1d233c0cb44c6fc2c78aab1566f88acf15a6abd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash

# Use dmenu and user-defined web shorcuts to query websites faster.
#
# This script tries to mimic Krunner Web Search Keywords functionality.
# See: https://userbase.kde.org/Plasma/Krunner#Browse_websites
#
# TODO: Integrate it to dmenu_run (so that this script doens't require a
#       dedicated keybinding)
#
# Mitsuo
# 2023-11-23

input=$(echo "" | dmenu -p 'wp:Hello World')
## Set Internal Field Separator, save separated fields as an array in $CMD (-a),
## don't allow backslashes to escape any characters (-r).  Feed $input as stdin.
#IFS=':' read -ra CMD <<< "$input"
#keyword=${CMD[0]}
#search_term=${CMD[1]}
keyword="${input%%:*}"
search_term="${input#*:}"

# Define web shortcuts here
case "$keyword" in
    # Search
    "dd") xdg-open "https://duckduckgo.com/?t=h_&q=${search_term// /+}" ;;
    "gg") xdg-open "https://www.google.com/search?q=$search_term" ;;
    "bing") xdg-open "https://www.bing.com/search?q=${search_term// /+}" ;;
    "metac") xdg-open "https://www.metacrawler.com/serp?q=${search_term// /+}" ;;

    # Finance
    "ggf") xdg-open "https://www.google.com/finance/quote/$search_term?window=1Y" ;;
    "yf") xdg-open "https://finance.yahoo.com/quote/$search_term" ;;
    "bb") xdg-open "https://www.bloomberg.com/quote/$search_term" ;;

    # Maps
    "ggm") xdg-open "https://www.google.com/maps/search/${search_term// /+}" ;;
    "osm") xdg-open "https://www.openstreetmap.org/search?query=$search_term" ;;
    
    # Reference
    "wp") xdg-open "https://en.wikipedia.org/wiki/${search_term// /_}" ;;
    "wt") xdg-open "https://en.wiktionary.org/wiki/${search_term// /_}" ;;
    "wv") xdg-open "https://en.wikivoyage.org/wiki/${search_term// /_}" ;;
    "scholar") xdg-open "https://scholar.google.com/scholar?hl=en&q=${search_query// /+}" ;;
    "arxiv") xdg-open "https://arxiv.org/search/?query=${search_query// /+}" ;;

    # Computer
    "arch") xdg-open "https://wiki.archlinux.org/index.php?search=${search_term// /+}" ;;
    "aur") xdg-open "https://aur.archlinux.org/packages?O=0&K=${search_term// /+}" ;;
    "so") xdg-open "https://stackoverflow.com/search?q=${search_term// /+}" ;;
    "gh") xdg-open "https://github.com/search?q=${search_term// /+}&type=repositories" ;;
    "gl") xdg-open "https://about.gitlab.com/search?searchText=$search_term" ;;
    "pypi") xdg-open "https://pypi.org/search/?q=${search_term// /+}&o=" ;;
    "npm") xdg-open "https://www.npmjs.com/search?q=${search_term// /+}" ;;

    # Media
    "yt") xdg-open "https://www.youtube.com/results?search_query=$search_term" ;;
    "vm") xdg-open "https://vimeo.com/search?q=$search_term" ;;
    "sp") xdg-open "https://open.spotify.com/search/$search_term" ;;
    "sc") xdg-open "https://soundcloud.com/search?q=$search_term" ;;
    "dz") xdg-open "https://www.deezer.com/search/$search_term" ;;
    "imdb") xdg-open "https://www.imdb.com/find/?q=$search_term" ;;

    # Social Media
    "x") xdg-open "https://x.com/search?q=$search_term&src=typed_query" ;;
    "rd") xdg-open "https://duckduckgo.com/?t=h_&q=site%3Areddit.com+${search_term// /+}&ia=web" ;;
    "ig") xdg-open "https://duckduckgo.com/?q=site%3Ainstagram.com+${search_term// /+}&ia=web" ;;
    "fb") xdg-open "https://duckduckgo.com/?q=site%3Afacebook.com+${search_term// /+}&ia=web" ;;

    # Shopping
    "amzn") xdg-open "https://www.amazon.com/s?k=${search_term// /+}" ;;
    "amznjp") xdg-open "https://www.amazon.co.jp/s?k=${search_term// /+}" ;;
    "ebay") xdg-open "https://www.ebay.com/sch/i.html?_nkw=${search_term// /+}" ;;

    # Utilities
    "ggt") xdg-open "https://translate.google.com/?sl=auto&tl=en&text=$search_term&op=translate" ;;
    "en2es") xdg-open "https://www.wordreference.com/es/translation.asp?tranword=$search_term" ;;
    "es2en") xdg-open "https://www.wordreference.com/es/en/translation.asp?spen=$search_term" ;;
    "en2de") xdg-open "https://www.wordreference.com/es/en/translation.asp?spen=$search_term" ;;
    "de2en") xdg-open "https://www.wordreference.com/deen/$search_term" ;;
    "jisho") xdg-open "https://jisho.org/search/$search_term" ;;
    "rae") xdg-open "https://dle.rae.es/?w=$search_term" ;;

    # Mitsuo
    "pw") xdg-open "http://wiki.pulse15/index.php?search=${search_term// /+}" ;;
    "factorio") xdg-open "https://wiki.factorio.com/${search_term// /_}" ;;
    "dst") xdg-open "https://dontstarve.wiki.gg/wiki/${search_term// /_}" ;;
    "mc") xdg-open "https://minecraft.wiki/w/${search_term// /_}" ;;
    "terraria") xdg-open "https://terraria.wiki.gg/wiki/${search_term// /_}" ;;

    *) exit 1 ;;
esac