mirror of
1
0
Fork 0

added support for TMUX_CONF and TMUX_CONF_LOCAL environment variables

exporting these environment variables before launching tmux gives flexibility
with respect to dot files preferred location

⚠️ this raises tmux minimum version to 2.4 as it relies of conditional parsing
of configuration directives with %if/%endif
This commit is contained in:
Gregory Pakosz 2019-04-27 15:23:12 +02:00
parent 915d4a3960
commit 3e5289d022
1 changed files with 52 additions and 41 deletions

View File

@ -7,6 +7,17 @@
# instead, override settings in ~/.tmux.conf.local, see README.md
# -- environment variables -----------------------------------------------------
%if #{==:#{TMUX_CONF},}
TMUX_CONF='~/.tmux.conf'
%endif
%if #{==:#{TMUX_CONF_LOCAL},}
TMUX_CONF_LOCAL='~/.tmux.conf.local'
%endif
# -- general -------------------------------------------------------------------
set -g default-terminal "screen-256color" # colors!
@ -24,10 +35,10 @@ setw -q -g utf8 on
set -g history-limit 5000 # boost history
# edit configuration
bind e new-window -n '~/.tmux.conf.local' "sh -c '\${EDITOR:-vim} ~/.tmux.conf.local && tmux source ~/.tmux.conf && tmux display \"~/.tmux.conf sourced\"'"
bind e new-window -n '#{TMUX_CONF_LOCAL}' "sh -c '\${EDITOR:-vim} $TMUX_CONF_LOCAL && tmux source $TMUX_CONF && tmux display \"$TMUX_CONF sourced\"'"
# reload configuration
bind r source-file ~/.tmux.conf \; display '~/.tmux.conf sourced'
bind r run 'tmux source "${TMUX_CONF/#\~/$HOME}" \; display "$TMUX_CONF sourced"'
# -- display -------------------------------------------------------------------
@ -75,7 +86,7 @@ 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'
bind + run 'cut -c3- #{TMUX_CONF} | sh -s _maximize_pane "#{session_name}" #D'
# pane resizing
bind -r H resize-pane -L 2
@ -91,17 +102,17 @@ 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"
bind m run "cut -c3- #{TMUX_CONF} | sh -s _toggle_mouse"
# -- urlview -------------------------------------------------------------------
bind U run "cut -c3- ~/.tmux.conf | sh -s _urlview #{pane_id}"
bind U run "cut -c3- #{TMUX_CONF} | sh -s _urlview #{pane_id}"
# -- facebook pathpicker -------------------------------------------------------
bind F run "cut -c3- ~/.tmux.conf | sh -s _fpp #{pane_id}"
bind F run "cut -c3- #{TMUX_CONF} | sh -s _fpp #{pane_id}"
# -- list choice (tmux < 2.4) --------------------------------------------------
@ -162,12 +173,12 @@ bind P choose-buffer # choose which buffer to paste from
# -- user defined overrides ----------------------------------------------------
if '[ -f ~/.tmux.conf.local ]' 'source ~/.tmux.conf.local'
run 'tmux source -q "${TMUX_CONF_LOCAL/#\~/$HOME}"'
# -- 8< ------------------------------------------------------------------------
run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration'
run 'cut -c3- #{TMUX_CONF} | sh -s _apply_configuration'
# EOF
@ -822,12 +833,12 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration'
# tmux_conf_theme_terminal_title=${tmux_conf_theme_terminal_title:-'#h ❐ #S ● #I #W'}
#
# tmux_conf_theme_terminal_title=$(echo "$tmux_conf_theme_terminal_title" | sed \
# -e 's%#{circled_window_index}%#(cut -c3- ~/.tmux.conf | sh -s _circled #I)%g' \
# -e 's%#{circled_session_name}%#(cut -c3- ~/.tmux.conf | sh -s _circled #S)%g' \
# -e 's%#{username}%#(cut -c3- ~/.tmux.conf | sh -s _username #{pane_tty} false #D)%g' \
# -e 's%#{hostname}%#(cut -c3- ~/.tmux.conf | sh -s _hostname #{pane_tty} false #D)%g' \
# -e 's%#{username_ssh}%#(cut -c3- ~/.tmux.conf | sh -s _username #{pane_tty} true #D)%g' \
# -e 's%#{hostname_ssh}%#(cut -c3- ~/.tmux.conf | sh -s _hostname #{pane_tty} true #D)%g')
# -e 's%#{circled_window_index}%#(cut -c3- #{TMUX_CONF} | sh -s _circled #I)%g' \
# -e 's%#{circled_session_name}%#(cut -c3- #{TMUX_CONF} | sh -s _circled #S)%g' \
# -e 's%#{username}%#(cut -c3- #{TMUX_CONF} | sh -s _username #{pane_tty} false #D)%g' \
# -e 's%#{hostname}%#(cut -c3- #{TMUX_CONF} | sh -s _hostname #{pane_tty} false #D)%g' \
# -e 's%#{username_ssh}%#(cut -c3- #{TMUX_CONF} | sh -s _username #{pane_tty} true #D)%g' \
# -e 's%#{hostname_ssh}%#(cut -c3- #{TMUX_CONF} | sh -s _hostname #{pane_tty} true #D)%g')
# tmux set -g set-titles-string "$tmux_conf_theme_terminal_title"
#
# tmux_conf_theme_window_status_fg=${tmux_conf_theme_window_status_fg:-'#8a8a8a'} # white
@ -846,19 +857,19 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration'
# fi
#
# tmux_conf_theme_window_status_format=$(echo "$tmux_conf_theme_window_status_format" | sed \
# -e 's%#{circled_window_index}%#(cut -c3- ~/.tmux.conf | sh -s _circled #I)%g' \
# -e 's%#{circled_session_name}%#(cut -c3- ~/.tmux.conf | sh -s _circled #S)%g' \
# -e 's%#{username}%#(cut -c3- ~/.tmux.conf | sh -s _username #{pane_tty} false #D)%g' \
# -e 's%#{hostname}%#(cut -c3- ~/.tmux.conf | sh -s _hostname #{pane_tty} false #D)%g' \
# -e 's%#{username_ssh}%#(cut -c3- ~/.tmux.conf | sh -s _username #{pane_tty} true #D)%g' \
# -e 's%#{hostname_ssh}%#(cut -c3- ~/.tmux.conf | sh -s _hostname #{pane_tty} true #D)%g')
# -e 's%#{circled_window_index}%#(cut -c3- #{TMUX_CONF} | sh -s _circled #I)%g' \
# -e 's%#{circled_session_name}%#(cut -c3- #{TMUX_CONF} | sh -s _circled #S)%g' \
# -e 's%#{username}%#(cut -c3- #{TMUX_CONF} | sh -s _username #{pane_tty} false #D)%g' \
# -e 's%#{hostname}%#(cut -c3- #{TMUX_CONF} | sh -s _hostname #{pane_tty} false #D)%g' \
# -e 's%#{username_ssh}%#(cut -c3- #{TMUX_CONF} | sh -s _username #{pane_tty} true #D)%g' \
# -e 's%#{hostname_ssh}%#(cut -c3- #{TMUX_CONF} | sh -s _hostname #{pane_tty} true #D)%g')
# tmux_conf_theme_window_status_current_format=$(echo "$tmux_conf_theme_window_status_current_format" | sed \
# -e 's%#{circled_window_index}%#(cut -c3- ~/.tmux.conf | sh -s _circled #I)%g' \
# -e 's%#{circled_session_name}%#(cut -c3- ~/.tmux.conf | sh -s _circled #S)%g' \
# -e 's%#{username}%#(cut -c3- ~/.tmux.conf | sh -s _username #{pane_tty} false #D)%g' \
# -e 's%#{hostname}%#(cut -c3- ~/.tmux.conf | sh -s _hostname #{pane_tty} false #D)%g' \
# -e 's%#{username_ssh}%#(cut -c3- ~/.tmux.conf | sh -s _username #{pane_tty} true #D)%g' \
# -e 's%#{hostname_ssh}%#(cut -c3- ~/.tmux.conf | sh -s _hostname #{pane_tty} true #D)%g')
# -e 's%#{circled_window_index}%#(cut -c3- #{TMUX_CONF} | sh -s _circled #I)%g' \
# -e 's%#{circled_session_name}%#(cut -c3- #{TMUX_CONF} | sh -s _circled #S)%g' \
# -e 's%#{username}%#(cut -c3- #{TMUX_CONF} | sh -s _username #{pane_tty} false #D)%g' \
# -e 's%#{hostname}%#(cut -c3- #{TMUX_CONF} | sh -s _hostname #{pane_tty} false #D)%g' \
# -e 's%#{username_ssh}%#(cut -c3- #{TMUX_CONF} | sh -s _username #{pane_tty} true #D)%g' \
# -e 's%#{hostname_ssh}%#(cut -c3- #{TMUX_CONF} | sh -s _hostname #{pane_tty} true #D)%g')
#
# tmux setw -g window-status-style "fg=$tmux_conf_theme_window_status_fg,bg=$tmux_conf_theme_window_status_bg,$tmux_conf_theme_window_status_attr" \;\
# setw -g window-status-format "$tmux_conf_theme_window_status_format" \;\
@ -916,7 +927,7 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration'
# -e "s/#{prefix}/#[fg=$tmux_conf_theme_prefix_fg]#[bg=$tmux_conf_theme_prefix_bg]#[$tmux_conf_theme_prefix_attr]#{?client_prefix,$tmux_conf_theme_prefix,}/g")
#
# tmux_conf_theme_status_left=$(echo "$tmux_conf_theme_status_left" | sed \
# -e "s%#{root}%#[fg=$tmux_conf_theme_root_fg]#[bg=$tmux_conf_theme_root_bg]#[$tmux_conf_theme_root_attr]#(cut -c3- ~/.tmux.conf | sh -s _root #{pane_tty} #D)#[inherit]%g")
# -e "s%#{root}%#[fg=$tmux_conf_theme_root_fg]#[bg=$tmux_conf_theme_root_bg]#[$tmux_conf_theme_root_attr]#(cut -c3- #{TMUX_CONF} | sh -s _root #{pane_tty} #D)#[inherit]%g")
#
# tmux_conf_theme_status_left=$(echo "$tmux_conf_theme_status_left" | sed \
# -e "s%#{synchronized}%#[fg=$tmux_conf_theme_synchronized_fg]#[bg=$tmux_conf_theme_synchronized_bg]#[$tmux_conf_theme_synchronized_attr]#{?pane_synchronized,$tmux_conf_theme_synchronized,}%g")
@ -1003,7 +1014,7 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration'
# -e "s/#{prefix}/#[fg=$tmux_conf_theme_prefix_fg]#[bg=$tmux_conf_theme_prefix_bg]#[$tmux_conf_theme_prefix_attr]#{?client_prefix,$tmux_conf_theme_prefix,}/g")
#
# tmux_conf_theme_status_right=$(echo "$tmux_conf_theme_status_right" | sed \
# -e "s%#{root}%#[fg=$tmux_conf_theme_root_fg]#[bg=$tmux_conf_theme_root_bg]#[$tmux_conf_theme_root_attr]#(cut -c3- ~/.tmux.conf | sh -s _root #{pane_tty} #D)#[inherit]%g")
# -e "s%#{root}%#[fg=$tmux_conf_theme_root_fg]#[bg=$tmux_conf_theme_root_bg]#[$tmux_conf_theme_root_attr]#(cut -c3- #{TMUX_CONF} | sh -s _root #{pane_tty} #D)#[inherit]%g")
#
# tmux_conf_theme_status_right=$(echo "$tmux_conf_theme_status_right" | sed \
# -e "s%#{synchronized}%#[fg=$tmux_conf_theme_synchronized_fg]#[bg=$tmux_conf_theme_synchronized_bg]#[$tmux_conf_theme_synchronized_attr]#{?pane_synchronized,$tmux_conf_theme_synchronized,}%g")
@ -1104,22 +1115,22 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration'
# set -g '@battery_vbar_palette' "$tmux_conf_battery_vbar_palette" \;\
# set -g '@battery_status_charging' "$tmux_conf_battery_status_charging" \;\
# set -g '@battery_status_discharging' "$tmux_conf_battery_status_discharging"
# status_right="#(cut -c3- ~/.tmux.conf | sh -s _battery)$status_right"
# status_right="#(cut -c3- #{TMUX_CONF} | sh -s _battery)$status_right"
# ;;
# esac
#
# case "$status_left $status_right" in
# *'#{username}'*|*'#{hostname}'*|*'#{username_ssh}'*|*'#{hostname_ssh}'*)
# status_left=$(echo "$status_left" | sed \
# -e 's%#{username}%#(cut -c3- ~/.tmux.conf | sh -s _username #{pane_tty} false #D)%g' \
# -e 's%#{hostname}%#(cut -c3- ~/.tmux.conf | sh -s _hostname #{pane_tty} false #D)%g' \
# -e 's%#{username_ssh}%#(cut -c3- ~/.tmux.conf | sh -s _username #{pane_tty} true #D)%g' \
# -e 's%#{hostname_ssh}%#(cut -c3- ~/.tmux.conf | sh -s _hostname #{pane_tty} true #D)%g')
# -e 's%#{username}%#(cut -c3- #{TMUX_CONF} | sh -s _username #{pane_tty} false #D)%g' \
# -e 's%#{hostname}%#(cut -c3- #{TMUX_CONF} | sh -s _hostname #{pane_tty} false #D)%g' \
# -e 's%#{username_ssh}%#(cut -c3- #{TMUX_CONF} | sh -s _username #{pane_tty} true #D)%g' \
# -e 's%#{hostname_ssh}%#(cut -c3- #{TMUX_CONF} | sh -s _hostname #{pane_tty} true #D)%g')
# status_right=$(echo "$status_right" | sed \
# -e 's%#{username}%#(cut -c3- ~/.tmux.conf | sh -s _username #{pane_tty} false #D)%g' \
# -e 's%#{hostname}%#(cut -c3- ~/.tmux.conf | sh -s _hostname #{pane_tty} false #D)%g' \
# -e 's%#{username_ssh}%#(cut -c3- ~/.tmux.conf | sh -s _username #{pane_tty} true #D)%g' \
# -e 's%#{hostname_ssh}%#(cut -c3- ~/.tmux.conf | sh -s _hostname #{pane_tty} true #D)%g')
# -e 's%#{username}%#(cut -c3- #{TMUX_CONF} | sh -s _username #{pane_tty} false #D)%g' \
# -e 's%#{hostname}%#(cut -c3- #{TMUX_CONF} | sh -s _hostname #{pane_tty} false #D)%g' \
# -e 's%#{username_ssh}%#(cut -c3- #{TMUX_CONF} | sh -s _username #{pane_tty} true #D)%g' \
# -e 's%#{hostname_ssh}%#(cut -c3- #{TMUX_CONF} | sh -s _hostname #{pane_tty} true #D)%g')
# ;;
# esac
#
@ -1135,7 +1146,7 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration'
# -e 's/#\{(\?)?uptime_h/#\{\1@uptime_h/g' \
# -e 's/#\{(\?)?uptime_m/#\{\1@uptime_m/g' \
# -e 's/#\{(\?)?uptime_s/#\{\1@uptime_s/g')
# status_right="#(cut -c3- ~/.tmux.conf | sh -s _uptime)$status_right"
# status_right="#(cut -c3- #{TMUX_CONF} | sh -s _uptime)$status_right"
# ;;
# esac
#
@ -1145,12 +1156,12 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration'
# -e 's/#\{(\?)?loadavg/#\{\1@loadavg/g')
# status_right=$(echo "$status_right" | sed -E \
# -e 's/#\{(\?)?loadavg/#\{\1@loadavg/g')
# status_right="#(cut -c3- ~/.tmux.conf | sh -s _loadavg)$status_right"
# status_right="#(cut -c3- #{TMUX_CONF} | sh -s _loadavg)$status_right"
# ;;
# esac
#
# status_left=$(echo "$status_left" | sed 's%#{circled_session_name}%#(cut -c3- ~/.tmux.conf | sh -s _circled #S)%g')
# status_right=$(echo "$status_right" | sed 's%#{circled_session_name}%#(cut -c3- ~/.tmux.conf | sh -s _circled #S)%g')
# status_left=$(echo "$status_left" | sed 's%#{circled_session_name}%#(cut -c3- #{TMUX_CONF} | sh -s _circled #S)%g')
# status_right=$(echo "$status_right" | sed 's%#{circled_session_name}%#(cut -c3- #{TMUX_CONF} | sh -s _circled #S)%g')
#
# tmux set -g status-left-length 1000 \; set -g status-left "$status_left" \;\
# set -g status-right-length 1000 \; set -g status-right "$status_right"