---
title: 'tm: wrapper for tmux, redux (with Fish tab completion)'
date: 2019-12-17 08:00
slug: tm-wrapper-for-tmux-redux-with-fish-tab-completion
categories:
- Code
tags:
- fish
- scripting
- tmux
- terminal
---

[2014]: https://brettterpstra.com/2014/05/11/making-my-tmux-life-easier/
[bashcomplete]: https://brettterpstra.com/2014/05/15/tmux-even-easier-tm-with-fuzzy-completion/
[fishcomplete]: https://gist.github.com/64836c69bccc3fb6cdb09160e9860972
[gist]: https://gist.github.com/ttscoff/a37427a8c331f072904d

![tmux logo](https://brettterpstra.com/uploads/2019/12/tmux-logo.png)

[Back in 2014][2014] I wrote a Bash script called `tm` that made creating and connecting to [tmux](https://github.com/tmux/tmux/wiki) 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](https://github.com/junegunn/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][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](https://brettterpstra.com/uploads/2019/12/tm-fish-complete.png)

When I first published it, I included some [bash completion scripts][bashcomplete]. I've added a [Fish completion script][fishcomplete] 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 is a writer and developer living in Minnesota, USA. You can follow him as ttscoff. This content is supported by readers like you. [More about Brett](https://brettterpstra.com/contact.md), including social links.

Copyright © 2026 Brett Terpstra. All rights reserved.
