From e8ef9a6f729304ce9bde4e323615e4c267eccd44 Mon Sep 17 00:00:00 2001 From: Gregory Pakosz Date: Sat, 12 Oct 2024 10:41:28 +0200 Subject: [PATCH] added the #{pretty_pane_current_path} variable --- .tmux.conf | 22 +++++++++++++++++++++- .tmux.conf.local | 1 + README.md | 2 ++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/.tmux.conf b/.tmux.conf index e8f1d74..ad3cace 100644 --- a/.tmux.conf +++ b/.tmux.conf @@ -204,7 +204,14 @@ run 'cut -c3- "$TMUX_CONF" | sh -s _apply_configuration' # _tmux_version=$(tmux -V | perl -n -e '($l, $r) = $_ =~ /^[^0-9]+([0-9.]+)([a-z])?(-rc.*)?$/; print $l * 1000 + ($r eq "" ? 0 : ord($r) - 96)') # # _is_true() { -# [ "$1" = "true" ] || [ "$1" = "yes" ] || [ "$1" = "1" ] +# case "$1" in +# true|yes|1) +# return 0 +# ;; +# *) +# return 1 +# ;; +# esac # } # # _is_enabled() { @@ -230,6 +237,14 @@ run 'cut -c3- "$TMUX_CONF" | sh -s _apply_configuration' # printf '%s' "$*" | perl -CS -pe 's/(\\u([0-9A-Fa-f]{1,4})|\\U([0-9A-Fa-f]{1,8}))/chr(hex($2.$3))/eg' 2>/dev/null # } # +# _pretty_path() { +# max_length=${1:-auto}; shift +# if [ "$max_length" = "auto" ]; then +# max_length=$(($(tmux -q display -p '#{client_width}') / 4)) +# fi +# { cd "$*" && pwd || printf '%s' "$*"; } | perl -s -p -E 's|^$HOME|~|; /^.{0,$max_length}$/ || s|(~?\/[^/]+)(/[^/]+)(?:/.+)(/[^/]+)$|$1$2/...$3|g' -- -HOME="$HOME" -max_length="$max_length" +# } +# # if command -v pkill > /dev/null 2>&1; then # _pkillf() { # pkill -f "$@" || true @@ -1388,6 +1403,7 @@ run 'cut -c3- "$TMUX_CONF" | sh -s _apply_configuration' # set_titles_string=$(printf '%s' "${tmux_conf_theme_terminal_title:-$(tmux show -gv set-titles-string)}" | 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%#{pretty_pane_current_path}%#(cut -c3- '$TMUX_CONF' | sh -s _pretty_path auto '#{pane_current_path}')%g" \ # -e "s%#{username}%#(cut -c3- '$TMUX_CONF' | sh -s _username '#{pane_pid}' '#{b:pane_tty}' false '#D')%g" \ # -e "s%#{hostname}%#(cut -c3- '$TMUX_CONF' | sh -s _hostname '#{pane_pid}' '#{b:pane_tty}' false false '#h' '#D')%g" \ # -e "s%#{hostname_full}%#(cut -c3- '$TMUX_CONF' | sh -s _hostname '#{pane_pid}' '#{b:pane_tty}' false true '#H' '#D')%g" \ @@ -1398,6 +1414,7 @@ run 'cut -c3- "$TMUX_CONF" | sh -s _apply_configuration' # window_status_format=$(printf '%s' "${window_status_format:-$(tmux show -gv 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%#{pretty_pane_current_path}%#(cut -c3- '$TMUX_CONF' | sh -s _pretty_path auto '#{pane_current_path}')%g" \ # -e "s%#{username}%#(cut -c3- '$TMUX_CONF' | sh -s _username '#{pane_pid}' '#{b:pane_tty}' false '#D')%g" \ # -e "s%#{hostname}%#(cut -c3- '$TMUX_CONF' | sh -s _hostname '#{pane_pid}' '#{b:pane_tty}' false false '#h' '#D')%g" \ # -e "s%#{hostname_full}%#(cut -c3- '$TMUX_CONF' | sh -s _hostname '#{pane_pid}' '#{b:pane_tty}' false true '#H' '#D')%g" \ @@ -1408,6 +1425,7 @@ run 'cut -c3- "$TMUX_CONF" | sh -s _apply_configuration' # window_status_current_format=$(printf '%s' "${window_status_current_format:-$(tmux show -gv 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%#{pretty_pane_current_path}%#(cut -c3- '$TMUX_CONF' | sh -s _pretty_path auto '#{pane_current_path}')%g" \ # -e "s%#{username}%#(cut -c3- '$TMUX_CONF' | sh -s _username '#{pane_pid}' '#{b:pane_tty}' false '#D')%g" \ # -e "s%#{hostname}%#(cut -c3- '$TMUX_CONF' | sh -s _hostname '#{pane_pid}' '#{b:pane_tty}' false false '#h' '#D')%g" \ # -e "s%#{hostname_full}%#(cut -c3- '$TMUX_CONF' | sh -s _hostname '#{pane_pid}' '#{b:pane_tty}' false true '#H' '#D')%g" \ @@ -1421,6 +1439,7 @@ run 'cut -c3- "$TMUX_CONF" | sh -s _apply_configuration' # -e "s/#{mouse}/#{?mouse,$tmux_conf_theme_mouse ,$(printf '%s' "$tmux_conf_theme_mouse" | sed -e 's/./ /g') }/g" \ # -e "s%#{synchronized}%#{?pane_synchronized,$tmux_conf_theme_synchronized ,}%g" \ # -e "s%#{circled_session_name}%#(cut -c3- '$TMUX_CONF' | sh -s _circled '#S')%g" \ +# -e "s%#{pretty_pane_current_path}%#(cut -c3- '$TMUX_CONF' | sh -s _pretty_path auto '#{pane_current_path}')%g" \ # -e "s%#{root}%#{?#{==:#(cut -c3- '$TMUX_CONF' | sh -s _username '#{pane_pid}' '#{b:pane_tty}' '#D'),root},$tmux_conf_theme_root,}%g") # # status_right=$(printf '%s' "${status_right-$(tmux show -gv status-right)}" | sed \ @@ -1429,6 +1448,7 @@ run 'cut -c3- "$TMUX_CONF" | sh -s _apply_configuration' # -e "s/#{mouse}/#{?mouse,$tmux_conf_theme_mouse ,$(printf '%s' "$tmux_conf_theme_mouse" | sed -e 's/./ /g') }/g" \ # -e "s%#{synchronized}%#{?pane_synchronized,$tmux_conf_theme_synchronized ,}%g" \ # -e "s%#{circled_session_name}%#(cut -c3- '$TMUX_CONF' | sh -s _circled '#S')%g" \ +# -e "s%#{pretty_pane_current_path}%#(cut -c3- '$TMUX_CONF' | sh -s _pretty_path auto '#{pane_current_path}')%g" \ # -e "s%#{root}%#{?#{==:#(cut -c3- '$TMUX_CONF' | sh -s _username '#{pane_pid}' '#{b:pane_tty}' '#D'),root},$tmux_conf_theme_root,}%g") # # tmux_conf_battery_bar_symbol_full=$(_decode_unicode_escapes "${tmux_conf_battery_bar_symbol_full:-◼}") diff --git a/.tmux.conf.local b/.tmux.conf.local index 88a4780..3e7aea8 100644 --- a/.tmux.conf.local +++ b/.tmux.conf.local @@ -268,6 +268,7 @@ tmux_conf_theme_right_separator_sub="|" # - #{username} # - #{username_ssh} tmux_conf_theme_status_left=" ❐ #S | ↑#{?uptime_y, #{uptime_y}y,}#{?uptime_d, #{uptime_d}d,}#{?uptime_h, #{uptime_h}h,}#{?uptime_m, #{uptime_m}m,} " +#tmux_conf_theme_status_left=" ❐ #S | ↑#{?uptime_y, #{uptime_y}y,}#{?uptime_d, #{uptime_d}d,}#{?uptime_h, #{uptime_h}h,}#{?uptime_m, #{uptime_m}m,} | #{pretty_pane_current_path} " tmux_conf_theme_status_right=" #{prefix}#{mouse}#{pairing}#{synchronized}#{?battery_status,#{battery_status},}#{?battery_bar, #{battery_bar},}#{?battery_percentage, #{battery_percentage},} , %R , %d %b | #{username}#{root} | #{hostname} " # status left style diff --git a/README.md b/README.md index 82eaeec..5e7f695 100644 --- a/README.md +++ b/README.md @@ -277,6 +277,8 @@ This configuration supports the following builtin variables: connected to a remote server through SSH/Mosh - `#{loadavg}`: load average - `#{pairing}`: is session attached to more than one client? + - `#{pretty_pane_current_path}`: prettified `#{pane_current_path}` when its + length is too long - `#{prefix}`: is prefix being depressed? - `#{root}`: is current user root? - `#{synchronized}`: are the panes synchronized?