Tmux : Add extra session switching.

This commit is contained in:
Dmitry Voronin 2024-01-23 15:55:40 +03:00
parent ba1a9aca36
commit b2b937b40f
3 changed files with 39 additions and 22 deletions

View file

@ -2,15 +2,20 @@
# By default uses name `main`. # By default uses name `main`.
# Usage: ta [NAME] # Usage: ta [NAME]
function ta() { function ta() {
local name="$1" local name="${1}"
# set default name. # Set default name.
if [[ "$name" = "" ]]; then [[ "${name}" = "" ]] && name="main"
name="main"
# Create session.
tmux new-session -s "${name}" -d &> /dev/null
# Attach to session.
if [[ "${TERM_PROGRAM}" = "tmux" ]]; then
tmux switch-client -t "${name}"
else
tmux attach-session -t "${name}"
fi fi
# call tmux.
tmux new -s "$name" 2> /dev/null || tmux attach-session -t "$name"
} }
# Detach from running session. # Detach from running session.

View file

@ -1,12 +1,12 @@
# remap <C-b> to <C-t>. # Remap <C-b> to <C-t>.
unbind-key C-b unbind-key C-b
set-option -g prefix C-t set-option -g prefix C-t
bind-key C-t send-prefix bind-key C-t send-prefix
# disable escape delay. # Disable escape delay.
set -sg escape-time 0 set -sg escape-time 0
# remap split keys. # Remap split keys.
bind -n M-\\ split-window -h -c "#{pane_current_path}" bind -n M-\\ split-window -h -c "#{pane_current_path}"
bind -n M-- split-window -v -c "#{pane_current_path}" bind -n M-- split-window -v -c "#{pane_current_path}"
bind -n M-= select-layout tiled bind -n M-= select-layout tiled
@ -17,56 +17,59 @@ bind -n M-l resize-pane -R 1
unbind '"' unbind '"'
unbind % unbind %
# reload config. # Reload config.
bind -n M-r source-file ~/.config/tmux/tmux.conf bind -n M-r source-file ~/.config/tmux/tmux.conf
# swith panes with alt + hjkl. # Swith panes with alt + hjkl.
bind -n M-a select-pane -L bind -n M-a select-pane -L
bind -n M-d select-pane -R bind -n M-d select-pane -R
bind -n M-w select-pane -U bind -n M-w select-pane -U
bind -n M-s select-pane -D bind -n M-s select-pane -D
# close pane. # Close pane.
bind -n M-c kill-pane bind -n M-c kill-pane
bind -n M-C kill-pane -a bind -n M-C kill-pane -a
# create new window. # Create new window.
bind -n M-Escape new-window -c "#{pane_current_path}" bind -n M-Escape new-window -c "#{pane_current_path}"
bind -n M-t new-window -c "#{pane_current_path}" # NOTE: for compatibility with Termux as it does not support <C-Esc> yet. bind -n M-t new-window -c "#{pane_current_path}" # NOTE: for compatibility with Termux as it does not support <C-Esc> yet.
# close window. # Close window.
bind -n M-x kill-window bind -n M-x kill-window
bind -n M-X kill-window -a bind -n M-X kill-window -a
# switch window. # Switch window.
bind -n M-e next-window bind -n M-e next-window
bind -n M-q previous-window bind -n M-q previous-window
# move window. # Move window.
bind -n M-E swap-window -t +1\; select-window -t +1 bind -n M-E swap-window -t +1\; select-window -t +1
bind -n M-Q swap-window -t -1\; select-window -t -1 bind -n M-Q swap-window -t -1\; select-window -t -1
# detach. # Detach.
bind -n M-z detach-client bind -n M-z detach-client
bind -n M-Z detach-client -a bind -n M-Z detach-client -a
# scroll. # Scroll.
bind -n M-p copy-mode -u bind -n M-p copy-mode -u
bind -n M-n send-keys Pagedown bind -n M-n send-keys Pagedown
# copy mode. # Copy mode.
setw -g mode-keys vi setw -g mode-keys vi
bind -n M-v copy-mode bind -n M-v copy-mode
bind -n M-P paste-buffer bind -n M-P paste-buffer
bind -T copy-mode-vi v send -X begin-selection bind -T copy-mode-vi v send -X begin-selection
bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy" bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy"
# Resize panes. # Switch sessions.
bind -n M-9 switch-client -p
bind -n M-0 switch-client -n
bind -n M-g choose-session
# Resize to smallest client. # Resize to smallest client.
set -g window-size smallest set -g window-size smallest
# statusbar # Statusbar.
set -g status-position bottom set -g status-position bottom
set -g status-justify left set -g status-justify left
set -g status-style 'bg=yellow fg=black dim' set -g status-style 'bg=yellow fg=black dim'

View file

@ -30,6 +30,9 @@ Key|Action
`Super+l`|None. `Super+l`|None.
`Super+p`|None. `Super+p`|None.
`Super+n`|None. `Super+n`|None.
`Super+g`|None.
`Super+9`|None.
`Super+0`|None.
## Tmux. ## Tmux.
@ -61,6 +64,9 @@ Key|Action
`Meta+l`|Resize split to the right. `Meta+l`|Resize split to the right.
`Meta+p`|Scroll up. `Meta+p`|Scroll up.
`Meta+n`|Scroll down. `Meta+n`|Scroll down.
`Meta+g`|Switch sessions.
`Meta+9`|Switch to the previous session.
`Meta+0`|Switch to the next session.
## Nvim. ## Nvim.
@ -89,5 +95,8 @@ Key|Action
`Space+l`|Resize split to the right. `Space+l`|Resize split to the right.
`Space+p`|None. `Space+p`|None.
`Space+n`|None. `Space+n`|None.
`Space+g`|None.
`Space+9`|None.
`Space+0`|None.
More info in [Nvim doc.](Nvim.md) More info in [Nvim doc.](Nvim.md)