Add initial rofi-bangs script
Can be executed with rofi-bang. It will take a comma-separated list of commands (for now statically sourced from rofi config dir), show labels and 'bangs' for them (in the manner of !c or !yt) which, if typed will instantly execute their command. In this manner, it becomes possible to create a quickly accessible menu using rofi. E.g. we could have !b to search bookmarks. As soon as !b is typed the 'bang' instance of rofi exits and executes the associated command. If the command starts up another, visually identical, rofi instance with a preselection of different user bookmarks, it appears as if we just jumped into a bookmark list in the same rofi instance. Of course, the commands can be anything. They don't have to invoke more rofi instances.
This commit is contained in:
parent
f1bcae1767
commit
264e095224
2 changed files with 54 additions and 0 deletions
6
.config/rofi/rofi-bang-commands.csv
Normal file
6
.config/rofi/rofi-bang-commands.csv
Normal file
|
@ -0,0 +1,6 @@
|
|||
Calculator,!c,source,"rofi -show calc -modi calc -no-show-match -no-sort -theme Arc-Dark"
|
||||
Clipboard,!y,source,"rofi -modi "clipboard:greenclip print" -show clipboard -run-command '{cmd}' -theme Arc-Dark"
|
||||
Emojis,!e,source,"rofimoji --rofi-args '-theme sidebar'"
|
||||
Youtube,!yt,source,"someroficommand"
|
||||
Wikipedia,!w,source,"someroficommand"
|
||||
DuckDuckGo,!ddg,source,"someroficommand"
|
Can't render this file because it contains an unexpected character in line 2 and column 33.
|
48
.local/bin/rofi-bang
Executable file
48
.local/bin/rofi-bang
Executable file
|
@ -0,0 +1,48 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
#
|
||||
# rofi-bang
|
||||
#
|
||||
|
||||
# Allows execution of arbitrary commands through rofi by
|
||||
# invoking shell scripts. These shell scripts can in turn
|
||||
# of course be other rofi commands, which allows the creation
|
||||
# of chained rofi executions (e.g. !c 1+2) to run a
|
||||
# calculator script within rofi and immediately execute it.
|
||||
# Hence, rofi-bang.
|
||||
|
||||
cwd="$XDG_CONFIG_HOME"/rofi
|
||||
if [ ! -d "$cwd" ]; then
|
||||
echo "The necessary directory at $HOME/.config/rofi is not set up correctly."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cmdfile="$cwd/rofi-bang-commands.csv"
|
||||
if [ ! -f "$cmdfile" ]; then
|
||||
echo "The nessesary file at $cwd/rofi-bang-commands.csv has not been found."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Present the initial selection screen - but as soon as only one candidate is left exit out
|
||||
# since bangs are unique (!text will not be matched by anything else) it should automatically exit
|
||||
# whenever a bang has been typed
|
||||
selection=$(
|
||||
cut <"$cmdfile" -s -d ',' -f 1,2 |
|
||||
sed 's/,/: /' |
|
||||
printf "%s\n%s\n%s" "$(cat -)" "suffix that is not in cmd file" "one last entry" |
|
||||
rofi -dmenu -i -p "Run> " -theme "Arc-Dark" -auto-select |
|
||||
sed 's/: /,/' |
|
||||
head -n 1
|
||||
)
|
||||
# we did not select anything, just exit
|
||||
if [ -z "$selection" ]; then exit 0; fi
|
||||
|
||||
# we selected something, check if it is in the bang commands file
|
||||
# if it is, we should execute the bang
|
||||
is_bang=$(grep "$selection" "$cmdfile")
|
||||
if [ -n "$is_bang" ]; then
|
||||
cmd=$(echo "$is_bang" | cut -s -d ',' -f 4)
|
||||
echo "$cmd" | xargs --no-run-if-empty -I "{}" /bin/bash -c "{}"
|
||||
else
|
||||
echo "not implemented yet, should re-run rofi with the exact same settings"
|
||||
fi
|
Loading…
Reference in a new issue