This is the second in a series of several posts on how to do way more than you really need to with rofi. It’s a neat little tool that does so many cool things. I don’t have a set number of posts, and I don’t have a set goal. I just want to share something I find useful.

This post looks at basic rofi configuration.

Assumptions

I’m running Fedora 27. Most of the instructions are based on that OS. This will translate fairly well to other RHEL derivatives. The Debian ecosystem should also work fairly well, albeit with totally different package names. This probably won’t work at all on Windows, and I have no intention of fixing that.

You’re going to need a newer version of rofi, >=1.4. I’m currently running this:

$ rofi -version
Version: 1.4.2-131-git-5c5665ef (next)

If you installed from source, you should be good to go.

Code

You can view the code related to this post under the post-02-basic-config tag.

Config File

At the momemnt, rofi is using default values and (probably) refers to a config file that doesn’t exist.

$ rofi --help \
| awk -F':' '/Configuration/{ print "cat "$2 }' \
| . /dev/stdin

cat: $XDG_USER_CONFIG_DIR/rofi/config: No such file or directory

rofi provides a couple of ways to load config (plus templating it for new users). We’ll need to create the user directory via $XDG_USER_CONFIG_DIR first:

$ echo $XDG_USER_CONFIG_DIR || echo "export XDG_USER_CONFIG_DIR=/path/to/desired/.config" >> ~/.whateverrc && source ~/.whateverrc
$ mkdir -p $XDG_USER_CONFIG_DIR/rofi

Since we’re running >=1.4, we can use the new config format.

$ rofi -dump-config > $XDG_USER_CONFIG_DIR/rofi/config.rasi

We’ve now got a super basic config file that contains every possible option (I think) commented out.

Theme File

While we’re at it, we might as well dump the theme too.

$ rofi -dump-theme > $XDG_USER_CONFIG_DIR/rofi/theme.rasi

To ensure the theme is actually consumed, we’ll need to update the config.

$ sed \
--in-place='.bak' \
--regexp-extended \
-e "s~^.*\stheme:.*$~\ttheme: \"$XDG_USER_CONFIG_DIR/rofi/theme.rasi\";~g" \
$XDG_USER_CONFIG_DIR/rofi/config.rasi

Scripted

If you’re like me, you’re going to mess up the config on a fairly regular basis. Same goes if you’re actively developing with rofi. It’s useful to have a quick method to rebuild defaults.

force-default-config
 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
#!/bin/bash

ROOT_DIR="$XDG_USER_CONFIG_DIR/rofi"

function rebuild_config {
rm -rf $ROOT_DIR/config*
rofi -dump-config > $ROOT_DIR/config.rasi
}

function rebuild_theme {
rm -rf $ROOT_DIR/theme*
rofi -dump-theme > $ROOT_DIR/theme.rasi
}

function reconnect_theme {
sed \
--in-place='.bak' \
--regexp-extended \
-e "s~^.*\stheme:.*$~\ttheme: \"$ROOT_DIR/theme.rasi\";~g" \
$ROOT_DIR/config.rasi
}

if [[ -n "$1" ]]; then
INPUT="$1"
else
INPUT=$(
echo -e "config\ntheme\nall" \
| rofi \
-dmenu \
-mesg 'forcibly rebuild config' \
-no-fixed-num-lines \
-width 24 \
-hide-scrollbar \
-theme-str '#inputbar { children: [entry,case-indicator]; }' \
-theme-str '#listview { dynamic: true; }' \
-theme-str '#mainbox { children: [message,inputbar,listview]; }' \
-theme-str '#message { border: 0; background-color: @selected-normal-background; text-color: @selected-normal-foreground; }' \
-theme-str '#textbox { text-color: inherit; }'
)
if [[ -z $INPUT ]]; then
exit 0
fi
fi

case "$INPUT" in
config)
rebuild_config
;;
theme)
rebuild_theme
;;
all)
rebuild_config
rebuild_theme
;;
*)
echo "usage: $0 {config,theme,all}"
exit 1
;;
esac
reconnect_theme

This script works both via the CLI and via the GUI, thanks to rofi.

$ scripts/force-default-config all
(rebuilds everything)
$ scripts/force-default-config

basic-config-scripted-gui