tm: wrapper for tmux, redux (with Fish tab completion)

tmux logo

Back in 2014 I wrote a Bash script called tm that made creating and connecting to tmux sessions and windows a bit easier. I’ve been using it ever since, pretty much daily, with a few revisions. I thought it was probably about time I shared the updates.

As a recap, tm lets you quickly create named tmux sessions like this:

# create new or connect to existing session named "mmc"
$ tm mmc

# Create new or connect to existing window named "remote"
$ tm mmc remote

Here’s what’s new:

  • Case insensitive session/window matching
  • Allow numeric index for window argument (zero-indexed)
  • Create new named window if second argument is passed but no existing match is found
  • Replace a bunch of sed and awk crud with -F params
  • Add select menus when running without arguments (just tm), using fzf if available
  • Exit gracefully (with error) if run within a tmux session

There are probably other little changes I made along the way, but that’s what I gathered from a quick diff. The updated script can be found in this gist.

Running with Fish

tm is written in Bash, but works fine in other shells with the /bin/bash hashbang. So in Fish, for example, I just make sure that the script is saved as tm, is executable, and is located in my $fish_user_paths.

Fish tab completion screenshot
Fish tab completion

When I first published it, I included some bash completion scripts. I’ve added a Fish completion script that you can install in ~/.config/fish/completions/tm.fish. Once installed, you can type tm [tab] it will complete from all open sessions, and running tm session_name [tab] will complete windows for the named session (including indexes for unnamed windows). Nifty.

Brett Terpstra

Brett is a writer and developer living in Minnesota, USA. You can follow him as ttscoff on Twitter, GitHub, and Mastodon. Keep up with this blog by subscribing in your favorite news reader.

This content is supported by readers like you.

Join the conversation