scripting with rofi is awesome
Scrolling through my Youtube feed I stumbled across Bread on Penguins video1 about her dmenu scripts. This inspired me to write some of my own. I would also recommend her channel to everyone intrested in linux stuff.
what even is rofi?
Rofi is a fuzzy finder with which you can launch applications, switch windows and more. It really is a convenient way of interacting with ones operating system.
I originally only used it for launching applications and rarely for switching to windows. But integrating it in scripts opens up a lot of possibilities, since it is a simple way of getting user input in a variety of forms.
my scripts
DISCLAIMER these scripts are made by me for me and fit my system and workflow. They may be usefull for inspiration but will moste likely not work out of the box. They are also going to change over time and wont be updated here.
.select.sh
This is the script with which I start the other scripts.
And yes the filename starts with a dot.
Since ls
by default does not list files that are “hidden”,
I have a way of excluding scripts/files which should not be listed in the selection.
source
#!/bin/bash here=$(dirname -- "$0") # gets the path to this script script=$(ls $here | rofi -dmenu -p "select") cd "$here" bash "$script"
calc
Simple script piping the input of rofi into bc and back. Works great for simple calculations, and more if you know how to use bc.
source
# vim: filetype=sh out=$( # so the output of the last calculation gets shown in rofi if [[ ! -z "$@" ]]; then echo "$@" fi | rofi -dmenu -p "bc" | bc -l ) # only rerun this script if the the output is not empty # -> to be able to exit if [[ ! -z "$out" ]]; then bash "$0" "$out" fi
kill
This is a one-liner I stole from Bread on Penguins, which gives me the pid, name and args of running processes to select from. The selected process will then be killed.
I should probably add a confirmation menu though.
source
#!/bin/bash # vim: filetype=sh ps -u $USER -o pid,comm,args | rofi -dmenu -p "kill" | awk '{print $1}' | xargs -r kill
dict
This is the launching script for .dict since it has to be opened in a terminal window to work. Yes it technically is not really a “rofi script”, but it is just so awesome that i have to include it.
source
#!/bin/bash # vim: filetype=sh alacritty --hold -e bash .dict #Examples for other terminals # konsole --hold -e "bash .dict" # gnome-terminal --wait -- bash .dict # xterm -hold -e "bash .dict"
.dict
This is the cool script :D At least for someone who likes to look words up in the dictionary lol. With this I am able to quickly fzf in the dictionaries I have set up for dictd.
It opens up a floating terminal window at the right of my primary monitor in which i can search for words. If I want to view the definiton(s) for a word easier I can simply press enter and view it with bat, since scrolling does not really work well with fzf.
source
#!/bin/bash # vim: filetype=sh #DEPENDENCIES # i3 # working dict setup # colorit (+ m4) # bat # fzf # (bash) i3-msg floating enable i3-msg resize set 35 ppt 100 ppt i3-msg move position 65 ppt 0 ppt i3-msg move to output primary i3-msg focus output primary i3-msg focus floating #dict='reload: dict {q} || :' #spell='reload:echo {q} | hunspell -a -d de_DE,en_US,en_GB | tail -2 || :' this="$0" RELOAD='reload: dict {q} | colorit || :' OPENER="dict {q} | colorit | bat --style grid,header --paging always ; bash $this" fzf --disabled --ansi --multi \ --bind "start:$RELOAD" --bind "change:$RELOAD" \ --bind "ctrl-s:execute:RELOAD=$" \ --bind "enter:become:$OPENER" \ --reverse \ --delimiter :
planned scripts / ideas
Some other script ideas I have had or came across:
- rofi keepassxc: easily copy keepassxc entries with rofi
- clipboard manager
Footnotes:
Dmenu Is Extremely Powerful, If You Get Creative, 2025. https://www.youtube.com/watch?v=4JWeU78A95c.