diff --git a/.config/bash/module/Tmux.sh b/.config/bash/module/Tmux.sh index 1398207..9b5f2de 100644 --- a/.config/bash/module/Tmux.sh +++ b/.config/bash/module/Tmux.sh @@ -2,15 +2,20 @@ # By default uses name `main`. # Usage: ta [NAME] function ta() { - local name="$1" + local name="${1}" - # set default name. - if [[ "$name" = "" ]]; then - name="main" + # Set default name. + [[ "${name}" = "" ]] && 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 - - # call tmux. - tmux new -s "$name" 2> /dev/null || tmux attach-session -t "$name" } # Detach from running session. diff --git a/.config/tmux/tmux.conf b/.config/tmux/tmux.conf index 641bf82..37d40b0 100644 --- a/.config/tmux/tmux.conf +++ b/.config/tmux/tmux.conf @@ -1,12 +1,12 @@ -# remap to . +# Remap to . unbind-key C-b set-option -g prefix C-t bind-key C-t send-prefix -# disable escape delay. +# Disable escape delay. 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 -v -c "#{pane_current_path}" bind -n M-= select-layout tiled @@ -17,56 +17,59 @@ bind -n M-l resize-pane -R 1 unbind '"' unbind % -# reload config. +# Reload config. 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-d select-pane -R bind -n M-w select-pane -U bind -n M-s select-pane -D -# close pane. +# Close pane. bind -n M-c kill-pane 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-t new-window -c "#{pane_current_path}" # NOTE: for compatibility with Termux as it does not support yet. -# close window. +# Close window. bind -n M-x kill-window bind -n M-X kill-window -a -# switch window. +# Switch window. bind -n M-e next-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-Q swap-window -t -1\; select-window -t -1 -# detach. +# Detach. bind -n M-z detach-client bind -n M-Z detach-client -a -# scroll. +# Scroll. bind -n M-p copy-mode -u bind -n M-n send-keys Pagedown -# copy mode. +# Copy mode. setw -g mode-keys vi bind -n M-v copy-mode bind -n M-P paste-buffer bind -T copy-mode-vi v send -X begin-selection 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. set -g window-size smallest -# statusbar +# Statusbar. set -g status-position bottom set -g status-justify left set -g status-style 'bg=yellow fg=black dim' diff --git a/.doc/Navigation.md b/.doc/Navigation.md index 5f5a6d7..2c1106b 100644 --- a/.doc/Navigation.md +++ b/.doc/Navigation.md @@ -30,6 +30,9 @@ Key|Action `Super+l`|None. `Super+p`|None. `Super+n`|None. +`Super+g`|None. +`Super+9`|None. +`Super+0`|None. ## Tmux. @@ -61,6 +64,9 @@ Key|Action `Meta+l`|Resize split to the right. `Meta+p`|Scroll up. `Meta+n`|Scroll down. +`Meta+g`|Switch sessions. +`Meta+9`|Switch to the previous session. +`Meta+0`|Switch to the next session. ## Nvim. @@ -89,5 +95,8 @@ Key|Action `Space+l`|Resize split to the right. `Space+p`|None. `Space+n`|None. +`Space+g`|None. +`Space+9`|None. +`Space+0`|None. More info in [Nvim doc.](Nvim.md)