The zsh-navigator plugin allows you to quickly navigate your workspace using fzf and optionally manage tmux sessions or switch directories.
Inspired by ThePrimeagen tmux-sessionizer script.
- Oh My Zsh or Zinit:
- Add the plugin to your
.zshrc: zinit light Andree37/zsh-navigator - Or for Oh My Zsh:
- Add the plugin to your
git clone https://github.com/Andree37/zsh-navigator.git $ZSH_CUSTOM/plugins/zsh-navigatorAdd the plugin to your .zshrc:
plugins=(zsh-navigator)- Reload your Zsh configuration:
source ~/.zshrcAll configuration is done through ZSH_NAVIGATOR_* variables that can be set in your .zshrc file before loading the plugin. The plugin also provides a configuration utility for runtime changes.
| Variable | Default | Description | Examples |
|---|---|---|---|
ZSH_NAVIGATOR_MODE |
tmux |
Set the navigation mode. | tmux, cd |
ZSH_NAVIGATOR_KEYBIND_ENABLED |
true |
Enable keybindings. | true, false |
ZSH_NAVIGATOR_KEYBIND |
^f |
Keybinding to launch the navigator. | ^g, ^n |
ZSH_NAVIGATOR_ORIGINAL_PATH_KEYBIND |
^h |
Keybinding to return to the original directory. | ^x, ^o |
ZSH_NAVIGATOR_STRUCTURE |
unsorted |
Define the workspace structure. | workspace, workspace_src, unsorted |
ZSH_NAVIGATOR_BASE_DIR |
$HOME/github |
Set the base directory for navigation. | /path/to/projects |
ZSH_NAVIGATOR_WINDOW_NAMING |
false |
Enable automatic renaming of tmux windows. | true, false |
ZSH_NAVIGATOR_HOME_PATH |
. |
Default directory to return to. | $HOME, /path/to/default |
Configure zsh-navigator by setting ZSH_NAVIGATOR_* variables in your .zshrc file before loading the plugin. This is the standard way that zsh plugins are configured (same pattern as zsh-autosuggestions, zsh-syntax-highlighting, etc.).
ZSH_NAVIGATOR_MODE: Controls how the navigator operates (tmuxfor session management,cdfor changing directories).ZSH_NAVIGATOR_KEYBIND_ENABLED: Toggles keybinding functionality (trueto enable,falseto disable).ZSH_NAVIGATOR_KEYBIND: Defines the keybinding for launching the navigator (default isCtrl+f).ZSH_NAVIGATOR_ORIGINAL_PATH_KEYBIND: Sets the keybinding for returning to the original directory (default isCtrl+h).ZSH_NAVIGATOR_STRUCTURE: Configures workspace organization (workspace,workspace_src, orunsorted).ZSH_NAVIGATOR_BASE_DIR: Specifies the root directory for navigation.ZSH_NAVIGATOR_WINDOW_NAMING: Enables or disables automatic renaming of the current tmux window based on the selected package name.- IMPORTANT that this option is only effective in
tmuxmode and it requires additional configuration in your~/.tmux.conffile to work properly. See the tmux configuration section below for details.
- IMPORTANT that this option is only effective in
ZSH_NAVIGATOR_HOME_PATH: Default directory to return to when using the original path keybinding.
The ZSH_NAVIGATOR_STRUCTURE variable allows you to define the structure of your workspace. The following options are available:
-
workspace: Expects a workspace directory with subdirectories for each project. For example:~/Projects ├── package1 ├── package2 ├── package3 -
workspace_src: Expects a workspace directory with subdirectories for each project containing asrcdirectory. For example:~/Projects ├── src │ ├── package1 │ ├── package2 │ ├── package3 -
unsorted: Does not expect any specific structure. All directories are listed without any assumptions and this is the default option.
Here's a complete example of how to configure zsh-navigator in your ~/.zshrc:
# Configure zsh-navigator BEFORE loading plugins
ZSH_NAVIGATOR_KEYBIND_ENABLED=true
ZSH_NAVIGATOR_STRUCTURE=workspace
ZSH_NAVIGATOR_MODE=tmux
ZSH_NAVIGATOR_WINDOW_NAMING=true
ZSH_NAVIGATOR_BASE_DIR="$HOME/Projects"
ZSH_NAVIGATOR_KEYBIND="^f"
# Load plugins
plugins=(git zsh-syntax-highlighting fast-syntax-highlighting zsh-autosuggestions zsh-navigator)
source $ZSH/oh-my-zsh.shIf you're happy with most defaults, you only need to set what you want to change:
# Only configure what you want to change
ZSH_NAVIGATOR_BASE_DIR="$HOME/Development"
ZSH_NAVIGATOR_STRUCTURE=workspace
plugins=(git zsh-navigator)If you were using the old NAVIGATOR_* environment variables, you need to update your configuration:
# OLD - Don't use this anymore
export NAVIGATOR_KEYBIND_ENABLED=true
export NAVIGATOR_STRUCTURE=workspace
export NAVIGATOR_MODE=tmux
export NAVIGATOR_WINDOW_NAMING=true
plugins=(zsh-navigator)# NEW - Use this format
ZSH_NAVIGATOR_KEYBIND_ENABLED=true
ZSH_NAVIGATOR_STRUCTURE=workspace
ZSH_NAVIGATOR_MODE=tmux
ZSH_NAVIGATOR_WINDOW_NAMING=true
plugins=(zsh-navigator)- Variable names: Added
ZSH_prefix to all variables. This matches other plugins - No exports: Remove
exportstatements - just set the variables - Order matters: Variables must be set BEFORE the
plugins=()line
-
Run the navigator:
- Manually:
navigator - Or, if keybinding is enabled: Press your configured key (e.g.,
Ctrl+f).
- Manually:
-
Use
fzfto select a directory. -
Depending on the mode:
- TMUX Mode: Opens or switches to a
tmuxsession. - CD Mode: Navigates to the selected directory in your terminal.
- TMUX Mode: Opens or switches to a
To enable automatic renaming of tmux windows based on the selected package name, add the following to your ~/.tmux.conf:
# Enable automatic renaming of tmux windows
set-option -g set-titles on
set-option -g set-titles-string "#W"