rft (rofi-tmux)

Introduction

_images/rft.png

Quickly switches tmux sessions, windows and tmuxinator projects on rofi. Integrates with i3wm for a smoother switching workflow, if you have multiple workspaces.

Use Case

I developed rft (rofi-tmux) to optimize my context-switching workflow. As a user who rely completely on tmux for anything shell related, I wanted to have a fuzzy finder switcher, to locate any tmux session or window with seamless integration with i3wm. I guess I’ve got spoiled by fuzzy finders. Watch the screencast in the Usage section and you’ll see what I mean :)

Features

  • Switch or kill any tmux session.
  • Switch or kill any tmux window, either globally or within the current session.
  • Switch to any tmuxinator project.
  • Cache last tmux session and window for fast switching back and forth, decreases the number of keystrokes.
  • Integration with i3wm for switching to the right workspace seamlessly.
  • Extensible for other window managers.

Installation

Simply pip3 install:

pip3 install rofi-tmux --user -U

Dependencies

Optional (but recommended) dependency is xprop, which will be used to query tmux window visibility.

Configuration

All configuration is optional, and is to be written in a json file at ~/.rft.

  • wm

    Defines which window manager we want to integrate with for smoother context-switching. With this integration, as soon as you switch context, rofi-tmux will automatically focus window where tmux is running. Currently the only supported window manager is i3, which is the default value.

    Note

    Feel free to send pull requests for other window managers that support multiple workspaces.

  • tmux_title_rgx

    Only applicable when wm config is set. This is the regular expression used by window-manager integration logic to locate the window housing specific tmux session. Generally you’d like this (roughly) to match your tmux configuration. The pattern also supports two optional placeholders that will be automatically expanded:

    • {session} will be expanded into tmux session name
    • {window} will be expanded into tmux window name

    Eg if you have set -g set-titles-string "#S / #W / #T" in your .tmux.conf, you might want to set to this value:

    {
        "tmux_title_rgx": "^{session} / {window} / "
    }
    
  • ignored_sessions

    Optional list of tmux session names that should be ignored when building the selection menu. Eg:

    {
        "ignored_sessions": ["session-name", "other-session-name"]
    }
    

Note

If you want to change the algorithm rofi uses, you should change it on rofi rc configuration file itself, “~/.config/rofi/config”, for example to uses the fuzzy macher you should set rofi.matching attribute as “fuzzy”.

config example using i3wm

{
    "wm": "i3",
    "tmux_title_rgx": "^tmux-{session}-{window}",
    "ignored_sessions": ["session-name-to-ignore"]
}

Usage

Two things you have to keep in mind when using rft:

  1. rft doesn’t launch a terminal automatically for you, so, if you don’t have a tmux session attached yet you’re supposed to run rft in the terminal (rft ss or rft lp).
  2. rft caches the last tmux session/window you have switched from, so it automatically pre-selects it in the rofi prompt, except if you are in a different workspace, where rft assumes that you probably want to switch over to the same session/window you were before/that is currently opened.

I recommend that you have shortcuts with control modifiers for rft, so if you always have a tmux session running, it’s going to be really fast to find this session and switch to it. For example, I use these key bindings on i3wm for launching rft:

bindsym $mod+y exec "$HOME/.local/bin/rft lp"
bindsym $mod+e exec "$HOME/.local/bin/rft ss"
bindsym $mod+w exec "$HOME/.local/bin/rft sw"
bindsym $mod+Shift+d exec "$HOME/.local/bin/rft ks"
bindsym $mod+Shift+w exec "$HOME/.local/bin/rft kw"
bindsym $mod4+g exec "$HOME/.local/bin/rft sw --global_scope false"

Note

If you have pip3 installed with the –user flag the executable will be in ~/$HOME/.local/bin/rft.

The first three are the ones that I use the most. They’re for loading a tmuxinator project (lp), switching to a session (ss) and switching to a window globally (sw). So, I set some keys that are near my home row. If you want to check all rft actions available:

❯ rft
Usage: rft [OPTIONS] COMMAND [ARGS]...

  RFT (rofi-tmux) switcher.

Options:
  --debug BOOLEAN  Enables logging at debug level.
  --help           Show this message and exit.

Commands:
  ks  Kill tmux session.
  kw  Kill tmux window.
  lp  Load tmuxinator project.
  ss  Switch tmux session.
  sw  Switch tmux window.
  v   Print version.

Screencast

Watch this screencast to see rft in action: