From 6e7f7c6a21145dccf45113ac1d2f3773af21a22f Mon Sep 17 00:00:00 2001 From: Bruce Wen Date: Wed, 22 Oct 2025 06:57:04 +0200 Subject: [PATCH] If the target theme doesn't exist, save the current dynamic theme to it rather than logging not found message Use template.6.theme.yaml as default template template.theme.yaml Reapply "Reapply "Use template.6.theme.yaml as default template template.theme.yaml"" This reverts commit 55edce752be3ed04c6a81be711905e8e6e3d6e50. --- eutmux.tmux | 23 +++++---- hooks/session-window-changed.hook | 7 ++- template.theme.yaml | 80 +++++++++++++++---------------- 3 files changed, 61 insertions(+), 49 deletions(-) diff --git a/eutmux.tmux b/eutmux.tmux index eedad91..a41fcf4 100755 --- a/eutmux.tmux +++ b/eutmux.tmux @@ -42,6 +42,11 @@ PLACE_HOLDERS=( "DEEP_GRAY" ) +init(){ + # set working directory to eutmux project path + pushd "${_DIR}" >/dev/null 2>/dev/null || exit ${EXIT_ABNORMAL} +} + setup(){ # constants FORCE_SAVE_THEME=${FALSE} @@ -96,9 +101,6 @@ setup(){ ROTATE_THEME=${FALSE} CREATE_DYNMIC_THEME=${FALSE} - # set working directory to eutmux project path - pushd "${_DIR}" >/dev/null 2>/dev/null || exit ${EXIT_ABNORMAL} - # set config home and config file EUTMUX_CONFIG_HOME="${XDG_CONFIG_HOME:-${HOME}/.config}/eutmux" mkdir -p "${EUTMUX_CONFIG_HOME}" >/dev/null 2>/dev/null @@ -117,7 +119,7 @@ setup(){ tmux set-hook -g after-resize-pane "run-shell '${_DIR}/hooks/session-window-changed.hook'" } -teardown(){ +reset(){ popd >/dev/null 2>/dev/null || exit ${EXIT_ABNORMAL} } @@ -261,8 +263,12 @@ function save_dynamic_theme(){ current_dynamic_theme_cmd_filename="${current_dynamic_theme}${CMD_FILE_EXTENSION}" current_dynamic_palette_filename="${current_dynamic_theme}${PALETTE_FILE_EXTENSION}" + if [ "${new_theme_name}" == "${current_dynamic_theme}" ];then + return + fi + if [ -e "${EUTMUX_CONFIG_HOME}/${current_dynamic_theme_filename}" ];then - cp -f "${EUTMUX_CONFIG_HOME}/${current_dynamic_theme_filename}" "${EUTMUX_CONFIG_HOME}/${new_theme_name}${THEME_FILE_EXTENSION}" + cp -f "${EUTMUX_CONFIG_HOME}/${current_dynamic_theme_filename}" "${EUTMUX_CONFIG_HOME}/${new_theme_name}${THEME_FILE_EXTENSION}" cp -f "${EUTMUX_CONFIG_HOME}/${current_dynamic_palette_filename}" "${EUTMUX_CONFIG_HOME}/${new_theme_name}${PALETTE_FILE_EXTENSION}" cp -f "${EUTMUX_CONFIG_HOME}/${current_dynamic_theme_cmd_filename}" "${EUTMUX_CONFIG_HOME}/${new_theme_name}${CMD_FILE_EXTENSION}" fi @@ -281,9 +287,9 @@ apply_theme(){ else themes=$(show_all_themes) echo "$themes" | grep -q "${theme_name}" + # if the target theme name not exist, then save the current dynamic theme to it if [ $? -ne $TRUE ];then - tmux display-message -d "${DELAY}" "Not found theme: '${theme_name}'" - exit ${EXIT_ABNORMAL} + save_dynamic_theme ${theme_name} fi fi THEME_NAME="${theme_name}" @@ -422,6 +428,7 @@ usage(){ } # set -x +init setup while getopts "ac:dDfhLp:rRt:T:" opt; do case $opt in @@ -440,5 +447,5 @@ while getopts "ac:dDfhLp:rRt:T:" opt; do esac done main -teardown +reset set +x diff --git a/hooks/session-window-changed.hook b/hooks/session-window-changed.hook index 532f46d..e4dae23 100755 --- a/hooks/session-window-changed.hook +++ b/hooks/session-window-changed.hook @@ -1,6 +1,9 @@ #!/usr/bin/env bash +# trap "echo $GITHUB_REPO_ROOT" DEBUG + function change_theme(){ + set -x local eutmux_script=${GITHUB_REPO_ROOT}/eu.tmux/eutmux.tmux if [ ! -x ${eutmux_script} ];then return 2 @@ -26,12 +29,14 @@ function change_theme(){ if [[ ( ${is_pane_maximized} -eq 1 ) || ( ${panes_total} -eq 1 ) ]]; then if [ -n "${idename}" ];then ${eutmux_script} -t ${idename} - return 0 + return $? fi fi # for other cases, use default latset theme ${eutmux_script} -R + return $? fi + set +x } change_theme diff --git a/template.theme.yaml b/template.theme.yaml index cfe43b5..c85a383 100644 --- a/template.theme.yaml +++ b/template.theme.yaml @@ -3,51 +3,51 @@ terminal: foreground: "#b7b7ff" background: "#231f32" status_line: - foreground: "C_06_01" - background: "C_06_17" + foreground: "C_14_10" + background: "C_14_53" left_icon: "" right_icon: "" left_decorator: "" right_decorator: "" - fg_format: "C_06_06" - bg_format: "C_06_13" - fg_icon: "C_06_06" - bg_icon: "C_06_15" - fg_decorator: "C_06_15" - bg_decorator: "C_06_17" + fg_format: "C_14_20" + bg_format: "C_14_25" + fg_icon: "C_14_20" + bg_icon: "C_14_30" + fg_decorator: "C_14_30" + bg_decorator: "C_14_50" style: "nobold,nounderscore,noitalics" status_left: - fg_format: "C_04_08" - bg_format: "C_06_17" - fg_icon: "C_06_06" - bg_icon: "C_06_13" - fg_decorator: "C_06_13" - bg_decorator: "C_06_17" + fg_format: "C_10_25" + bg_format: "C_14_53" + fg_icon: "C_14_01" + bg_icon: "C_10_45" + fg_decorator: "C_10_45" + bg_decorator: "C_14_53" icon: "  " decorator: "" style: "nobold,nounderscore,noitalics" window: active: - fg_window: "C_04_14" - bg_window: "C_04_08" - fg_window_index: "C_04_14" - bg_window_index: "C_04_10" - fg_icon: "C_04_06" - bg_icon: "C_04_08" - fg_decorator: "C_04_10" - bg_decorator: "C_04_17" + fg_window: "C_14_59" + bg_window: "C_07_40" + fg_window_index: "C_14_59" + bg_window_index: "C_07_30" + fg_icon: "C_14_10" + bg_icon: "C_08_15" + fg_decorator: "C_07_30" + bg_decorator: "C_14_53" icon: "" decorator: "" style: "nobold,nounderscore,noitalics" inactive: - fg_window: "C_06_06" - bg_window: "C_06_13" - fg_window_index: "C_06_06" - bg_window_index: "C_06_15" + fg_window: "C_14_20" + bg_window: "C_14_35" + fg_window_index: "C_14_20" + bg_window_index: "C_14_45" fg_icon: "" bg_icon: "" - fg_decorator: "C_06_15" - bg_decorator: "C_06_17" + fg_decorator: "C_14_45" + bg_decorator: "C_14_53" icon: "" decorator: "" style: "nobold,nounderscore,noitalics" @@ -55,16 +55,16 @@ status_right: icon: " " decorator: "" style: "nobold,nounderscore,noitalics" - fg_format: "C_06_06" - bg_format: "C_06_13" - fg_icon: "C_06_06" - bg_icon: "C_06_15" - fg_decorator: "C_06_15" - bg_decorator: "C_06_17" + fg_format: "C_14_20" + bg_format: "C_14_40" + fg_icon: "C_14_15" + bg_icon: "C_14_45" + fg_decorator: "C_14_45" + bg_decorator: "C_14_53" directory: - fg_format: "C_05_06" - bg_format: "C_05_13" - fg_icon: "C_05_06" - bg_icon: "C_05_15" - fg_decorator: "C_05_15" - bg_decorator: "C_05_17" + fg_format: "C_14_15" + bg_format: "C_14_20" + fg_icon: "C_14_15" + bg_icon: "C_14_20" + fg_decorator: "C_14_20" + bg_decorator: "C_14_53"