Terminal Setup: Beyond the multiplexer with Sesh

In my previous post, I shared concisely how my terminal dev environment look like with kitty, tmux and nvim. Let's talk about how I use tmux with sesh to speed up productivity.

Sesh?

Sesh is smart session manager for tmux, it's a useful tool that combines zoxide and tmux sessions.

For installation, follow the sesh github page.

After that, integrate with tmux by adding this to .tmux.config

.tmux.config
bind-key "S" run-shell "sesh connect \"$(
  sesh list --icons | fzf-tmux -p 80%,70% \
    --no-sort --ansi --border-label ' sesh ' --prompt '⚑  ' \
    --header '  ^a all ^t tmux ^g configs ^x zoxide ^d tmux kill ^f find' \
    --bind 'tab:down,btab:up' \
    --bind 'ctrl-a:change-prompt(⚑  )+reload(sesh list --icons)' \
    --bind 'ctrl-t:change-prompt(πŸͺŸ  )+reload(sesh list -t --icons)' \
    --bind 'ctrl-g:change-prompt(βš™οΈ  )+reload(sesh list -c --icons)' \
    --bind 'ctrl-x:change-prompt(πŸ“  )+reload(sesh list -z --icons)' \
    --bind 'ctrl-f:change-prompt(πŸ”Ž  )+reload(fd -H -d 2 -t d -E .Trash . ~)' \
    --bind 'ctrl-d:execute(tmux kill-session -t {2..})+change-prompt(⚑  )+reload(sesh list --icons)' \
    --preview-window 'right:55%' \
    --preview 'sesh preview {}'
)\""

You can bind any key that make sense to you, I choose S (S == Sesh).

It will open a popup running sesh with prefix + S

But to open that we need to be in a tmux session, it’s more convenient if we can open that in terminal without any active tmux session.
We can run this command below in terminal directly

terminal
sesh connect "$(
  sesh list --icons --hide-duplicates | fzf --no-border \
    --ansi \
    --list-border \
    --no-sort --prompt '⚑  ' \
    --color 'list-border:6,input-border:3,preview-border:4,header-bg:-1,header-border:6' \
    --input-border \
    --header-border \
    --bind 'tab:down,btab:up' \
    --bind 'ctrl-a:change-prompt(⚑  )+reload(sesh list --icons)' \
    --bind 'ctrl-t:change-prompt(πŸͺŸ  )+reload(sesh list -t --icons)' \
    --bind 'ctrl-g:change-prompt(βš™οΈ  )+reload(sesh list -c --icons)' \
    --bind 'ctrl-x:change-prompt(πŸ“  )+reload(sesh list -z --icons)' \
      --bind 'ctrl-f:change-prompt(πŸ”Ž  )+reload(fd -H -d 2 -t d -E .Trash . ~)' \
    --bind 'ctrl-d:execute(tmux kill-session -t {2..})+change-prompt(⚑  )+reload(sesh list --icons)' \
    --preview-window 'right:70%' \
    --preview 'sesh preview {}' \
)"

Or we can save that command to a script file (e.g. sesh_start), add that to your $PATH so we can run it anywhere.

Now we can open the sesh popup by running sesh_start script in terminal, then we can open a tmux session.

Sesh custom configs

Sesh allows you to define how specific sessions should behave. For example, if I open a project, I usually want Nvim to start automatically.
That could be done by using sesh config file, create sesh.toml file in $HOME/.config/sesh

sesh.toml
[[session]]
name = "Personal Blog"
path = "~/dev/blog"
startup_command = "nvim ."

Or you can use startup command with a script path to do something like this

sesh.toml
[[session]]
name = "Personal Blog"
path = "~/dev/blog"
startup_command = "~/.config/sesh/scripts/blog_dev"

the script:

blog_dev
#!/usr/bin/env fish
# Get the ID of the original window
set original_window (tmux display-message -p '#{window_id}')

# Create a new tmux window for bun run dev
tmux new-window -n "bun-dev" "bun run dev; read"

# Switch back to the original window
tmux select-window -t $original_window

# Open nvim with Telescope in the original window
tmux send-keys -t . "nvim" Enter ":Telescope find_files" Enter

it will create a tmux session with two windows, one for nvim and the other (bun-dev) running dev server.

Keybinding (kitty)

Tmux default prefix is C-b (ctrl + b), tapping too many keys to open sesh is a bit annoying, with above config, I have to hit ctrl + b -> shift + s.

I'm using Kitty and I will remap tmux prefix with super key. In order to find out what exactly Kitty send to terminal for keystrokes, run this in your Kitty

terminal
kitty +kitten show_key

the output for tmux prefix C-b is \x02, so C-b S will be \x02S, add that to kitty.conf

kitty.conf
#: remap to use super (cmd, command, ⌘) instead of prefix for tmux
# default tmux prefix: C-b is \x02
# open sesh popup
map super+s send_text all \x02S

Now, I can hit super+s to open sesh popup.
Below is more tmux keybindings I've set up in my Kitty:

kitty.conf
map super+t send_text all \x02c # create new tmux window
map super+w send_text all \x02x # close current tmux window
map super+n send_text all \x13n # next tmux window

Conclusion

Hope this could help, here is my dotfiles.

Leave comment

@ 2024-2026 ihsor.dev