Skip to content

Instantly share code, notes, and snippets.

@mmm
Last active December 11, 2023 17:12
Show Gist options
  • Save mmm/f09e6e4e9a10105372369c86d02df8a9 to your computer and use it in GitHub Desktop.
Save mmm/f09e6e4e9a10105372369c86d02df8a9 to your computer and use it in GitHub Desktop.
tmux fuzzy launcher
#!/bin/bash
__tmux_find_session_like() {
local requested_session=$1
tmux list-sessions | sed -E 's/:.*$//' | fzf --filter=$requested_session --no-sort
}
__tmux_create_or_attach_to() {
local requested_session=$1
local session_name=$(__tmux_find_session_like $requested_session)
[ -n "$session_name" ] \
&& tmux attach-session -t $session_name \
|| tmux new-session -s $requested_session
}
t() {
local session=$1
[ -n "$session" ] \
&& __tmux_create_or_attach_to $session \
|| tmux ls
}
@mmm
Copy link
Author

mmm commented Dec 11, 2023

source the above from your .bashrc or shell startup.

Usage:
t: lists existing tmux sessions
t <blah>: attach to session whose names uniquely matches with the <blah> text fragment (create a new session of this name if you can't match)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment