-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtmux.conf
278 lines (225 loc) · 9.2 KB
/
tmux.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
# cat << EOF > /dev/null
# -- general -------------------------------------------------------------------
set -g default-terminal "tmux-256color" # colors!
set -ga terminal-overrides ",xterm-256color*:Tc"
set -g set-clipboard on
set -s escape-time 10 # faster command sequences
set -s focus-events on
# remap prefix from 'C-b' to 'C-a'
unbind C-b
set-option -g prefix C-a
bind-key C-a send-prefix
set -g history-limit 20000 # boost history
# edit configuration
bind e new-window -n '~/.tmux.conf' "sh -c '\${EDITOR:-nvim} ~/.tmux.conf && tmux source ~/.tmux.conf && tmux display \"~/.tmux.conf sourced\"'"
# reload configuration
bind r source-file ~/.tmux.conf \; display '~/.tmux.conf sourced'
# start with mouse mode enabled
set -g mouse on
# enable vi mode for copy
setw -g mode-keys vi
# emacs key bindings in tmux command prompt (prefix + :) are better than
# vi keys, even for vim users
set -g status-keys emacs
# -- display -------------------------------------------------------------------
set -g base-index 1 # start windows numbering at 1
setw -g pane-base-index 1 # make pane numbering consistent with windows
set -g automatic-rename on # rename window to reflect current program
set -g automatic-rename-format '#{b:pane_current_path}'
set -g renumber-windows on # renumber windows when a window is closed
set -g set-titles on # set terminal title
set -g set-titles-string '#h ❐ #S ● #I #W'
set -g display-panes-time 800 # slightly longer pane indicators display time
set -g display-time 1000 # slightly longer status messages display time
set -g status-interval 10 # redraw status line every 10 seconds
# clear both screen and history
bind -n C-l send-keys C-l \; run 'sleep 0.1' \; clear-history
# -- navigation ----------------------------------------------------------------
# create session
bind C-c new-session
# split current window horizontally
bind s split-window -v -c "#{pane_current_path}"
# split current window vertically
bind v split-window -h -c "#{pane_current_path}"
unbind '"'
unbind %
# pane navigation
bind h select-pane -L
bind j select-pane -D
bind k select-pane -U
bind l select-pane -R
bind > swap-pane -D # swap current pane with the next one
bind < swap-pane -U # swap current pane with the previous one
# maximize current pane
bind + run 'cut -c3- ~/.tmux.conf | sh -s _maximize_pane "#{session_name}" #D'
# pane resizing
bind -r H resize-pane -L 2
bind -r J resize-pane -D 2
bind -r K resize-pane -U 2
bind -r L resize-pane -R 2
# window navigation
unbind n
unbind p
bind -r C-h previous-window # select previous window
bind -r C-l next-window # select next window
bind Tab last-window # move to last active window
# toggle mouse
bind m run "cut -c3- ~/.tmux.conf | sh -s _toggle_mouse"
# Fast switching projects
bind o display-popup -E 'cut -c3- ~/.tmux.conf | zsh -s _open_project --project ~/Documents/dotfiles --project ~/dotfiles --directory ~/Workspace'
bind O display-popup -E 'cut -c3- ~/.tmux.conf | zsh -s _open_project --replace --project ~/Documents/dotfiles --project ~/dotfiles --directory ~/Workspace'
# -- copy mode -----------------------------------------------------------------
bind Enter copy-mode # enter copy mode
bind -T copy-mode-vi v send -X begin-selection
bind -T copy-mode-vi C-v send -X rectangle-toggle
bind -T copy-mode-vi Escape send -X cancel
bind -T copy-mode-vi y send -X copy-selection \; send -X clear-selection
bind -T copy-mode-vi MouseDragEnd1Pane send -X copy-selection \; send -X clear-selection
# -- buffers -------------------------------------------------------------------
bind b list-buffers # list paste buffers
bind p paste-buffer # paste from the top paste buffer
bind P choose-buffer # choose which buffer to paste from
# -- theme ---------------------------------------------------------------------
set -g @catppuccin_flavor "macchiato"
set -g @catppuccin_status_background "none"
set -g @catppuccin_window_status_style "custom"
set -g @catppuccin_window_left_separator "#[fg=#{@catppuccin_window_text_color},bg=default]#[none]"
set -g @catppuccin_window_middle_separator " "
set -g @catppuccin_window_right_separator "#[fg=#{@catppuccin_window_number_color},bg=default]#[none]"
set -g @catppuccin_window_current_left_separator "#[fg=#{@catppuccin_window_current_text_color},bg=default]#[none]"
set -g @catppuccin_window_current_right_separator "#[fg=#{@catppuccin_window_current_number_color},bg=default]#[none]"
set -g @catppuccin_status_module_text_bg "#{@thm_mantle}"
set -g @catppuccin_window_number_position "right"
set -g @catppuccin_window_text "#W#{?window_zoomed_flag, 🔍,}"
set -g @catppuccin_window_current_text "#W#{?window_zoomed_flag, 🔍,}"
set -g @catppuccin_date_time_text " %b %d %R"
set -g @catppuccin_host_text " #h"
run ~/.config/tmux/plugins/catppuccin/tmux/catppuccin.tmux
set -g status-left-length 100
set -g status-right-length 100
set -g @_session_status_fg "#{?client_prefix,#{E:@thm_red},#{E:@thm_green}}"
set -g status-left "#[fg=#{@thm_fg},bg=#{E:@catppuccin_status_module_text_bg}] #S #[fg=#{E:@_session_status_fg}]█#[fg=#{@thm_crust},bg=#{E:@_session_status_fg}]#[fg=#{E:@_session_status_fg},bg=default] "
set -g status-right "#{E:@catppuccin_status_application}"
set -ag status-right "#{E:@catppuccin_status_date_time}"
set -ag status-right "#{E:@catppuccin_status_host}"
# EOF
#
# # exit the script if any statement returns a non-true return value
# set -e
#
# unset GREP_OPTIONS
# export LC_NUMERIC=C
#
# if ! printf '' | sed -E 's///' 2>/dev/null; then
# if printf '' | sed -r 's///' 2>/dev/null; then
# sed () {
# n=$#; while [ "$n" -gt 0 ]; do arg=$1; shift; case $arg in -E*) arg=-r${arg#-E};; esac; set -- "$@" "$arg"; n=$(( n - 1 )); done
# command sed "$@"
# }
# fi
# fi
#
# __newline='
# '
#
# _maximize_pane() {
# current_session=${1:-$(tmux display -p '#{session_name}')}
# current_pane=${2:-$(tmux display -p '#{pane_id}')}
#
# dead_panes=$(tmux list-panes -s -t "$current_session" -F '#{pane_dead} #{pane_id} #{pane_start_command}' | grep -E -o '^1 %.+maximized.+$' || true)
# restore=$(echo "$dead_panes" | sed -n -E -e "s/^1 $current_pane .+maximized.+'(%[0-9]+)'$/tmux swap-pane -s \1 -t $current_pane \; kill-pane -t $current_pane/p" -e "s/^1 (%[0-9]+) .+maximized.+'$current_pane'$/tmux swap-pane -s \1 -t $current_pane \; kill-pane -t \1/p" )
#
# if [ -z "$restore" ]; then
# [ "$(tmux list-panes -t "$current_session:" | wc -l | sed 's/^ *//g')" -eq 1 ] && tmux display "Can't maximize with only one pane" && return
# window=$(tmux new-window -t "$current_session:" -P "exec maximized... 2> /dev/null & tmux setw -t \"$current_session:\" remain-on-exit on; printf \"Pane has been maximized, press <prefix>+ to restore. %s\" '$current_pane'")
# window=${window%.*}
#
# retry=10
# while [ x"$(tmux list-panes -t "$window" -F '#{session_name}:#{window_index} #{pane_dead}' 2>/dev/null)" != x"$window 1" ] && [ "$retry" -ne 0 ]; do
# sleep 0.05
# retry=$((retry - 1))
# done
# if [ "$retry" -eq 0 ]; then
# tmux display 'Unable to maximize pane'
# fi
#
# new_pane=$(tmux display -t "$window" -p '#{pane_id}')
# tmux setw -t "$window" remain-on-exit off \; swap-pane -s "$current_pane" -t "$new_pane"
# else
# $restore || tmux kill-pane
# fi
# }
#
# _toggle_mouse() {
# old=$(tmux show -gv mouse)
# new=""
#
# if [ "$old" = "on" ]; then
# new="off"
# else
# new="on"
# fi
#
# tmux set -g mouse $new \;\
# display "mouse: $new"
# }
#
# _open_project() {
# PROJECTS=()
#
# while [[ $# -gt 0 ]]; do
# case $1 in
# -p|--project)
# if [[ -d "$2" ]]; then
# PROJECTS+=("$(readlink -f "$2")")
# fi
# shift
# shift
# ;;
# -d|--directory)
# if [[ -d "$2" ]]; then
# PROJECTS+=("$2"/*)
# fi
# shift
# shift
# ;;
# --replace)
# REPLACE=true
# shift
# ;;
# *)
# echo "Unknown option $1" >&2
# exit 1
# ;;
# esac
# done
#
# if [[ -f ~/.z ]]; then
# NOW="$(date +%s)"
# typeset -A FRECENTS
# while read LINE; do
# IFS="|" read DIR RANK TIME <<< "$LINE"
# FRECENT=$((10000 * $RANK * (3.75 / (0.0001 * ($NOW - $TIME) + 1.25))))
# FRECENTS["$DIR"]=$FRECENT
# done < ~/.z
# fi
#
# RANKED_PROJECTS=$(for i in "${PROJECTS[@]}"; do FRECENT=${FRECENTS["$i"]-0}; echo "$FRECENT\t$i"; done)
# IFS=$'\n' SORTED_PROJECTS=($(sort -t $'\t' -k 1 -g -r <<< "${RANKED_PROJECTS[*]}"))
#
# PROJECT_WITH_NAMES=$(for i in "${SORTED_PROJECTS[@]}"; do DIR=$(echo "$i" | cut -f2); echo "$(basename "$DIR")\t$DIR"; done)
#
# NAME_AND_DIR=$(printf "%s\n" "${PROJECT_WITH_NAMES[@]}" | fzf --with-nth 1 --delimiter='\t' --preview 'ls {2}')
# IFS=$'\t' read PROJECT_NAME PROJECT_DIR <<< "$NAME_AND_DIR"
#
# OPEN_NVIM="nvim; zsh"
# if [[ -z "$REPLACE" ]]; then
# tmux new-window -S -n "$PROJECT_NAME" -c "$PROJECT_DIR" "$OPEN_NVIM"
# else
# SESSION_NAME=$(tmux display-message -p '#S')
# tmux rename-window "$PROJECT_NAME"
# tmux new-window -k -n "$PROJECT_NAME" -c "$PROJECT_DIR" -t "$SESSION_NAME:$PROJECT_NAME" "$OPEN_NVIM"
# fi
# }
#
# "$@"