paapereira.xyz

Rofi: a window switcher, application launcher and dmenu replacement

Rofi is a window switcher, application launcher and dmenu replacement.

I’ve been using rofi with i3-gaps since early 2019. I had played with it before, but I’ve been using it daily the last couple of years.

I use it to launch applications, open ssh sessions, with pass and with a set of useful custom scripts.

Installation

You need to install the rofi package. I also installed rofi-dmenu for dmenu compatibility, rofi-pass to use with pass and the extra rofi-emoji and rofi-calc.

1paru -S rofi rofi-dmenu rofi-pass rofi-emoji rofi-calc

Executing

You can run Rofi in different modes depending if you want to launch an application, open a ssh session, change windows or executing a command in the terminal.

Check Rofi at github and man rofi for more details.

In my setup, and using i3-gaps (learn more here) I use it to accomplish a series of tasks:

1bindsym    $mod+d     exec --no-startup-id "rofi -modi combi -show combi -combi-modi drun,run"

rofi

1bindsym    $mod+p    exec --no-startup-id rofi-pass

pass

1bindsym    $mod+s    exec --no-startup-id rofi -show ssh
1bindsym    $mod+f    exec --no-startup-id websearch

websearch

Here’s my websearch script, inspired by ditrotube.

 1cat .local/bin/websearch
 2
 3#!/usr/bin/env bash
 4
 5DMBROWSER="/usr/bin/librewolf"
 6
 7declare -a options=(
 8"searx - https://searx.tuxcloud.net/?q="
 9"amazon - https://www.amazon.com/s?k="
10"kindlebooks - https://www.amazon.com/s?rh=n%3A154606011&ref=nb_sb_noss&k="
11"youtube - https://www.youtube.com/results?search_query="
12"goodreads - https://www.goodreads.com/search?q="
13"archaur - https://aur.archlinux.org/packages/?O=0&K="
14"archpkg - https://archlinux.org/packages/?sort=&q="
15"archwiki - https://wiki.archlinux.org/index.php?search="
16"audible - https://audible.com/search?keywords="
17"duckduckgo - https://duckduckgo.com/lite/?q="
18"github - https://github.com/search?q="
19"gitlab - https://gitlab.com/search?search="
20"google - https://www.google.com/search?q="
21"reddit - https://www.reddit.com/search/?q="
22"quit"
23)
24
25while [ -z "$engine" ]; do
26  enginelist=$(printf '%s\n' "${options[@]}" | rofi -dmenu -p 'Choose search engine:') || exit
27  engineurl=$(echo "$enginelist" | awk '{print $NF}')
28  engine=$(echo "$enginelist" | awk '{print $1}')
29done
30
31while [ -z "$query" ]; do
32  if [[ "$engine" == "quit" ]]; then
33    echo "Program terminated." && exit 0
34  else
35    query=$(echo "$engine" | rofi -dmenu -p 'Enter search query:') || exit
36  fi
37done
38
39$DMBROWSER "$engineurl""$query"
40
41#eof

Configuration

The rofi configuration file is located at .config/rofi/config.rasi.

 1cat .config/rofi/config.rasi
 2
 3configuration {
 4    modi:                   "run,ssh,window,combi,drun,windowcd";
 5    matching:               "fuzzy";
 6    show-icons:             true;
 7    theme:                  "~/.config/rofi/themes/dmenu.rasi";
 8    font:                   "Cantarell Regular 11";
 9    icon-theme:             "oomox-gruvbox-dark";
10    lines:                  7;
11    separator-style:        "solid";
12    hide-scrollbar:         true;
13    kb-row-down:            "Control+j";
14    kb-row-up:              "Control+k";
15    kb-accept-entry:        "Return,KP_Enter";
16    kb-remove-to-eol:       "";
17    display-drun:           "Open";
18    display-run:            "❯ sh";
19    display-combi:          "";
20    display-window:         "Change window";
21    display-windowcd:       "Change window (same workspace)";
22    terminal:               "/usr/bin/alacritty";
23    ssh-command:            "{terminal} -e {ssh-client} {host}";
24}

I’m using a theme to emulate dmenu, but I used a gruvbox inspired on until recently.

 1cat .config/rofi/themes/dmenu.rasi
 2
 3* {
 4    background-color:   Black;
 5    border-color:       White;
 6    text-color:         White;
 7    font:               "Cantarell Regular 12";
 8}
 9
10#window {
11    anchor:     north;
12    location:   north;
13    width:      100%;
14    padding:    4px;
15    children:   [ horibox ];
16}
17
18#horibox {
19    orientation: horizontal;
20    children:   [ prompt, entry, listview ];
21}
22
23#listview {
24    layout:     horizontal;
25    spacing:    5px;
26    lines:      100;
27}
28
29#entry {
30    expand:     false;
31    width:      10em;
32}
33
34#element {
35    padding: 0px 2px;
36}
37#element selected {
38    background-color: SteelBlue;
39}
  1cat .config/rofi/themes/gruvbox-common.inc.rasi
  2
  3window {
  4    background-color: @background;
  5    border:           2;
  6    padding:          2;
  7}
  8
  9mainbox {
 10    border:  0;
 11    padding: 0;
 12}
 13
 14message {
 15    border:       2px 0 0;
 16    border-color: @separatorcolor;
 17    padding:      1px;
 18}
 19
 20textbox {
 21    highlight:  @highlight;
 22    text-color: @foreground;
 23}
 24
 25listview {
 26    border:       2px solid 0 0;
 27    padding:      2px 0 0;
 28    border-color: @separatorcolor;
 29    spacing:      2px;
 30    scrollbar:    @scrollbar;
 31}
 32
 33element {
 34    border:  0;
 35    padding: 2px;
 36}
 37
 38element.normal.normal {
 39    background-color: @normal-background;
 40    text-color:       @normal-foreground;
 41}
 42
 43element.normal.urgent {
 44    background-color: @urgent-background;
 45    text-color:       @urgent-foreground;
 46}
 47
 48element.normal.active {
 49    background-color: @active-background;
 50    text-color:       @active-foreground;
 51}
 52
 53element.selected.normal {
 54    background-color: @selected-normal-background;
 55    text-color:       @selected-normal-foreground;
 56}
 57
 58element.selected.urgent {
 59    background-color: @selected-urgent-background;
 60    text-color:       @selected-urgent-foreground;
 61}
 62
 63element.selected.active {
 64    background-color: @selected-active-background;
 65    text-color:       @selected-active-foreground;
 66}
 67
 68element.alternate.normal {
 69    background-color: @alternate-normal-background;
 70    text-color:       @alternate-normal-foreground;
 71}
 72
 73element.alternate.urgent {
 74    background-color: @alternate-urgent-background;
 75    text-color:       @alternate-urgent-foreground;
 76}
 77
 78element.alternate.active {
 79    background-color: @alternate-active-background;
 80    text-color:       @alternate-active-foreground;
 81}
 82
 83scrollbar {
 84    width:        4px;
 85    border:       0;
 86    handle-color: @scrollbar-handle;
 87    handle-width: 8px;
 88    padding:      0;
 89}
 90
 91sidebar {
 92    border:       2px 0 0;
 93    border-color: @separatorcolor;
 94}
 95
 96inputbar {
 97    spacing:    0;
 98    text-color: @normal-foreground;
 99    padding:    2px;
100    children:   [ prompt, textbox-prompt-sep, entry, case-indicator ];
101}
102
103case-indicator,
104entry,
105prompt,
106button {
107    spacing:    0;
108    text-color: @normal-foreground;
109}
110
111button.selected {
112    background-color: @selected-normal-background;
113    text-color:       @selected-normal-foreground;
114}
115
116textbox-prompt-sep {
117    expand:     false;
118    str:        ":";
119    text-color: @normal-foreground;
120    margin:     0 0.3em 0 0;
121}
 1cat .config/rofi/themes/gruvbox-dark.rasi
 2
 3* {
 4    /* Theme settings */
 5    highlight: bold italic;
 6    scrollbar: true;
 7
 8    /* Gruvbox dark colors */
 9    gruvbox-dark-bg0:          #282828;
10    gruvbox-dark-bg0-soft:     #32302f;
11    gruvbox-dark-bg3:          #665c54;
12    gruvbox-dark-fg0:          #fbf1c7;
13    gruvbox-dark-fg1:          #ebdbb2;
14    gruvbox-dark-red-dark:     #cc241d;
15    gruvbox-dark-red-light:    #fb4934;
16    gruvbox-dark-yellow-dark:  #d79921;
17    gruvbox-dark-yellow-light: #fabd2f;
18    gruvbox-dark-gray:         #a89984;
19
20    /* Theme colors */
21    background:                  @gruvbox-dark-bg0;
22    background-color:            @background;
23    foreground:                  @gruvbox-dark-fg1;
24    border-color:                @gruvbox-dark-gray;
25    separatorcolor:              @border-color;
26    scrollbar-handle:            @border-color;
27
28    normal-background:           @background;
29    normal-foreground:           @foreground;
30    alternate-normal-background: @gruvbox-dark-bg0-soft;
31    alternate-normal-foreground: @foreground;
32    selected-normal-background:  @gruvbox-dark-bg3;
33    selected-normal-foreground:  @gruvbox-dark-fg0;
34
35    active-background:           @gruvbox-dark-yellow-dark;
36    active-foreground:           @background;
37    alternate-active-background: @active-background;
38    alternate-active-foreground: @active-foreground;
39    selected-active-background:  @gruvbox-dark-yellow-light;
40    selected-active-foreground:  @active-foreground;
41
42    urgent-background:           @gruvbox-dark-red-dark;
43    urgent-foreground:           @background;
44    alternate-urgent-background: @urgent-background;
45    alternate-urgent-foreground: @urgent-foreground;
46    selected-urgent-background:  @gruvbox-dark-red-light;
47    selected-urgent-foreground:  @urgent-foreground;
48}
49
50@import "gruvbox-common.inc"

#Linux #Arch Linux #I3-Gaps #Rofi