Advertisement
Guest User

tmux.conf

a guest
Sep 6th, 2024
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.88 KB | Source Code | 0 0
  1. # Set the TMUX_CONF variable to track the location of the current tmux configuration file.
  2. # Set the TMUX_PROGRAM variable to track the path of the tmux binary being used.
  3. %if #{==:#{TMUX_PROGRAM},}
  4. run 'TMUX_PROGRAM="$(LSOF=$(PATH="$PATH:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" command -v lsof); \
  5. $LSOF -b -w -a -d txt -p #{pid} -Fn 2>/dev/null | perl -n -e "if (s/^n((?:.(?!dylib$|so$))+)$/\1/g && \
  6. s/(?:\s+\([^\s]+?\))?$//g) { print; exit } } exit 1; {" || readlink "/proc/#{pid}/exe" 2>/dev/null)"; \
  7. {[ -f "$TMUX_PROGRAM" ] && [ -x "$TMUX_PROGRAM" ]} || TMUX_PROGRAM="$(command -v tmux || printf tmux)"; \
  8. "$TMUX_PROGRAM" -S #{socket_path} set-environment -g TMUX_PROGRAM "$TMUX_PROGRAM"'
  9. %endif
  10.  
  11. # Set the TMUX_SOCKET variable to track the socket path being used by tmux.
  12. %if #{==:#{TMUX_SOCKET},}
  13. run '"$TMUX_PROGRAM" -S #{socket_path} set-environment -g TMUX_SOCKET "#{socket_path}"'
  14. %endif
  15.  
  16. # Set the TMUX_CONF variable to track the location of the tmux configuration file.
  17. %if #{==:#{TMUX_CONF},}
  18. run '"$TMUX_PROGRAM" set-environment -g TMUX_CONF $(for conf in "$HOME/.tmux.conf" "$XDG_CONFIG_HOME/tmux/tmux.conf" \
  19. "$HOME/.config/tmux/tmux.conf"; do [ -f "$conf" ] && printf "%s" "$conf" && break; done)'
  20. %endif
  21.  
  22.  
  23. # Keybinding to open and source the tmux configuration file in a new window using the preferred editor.
  24. bind e new-window -n "tmux.conf" -e EDITOR="$EDITOR" sh -c '
  25. # Check if nvim is available; use it if present, otherwise fall back to the current editor.
  26. if command -v nvim >/dev/null 2>&1; then
  27. EDITOR=nvim
  28. fi
  29.  
  30. # Open the tmux config file with the determined editor, setting appropriate syntax highlighting.
  31. case "${EDITOR:-vim}" in
  32. *vim*) ${EDITOR:-vim} -c ":set syntax=tmux" "$TMUX_CONF";;
  33. *) $EDITOR ~/.config/tmux/tmux.conf;;
  34. esac && "$TMUX_PROGRAM" ${TMUX_SOCKET:+-S "$TMUX_SOCKET"} source "$TMUX_CONF" \; display "$TMUX_CONF sourced"
  35. '
  36.  
  37. # Keybinding to open ~/.zshrc file in a new tmux window using the preferred editor.
  38. bind | new-window -n "zshrc" -e EDITOR="$EDITOR" sh -c '
  39. # Check if nvim is available; use it if present, otherwise fall back to the current editor.
  40. if command -v nvim >/dev/null 2>&1; then
  41. EDITOR=nvim
  42. else
  43. EDITOR=${EDITOR:-vim}
  44. fi
  45.  
  46. # Open the .zshrc file with the determined editor, setting appropriate syntax highlighting.
  47. case "$EDITOR" in
  48. *vim*) $EDITOR -c ":set syntax=zsh" "$HOME/.zshrc";;
  49. *) $EDITOR "$HOME/.zshrc";;
  50. esac && source "$HOME/.zshrc"; display "~/.zshrc sourced"
  51. '
  52.  
  53. # Keybinding to reload the tmux configuration file.
  54. bind r run '"$TMUX_PROGRAM" ${TMUX_SOCKET:+-S "$TMUX_SOCKET"} source "$TMUX_CONF"' \; display "#{TMUX_CONF} sourced"
  55.  
  56.  
  57. # -- general -------------------------------------------------------------------
  58.  
  59. # Enable true color support in xterm-compatible terminals.
  60. set-option -sa terminal-overrides ",xterm*:Tc"
  61.  
  62. # Enable focus events to detect when the terminal gains or loses focus.
  63. set -s focus-events on
  64.  
  65. # Enable mouse support for selecting panes, resizing, and scrolling.
  66. set -g mouse on
  67.  
  68. # Unset the default prefix key
  69. unbind C-b
  70.  
  71. # Set an additional prefix key for tmux commands.
  72. set -g prefix C-a
  73.  
  74. # Allow the use of the secondary prefix key (C-a) to send the original prefix key.
  75. bind -n C-a send-prefix
  76.  
  77.  
  78. # -- display -------------------------------------------------------------------
  79.  
  80. # Start window numbering from 1.
  81. set -g base-index 1
  82.  
  83. # Ensure pane numbering is consistent with window numbering.
  84. setw -g pane-base-index 1
  85.  
  86. # Automatically rename windows to reflect the currently active program.
  87. set -g automatic-rename on
  88.  
  89. # Renumber windows after closing a window.
  90. set -g renumber-windows on
  91.  
  92. # Set the terminal title to reflect the current tmux session and window.
  93. set -g set-titles on
  94.  
  95. # Set the terminal title string to show pane title, session name, and window details.
  96. set -g set-titles-string '#{pane_title} ❐ #{session_name} ❐ #{window_index}:#{window_name}'
  97.  
  98. # Set a slightly longer display time for pane indicators.
  99. set -g display-panes-time 800
  100.  
  101. # Set a slightly longer display time for status messages.
  102. set -g display-time 1000
  103.  
  104. # Ensure pane numbering starts from 1 in each window.
  105. set-window-option -g pane-base-index 1
  106.  
  107. # Enable pane border status at the top
  108. set -w pane-border-status top # removed the -g flag cause it was being over written by theme
  109.  
  110. # Zen-full pane border format with minimal and useful information
  111. set -g pane-border-format "#{pane_current_command}"
  112.  
  113. # set-hook -g after-new-window 'set allow-passthrough on'
  114. # set -g visual-activity off
  115.  
  116.  
  117. # -- navigation ----------------------------------------------------------------
  118.  
  119. # Bind C-c to create a new tmux session.
  120. bind C-c new-session
  121.  
  122. # Bind C-f to prompt for finding a session and switching to it.
  123. bind C-f command-prompt -p find-session 'switch-client -t %%'
  124.  
  125. # Bind BTab to switch to the last active session.
  126. bind BTab switch-client -l
  127.  
  128. # Split the current window horizontally with a new pane.
  129. bind - split-window -v
  130.  
  131. # Split the current window vertically with a new pane.
  132. bind _ split-window -h
  133.  
  134. # Split the current window horizontally, maintaining the current pane's working directory.
  135. bind - split-window -v -c "#{pane_current_path}"
  136.  
  137. # Split the current window vertically, maintaining the current pane's working directory.
  138. bind _ split-window -h -c "#{pane_current_path}"
  139.  
  140. # Commenting below pane movement keys since we are already using
  141. # christoomey/vim-tmux-navigator plugin which provides C-hjkl movements
  142. # but without <prefix>before them
  143. # Bind h, j, k, l for easy pane navigation in all directions.
  144. #bind -r h select-pane -L # move left
  145. #bind -r j select-pane -D # move down
  146. #bind -r k select-pane -U # move up
  147. #bind -r l select-pane -R # move right
  148.  
  149. # Bind > and < for swapping panes with the next or previous pane.
  150. bind > swap-pane -D
  151. bind < swap-pane -U
  152.  
  153. # Bind H, J, K, L for resizing panes in all directions.
  154. bind -r H resize-pane -L 2
  155. bind -r J resize-pane -D 2
  156. bind -r K resize-pane -U 2
  157. bind -r L resize-pane -R 2
  158.  
  159. # Unbind default navigation keys for previous and next window.
  160. unbind n
  161. unbind p
  162.  
  163. # Bind C-h and C-l for window navigation: previous and next window respectively.
  164. bind -r C-h previous-window
  165. bind -r C-l next-window
  166.  
  167. # Bind Tab to switch to the last active window.
  168. bind Tab last-window
  169.  
  170. # -- copy mode -----------------------------------------------------------------
  171.  
  172. # Bind Enter to enter copy mode in tmux.
  173. bind Enter copy-mode -e
  174.  
  175. # Use vi-style key bindings in copy mode.
  176. setw -g mode-keys vi
  177.  
  178. # Bind v for starting selection, C-v for rectangle selection, and y for yanking in vi-mode.
  179. bind -T copy-mode-vi v send -X begin-selection
  180. bind -T copy-mode-vi C-v send -X rectangle-toggle
  181. bind -T copy-mode-vi y send -X copy-selection-and-cancel
  182.  
  183. # Bind Escape to cancel copy mode in vi-style.
  184. bind -T copy-mode-vi Escape send -X cancel
  185.  
  186. # Bind H and L to move to the start and end of the line in vi-style copy mode.
  187. bind -T copy-mode-vi H send -X start-of-line
  188. bind -T copy-mode-vi L send -X end-of-line
  189.  
  190. # Copy mouse selected selection to system clipboard
  191. bind -Tcopy-mode MouseDragEnd1Pane send -X copy-selection
  192.  
  193. # bind C to open a new pane to enter copy mode for the current panr
  194. bind C {
  195. splitw -f -l30% ''
  196. set-hook -p pane-mode-changed 'if -F "#{!=:#{pane_mode},copy-mode}" "kill-pane"'
  197. copy-mode -s'{last}'
  198. }
  199. # -- buffers -------------------------------------------------------------------
  200.  
  201. # Bind b to list available paste buffers.
  202. bind b list-buffers
  203.  
  204. # Bind p to paste the top buffer content.
  205. bind p paste-buffer -p
  206.  
  207. # Bind P to choose which buffer to paste from.
  208. bind P choose-buffer
  209.  
  210.  
  211. # -- plugin settings -----------------------------------------------------------
  212.  
  213. # Set options for the Catppuccin tmux theme.
  214. set -g @catppuccin_flavour 'mocha'
  215.  
  216. # Set options for the Tokyo Night tmux theme.
  217. set -g @tokyo-night-tmux_show_datetime 0
  218. set -g @tokyo-night-tmux_show_path 1
  219. set -g @tokyo-night-tmux_path_format relative
  220. set -g @tokyo-night-tmux_window_id_style dsquare
  221. set -g @tokyo-night-tmux_pane_id_style hsquare
  222. set -g @tokyo-night-tmux_show_git 1
  223.  
  224. # resurrect settings
  225. set -g @resurrect-capture-pane-contents 'on'
  226. set -g @resurrect-strategy-nvim 'session'
  227.  
  228. # List of plugins to load with tmux.
  229. set -g @plugin 'tmux-plugins/tpm'
  230. set -g @plugin 'tmux-plugins/tmux-sensible'
  231. set -g @plugin 'christoomey/vim-tmux-navigator'
  232. set -g @plugin 'dreamsofcode-io/tokyo-night-tmux'
  233. # set -g @plugin 'catppuccin/tmux'
  234. set -g @plugin 'tmux-plugins/tmux-resurrect'
  235. set -g @plugin 'tmux-plugins/tmux-continuum'
  236. # Initialize TPM (Tmux Plugin Manager) for managing plugins.
  237. run -b '~/.tmux/plugins/tpm/tpm'
  238.  
  239. # Temporary settings
  240. set -ga terminal-overrides '*:Ss=\E[%p1%d q:Se=\E[ q' # see :h tui-cursor-shape in nvim for this setting
  241.  
  242.  
  243.  
Tags: Config tmux
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement