Skip to content

Instantly share code, notes, and snippets.

@ChrisVilches
Last active October 26, 2023 01:53
Show Gist options
  • Save ChrisVilches/9ef7e11c15c657c3167db2ba82777560 to your computer and use it in GitHub Desktop.
Save ChrisVilches/9ef7e11c15c657c3167db2ba82777560 to your computer and use it in GitHub Desktop.
tmux config
# Usage:
# ~/.config/tmux/tmux.conf
# Install TPM and follow instructions:
# https://github.com/tmux-plugins/tpm
# vim ~/.config/tmux/tmux.conf && tmux source ~/.config/tmux/tmux.conf
set -g exit-empty off
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'catppuccin/tmux'
set -g @catppuccin_flavour 'mocha'
set -g @plugin 'tmux-plugins/tmux-yank'
set-option -sa terminal-overrides ",xterm*:Tc"
set -g mouse on
# Change/swap windows
bind -n C-Pageup previous-window
bind -n C-Pagedown next-window
bind -n C-S-Pageup swap-window -t -1 \; previous-window
bind -n C-S-Pagedown swap-window -t +1 \; next-window
# Open panes in current directory
bind '"' split-window -v -c "#{pane_current_path}"
bind % split-window -h -c "#{pane_current_path}"
# Use 1-based indices
set -g base-index 1
set -g pane-base-index 1
set-window-option -g pane-base-index 1
set-option -g renumber-windows on
# Change layouts
bind C-q select-layout even-horizontal
bind C-w select-layout even-vertical
bind C-e select-layout main-horizontal
bind C-r select-layout main-vertical
bind C-t select-layout tiled
run '~/.tmux/plugins/tpm/tpm'
@ChrisVilches
Copy link
Author

ChrisVilches commented May 13, 2023

Always start tmux with this (~/.zshrc )

if command -v tmux &> /dev/null && [ -n "$PS1" ] && [[ ! "$TERM" =~ screen ]] && [[ ! "$TERM" =~ tmux ]] && [ -z "$TMUX" ] && [[ "$TERM_PROGRAM" != "vscode" ]]; then
  # Get the first unattached session, if any
  first_unattached_session=$(tmux ls -F '#{session_attached} #{session_name}' 2> /dev/null | grep ^0 -m 1 | cut -c3-)

  # If there's one unattached session, attach that one.
  # If not, just start a new one.
  if [ -n "$first_unattached_session" ]; then
    exec tmux attach -t $first_unattached_session
  else
    exec tmux
  fi
fi

You can open a new terminal without tmux by executing:

gnome-terminal

This will create a new window but it will have TERM_PROGRAM set to tmux, so tmux won't load (due to the condition).

@ChrisVilches
Copy link
Author

ChrisVilches commented May 13, 2023

TODO: Improve pane navigation.
Use this? https://github.com/christoomey/vim-tmux-navigator
It requires a VIM plugin as well, so I'm not sure.

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