Recently I've been exploring using tmux and fzf for a workspace management. I wanted a quick way to navigate and jump between projects. Here is what I came up with.
Prerequisites
Before you can use this workspace navigator, ensure you have the following installed:
- tmux - a terminal multiplexer (Learn more)
- fzf - a command-line fuzzy finder (Learn more)
- fd - a simple, fast alternative to find (Learn more)
Note: You'll need to have tmux running to use the display-popup command.
Configuration
Add this snippet to your `.tmux.conf`
file:
bind k display-popup -T"Workspace Navigator" -w 75% -h 40% -E "~/bin/scripts/list-workspaces"
The Script
Here's the script (list-workspaces
):
#!/opt/homebrew/bin/bash
fd . ~/Projects -d 1 -x echo {} {/} | \
fzf --header "session: enter | window: ctrl-w | below: ctrl-j | above: ctrl-k | left: ctrl-h | right: ctrl-l" \
--reverse \
--margin 0% \
--padding 0% \
--with-nth=2 \
--bind='enter:become(tmux has -t={2} 2>/dev/null || tmux new -ds {2} -c {1} && tmux switchc -t={2})' \
--bind='ctrl-w:become(tmux neww -c {1} -n {2})' \
--bind='ctrl-l:become(tmux splitw -c {1} -h)' \
--bind='ctrl-h:become(tmux splitw -c {1} -hb)' \
--bind='ctrl-j:become(tmux splitw -c {1} -v)' \
--bind='ctrl-k:become(tmux splitw -c {1} -vb)'
How It Works
This script uses fd to list directories in the ~/Projects folder, then pipes the output to fzf for interactive filtering. It allows you to create or switch to tmux sessions, create new windows, and split panes in various directions using keyboard shortcuts.
Keyboard Shortcuts
Enter - Create/switch to session
Ctrl+W - New window
Ctrl+J - Split below
Ctrl+K - Split above
Ctrl+H - Split left
Ctrl+L - Split right
Benefits
This has become my go-to approach for workspace navigation. It's especially useful in my job, where I work with many packages and microservices; being able to quickly jump between them makes this script a huge time-saver.
Fast Navigation - Quickly switch between projects without leaving your terminal
Flexible Layout - Create sessions, windows, or split panes in any direction
Microservices Ready - Perfect for environments with multiple packages and services
Session Management - Automatically creates or switches to existing tmux sessions
Try using this workspace navigator and let me know what you think! It might just transform how you navigate your development environment.