spmenu-wiki/Cool spmenu tricks.md

58 lines
2.1 KiB
Markdown
Raw Normal View History

# Cool spmenu tricks
2023-06-04 23:48:06 +02:00
This wiki article is intended to be a list of cool things you can do with
spmenu that I find very useful, and have changed the way I use my computer.
- clipmenu-spmenu
2023-06-04 23:48:06 +02:00
This is listed in [[User scripts]] too, but clipmenu is extremely useful.
With clipmenu, everything in the clipboard is saved, and you can easily pull up
a spmenu list of everything in your clipboard and then use it again.
If you're the kind of person that copies a lot of text all the time and then later
wants to use that same text again, this script is extremely useful.
- spmenu_run: Web searches
2023-06-04 23:48:06 +02:00
If you've read [[Functions in spmenu_run]] you're already aware that things
like this can be done with ease, but here's another use of the
`run_post_func()` function.
2023-06-04 23:48:06 +02:00
Open `~/.config/spmenu/run/config` and add a function like this to the config:
```Shell
2023-06-04 23:48:06 +02:00
run_post_func() {
case "${1:0:1}" in # first char
"s") query="$(printf "%s\n" "$1" | sed "s/s //; s/ /+/g")" && chromium
"http://localhost:8888/search?q=$query";
;;
2023-06-04 23:48:06 +02:00
esac
}
2023-06-04 23:48:06 +02:00
```
Note that you should replace `http://localhost:8888` here with the search engine
you use. Every search engine I've ever used uses this same format, though.
In this `case` statement, we're checking if the first character is `s`. If it is,
we get everything except `s` from the input, and in the latter half of the `sed`
2023-06-04 23:48:06 +02:00
we also replace all spaces with `+`, which search engines translate into a space.
You can easily add more search engines, too if you want.
```Shell
2023-06-04 23:48:06 +02:00
run_post_func() {
case "${1:0:1}" in # first char
"s") query="$(printf "%s\n" "$1" | sed "s/s //; s/ /+/g")" && chromium
"http://localhost:8888/search?q=$query" ;; "d") query="$(printf "%s\n"
"$1" | sed "s/d //; s/ /+/g")" && chromium
"https://duckduckgo.com/search?q=$query" ;; "r") query="$(printf "%s\n"
"$1" | sed "s/r //; s/ /+/g")" && chromium
"https://reddit.com/search?q=$query"
;;
2023-06-04 23:48:06 +02:00
esac
}
2023-06-04 23:48:06 +02:00
```
In this example, I've added duckduckgo searches using the `d` prefix and Reddit
searches using the `r` prefix. Pretty cool.