This page looks best with JavaScript enabled

You Can Make Anything With Rofi

 ·   ·  ☕ 7 min read · 👀... views

What is rofi?

Rofi is a popup list displayer which will display a list of whatever you want and do whatever you want with the selection you make from the prompted list.

Rofi started as a clone of simpleswitcher, written by Sean Pringle - a popup window switcher roughly based on superswitcher. Simpleswitcher laid the foundations, and therefore Sean Pringle deserves most of the credit for this tool. Rofi (renamed, as it lost the simple property) has been extended with extra features, like an application launcher and ssh-launcher, and can act as a drop-in dmenu replacement, making it a very versatile tool.
Rofi - GitHub

Rofi currently supports only X server. But you can find some forks of Rofi making them support wayland such as this one.

Some use cases of Rofi

Below I am proving some functionalities I use regularly with the help of Rofi. You can find all my dotfiles related to rofi in this link

Manage your configuration files

I use the git bare repository method to manage my dotfiles which is explained here. To manager your dotfiles, you have to create a folder where your .git directory will stay. After that, type the three commands below. I have considered my .git directory to be in ~/.dots-git directory.

1
2
3
4
5
6
# Initialize the repository
git init --bare $HOME/.dots-git
# make an alias to convenience (put this in your init script like bashrc/zshrc file)
alias dotfiles='/usr/bin/git --git-dir=$HOME/.dots-git/.git --work-tree=$HOME'
# Untrack files from your working directory
dotfiles config --local status.showUntrackedFiles no

After doing this, you can add a config file to manage with git with the following command.

1
2
dotfiles add FILE_NAME
dotfiles commit -m "Updated FILE_NAME and added THIS function"

You can also put your configs to a repository online by setting up a remote. Google if you don’t know how to manage git repositories.

In a fresh installation, you can download and run the below command from an online gist and all your settings will come back to the new machine!

The below script will overwrite your current settings.
1
2
3
4
5
6
cd $HOME
mkdir -p .dots-git/git-control/.git
/usr/bin/git clone YOUR_GIST_LINK --bare .dots-git/git-control/.git
alias dotfiles='/usr/bin/git --git-dir=$HOME/.dots-git/git-control/.git --work-tree=$HOME'
dotfiles checkout -f
echo "DONE"

Okay, as now you know how to manage your dots with git, lets setup rofi to quickly see and open your managed dotfiles. Below is the script:

1
2
3
4
5
6
7
8
9
#!/bin/bash

# Options
DOTS_GIT=$HOME/.dots-git/git-control/.git

dotfile_paths=$(/usr/bin/git --git-dir=$DOTS_GIT --work-tree=$HOME ls-tree -r master --name-only)

chosen="$(echo -e "$dotfile_paths" | rofi -dmenu -no-custom)"
[ -f "$chosen" ] && $TERMINAL $EDITOR $chosen || dunstify "No such file"

The main idea behind this is the command dotfiles ls-tree -r master --name-only which will print all the files in your git repository. The rest is pretty much simple to understand.

dotfiles

Use rofi as OCR

I am currently learning Japanese. So I often need to see the meaning of an article from a book written in English or Japanese. For this, I use tesseract and its language model dependencies. You will also need scrot to take screenshots of your desired portion of screen and imagemagick for some image processing. If you are using Arch Linux, go ahead and install them with one liner.

1
yay -S tesseract tesseract-data-eng tesseract-data-jpn tesseract-data-ben scrot

Then, all you need is to write a small script and assign it a keybinding.

 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
#!/bin/bash
# DEPENDENCIES: tesseract-ocr imagemagick scrot

APP_NAME="Screen Reader"

export LC_ALL=en_US.UTF-8

LANG="$(echo -e "eng\nita\ndeu\nben\njpn" | rofi -dmenu -no-custom)"
if [ -z "$LANG" ]; then 
	dunstify -a "$APP_NAME" "Invalid Language" 
	exit 1
fi

echo "Language set to $LANG"

SCR_IMG=$(mktemp) # create tempfile
trap "rm $SCR_IMG*" EXIT # make sure tempfiles get deleted afterwards

#take screenshot of area
scrot -s "$SCR_IMG".png -q 100
# postprocess to prepare for OCR
mogrify -modulate 100,0 -resize 400% "$SCR_IMG".png 
# OCR in given language
tesseract -l "$LANG" "$SCR_IMG".png "$SCR_IMG"
xsel -bi < "$SCR_IMG".txt # pass to clipboard
dunstify -a "$APP_NAME" "Text Copied to clipboard"
I have used dunstify to display nice notification when the OCR is done or the language could not be detected. You can comment those lines out if you do not wish to use it.

This script will first prompt the language you want to do OCR on, then start scrot screen clipping mode. Then it will do the ORC and copy the text in your clipboard.

ocr

Super useful plugins

Rofi is already mighty by itself as it can display a list to run any application in from you desktop files or commandline programs. It can also switch focus to a open window regardless of which workspace/desktop the window is in, as long as your window manager implements Window Manager Specification Project. But to enhance its functionality beyond just a application launcher, you can add tons of plugins taken from the internet (or make one yourself). Below are the plugins I use in my daily driver machine most of which are taken straight from the AUR. Below is the image of my main rofi interface.

rofi-main

I achieved this by using the following launch script and some theming with rasi.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#! /bin/sh

rofi \
	-modi combi,file-browser,"CALC:qalc +u8 -nocurrencies","CLIPBOARD:greenclip print",run \
	-show combi \
	-combi-modi window,drun \
	-display-combi APPS \
	-display-drun "" \
	-display-window "󰖯" \
	-display-file-browser FILES \
	-display-run SHELL \
	-columns 2 \

1. rofi-calc

Bring the calculator up straight hitting a shortcut key. And don’t think this lightweight calculator will do just some addition and substitution. It can do advanced calculations like the below one.

> solve(x*x/pi = 3 acres) to km
solve(((x * x) / pi) = (3 * acre), x) = 6.1758176 km

> fibonacci(133) to hex
fibonacci(133) = 0x90540BE2616C26F81F876B9

> 50m*2kg/50h to ?N
(50 meter (2 kilogram)) / (50 hour) = 555.55556 μNs

It can do this, because it uses libqalculate as the backend.

2. rofi-dmenu

A lot of program sometimes use dmenu for querying user or display things. If you have rofi installed, there is actually no reason to keep dmenu just for those applications because rofi can do everything dmenu does. But, well, the programs will look for dmenu anyways. So you can just manually create an alias for rofi -dmenu to use rofi as an in-place replacement for dmenu. Or, what I do is install this Arch package which does exactly this.

3. rofi-file-browser-extended

Yes, Rofi can be used as a file browser. If you want to quickly open up a file from not so deep directory in you home, you do not need to open up a heavy file manager (e.g. Nautilus/Thunar). Just use super + space (or whatever you like) to open up file browser and open a file. But as the name says, it is just a file browser, not a file manager. So you cannot copy/cut/paste your files or do such like things.

4. rofi-greenclip

Greenclip is a simple clipboard manager which has functionality to save your clipboard and manage them in your own way. Rofi-greenclip is an extension of rofi for the interfacing of greenclip. You can see your clipboard history and copy any text among those.

Rofi-search is a interactive web searching shortcut supporting Google and Duckduckgo. You can just search first from rofi and then open up your desired website only on your favorite browser. I did not include this with my default rofi access menu because it serves a bit different purpose than doing things in the desktop. So it has a separate keybinding in my machine. I use the below script to use in a keybinding.

1
GOOGLE_ARGS='["--count", 10]' rofi -modi blocks -blocks-wrap rofi-search -show blocks -lines 5 -eh 4 -kb-custom-1 'Control+y'

rofi-search

6. rofi-top

Rofi-top shows top in your rofi. Thats it. I have put a keybinding like this in my sxhkdrc.

1
2
super + r; t
	rofi -modi top -show top -eh 1 -kb-custom-1 'Alt+m' -kb-custom-5 'Alt+c'

As you can see, I can clearly tell that my google-chrome is eating up all my memory for opening 4 tabs 😄 alongside the VSCode behind this picture.

rofi-top

7. rofimoji

The last extension is what I use the most while writing an article or code. I have also specified a separate keybinding for this extension. Whenever I need an emoji, I search it in rofi and rofi automatically takes it into the clipboard and also puts one emoji of that into the focused text area.

rofimoji

Conclusion

I have read in the internet someone sarcastically saying to just use rofi to make a desktop environment. But to be honest, with some major tweaking of the code, it is not much far from impossible. If you use rofi in a cool way, please share it in the comments so I also can use it.

Share on

Rahat Zaman
WRITTEN BY
Rahat Zaman
Graduate Research Assistant, School of Computing