diff --git a/default_palette.txt b/default_palette.txt new file mode 100644 index 0000000..02014be --- /dev/null +++ b/default_palette.txt @@ -0,0 +1,36 @@ +#e0d1e0 +#c8a8c8 +#ae7eae +#965496 +#7d2a7d +#640164 +#ead2e1 +#dfaacb +#d482b5 +#c95aa0 +#bd328a +#b20a74 +#e6ded0 +#d6c5a8 +#c5ac7f +#b49356 +#a47a2d +#936105 +#cddecf +#a6c3aa +#7da784 +#568b5e +#2d6f38 +#065413 +#d1d3dc +#a8adbd +#7d859e +#545e7f +#293760 +#001041 +#d1d3d7 +#a7abb3 +#7d828d +#545a68 +#293143 +#00091e diff --git a/dynamic.violet.yaml b/dynamic.violet.yaml index df10c95..ec4c4c6 100644 --- a/dynamic.violet.yaml +++ b/dynamic.violet.yaml @@ -35,20 +35,22 @@ window: active: window_name: " #W " window_index: " #I" + icon: "" inactive: window_name: " #W " window_index: " #I" + icon: "" status_right: directory: enabled: on tmux_option: " #{b:pane_current_path} " icon: " " decorator: "" - fg_option: "#284b4b" - bg_option: "#aa9784" - fg_icon: "#284b4b" - bg_icon: "#755636" - fg_decorator: "#755636" + fg_option: "#293143" + bg_option: "#c5ac7f" + fg_icon: "#293143" + bg_icon: "#a47a2d" + fg_decorator: "#a47a2d" date: enabled: on diff --git a/dynamic_theme.sh b/dynamic_theme.sh deleted file mode 100755 index 6af39ee..0000000 --- a/dynamic_theme.sh +++ /dev/null @@ -1,73 +0,0 @@ -#!/usr/bin/env bash -_DIR="$(cd "$(dirname "$0")" && pwd)" -export PATH="${_DIR}:${PATH}" - -# 3 groups of colors from light to deep -# the colors are generated by palette.py -PLACE_HOLDERS=( - "PALE_RED" - "LIGHT_RED" - "MIDDLE_RED" - "STRONG_RED" - "DARK_RED" - "DEEP_RED" - "PALE_PURPLE" - "LIGHT_PURPLE" - "MIDDLE_PURPLE" - "STRONG_PURPLE" - "DARK_PURPLE" - "DEEP_PURPLE" - "PALE_ORANGE" - "LIGHT_ORANGE" - "MIDDLE_ORANGE" - "STRONG_ORANGE" - "DARK_ORANGE" - "DEEP_ORANGE" - "PALE_GREEN" - "LIGHT_GREEN" - "MIDDLE_GREEN" - "STRONG_GREEN" - "DARK_GREEN" - "DEEP_GREEN" - "PALE_BLUE" - "LIGHT_BLUE" - "MIDDLE_BLUE" - "STRONG_BLUE" - "DARK_BLUE" - "DEEP_BLUE" - "PALE_GRAY" - "LIGHT_GRAY" - "MIDDLE_GRAY" - "STRONG_GRAY" - "DARK_GRAY" - "DEEP_GRAY" -) - -palette=$(python3 -c "import palette; palette = palette.create_theme_palette(); print(palette)") -tmpfile=$(mktemp) -colors=$(echo $palette | grep -iEo '#[[:alnum:]]{6}' > ${tmpfile}) - -dynamic_theme_name=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 8) -dynamic_theme_name="dynamic" -dynamic_theme_file_name="${dynamic_theme_name}.theme.yaml" -dynamic_config_file_name="${dynamic_theme_name}.violet.yaml" -tmux set-option -gq "@dynamic_theme_name" "${dynamic_theme_name}" -tmux set-option -gq "@dynamic_config_file_name" "${dynamic_config_file_name}" -if [ -e "${dynamic_theme_file_name}" ];then - rm -f "${dynamic_theme_file_name}" -fi -if [ -e "${dynamic_config_file_name}" ];then - rm -f "${dynamic_config_file_name}" -fi -cp "template.theme.yaml" "${dynamic_theme_file_name}" -cp "violet.yaml" "${dynamic_config_file_name}" -# trap "rm -f ${dynamic_theme_file_name}" EXIT INT TERM - -index=1 -while read -r _color;do - sed -i "s/${PLACE_HOLDERS[$index]}/${_color}/g" "${dynamic_theme_file_name}" - sed -i "s/${PLACE_HOLDERS[$index]}/${_color}/g" "${dynamic_config_file_name}" - ((index++)) -done < "${tmpfile}" - -source violet.tmux diff --git a/palette.py b/palette.py index bfde86e..1bdf37b 100644 --- a/palette.py +++ b/palette.py @@ -123,7 +123,7 @@ def generate_random_dark_green(n_colors=1): def generate_palette(n_palette=1): - """ "Convert""" + """Convert""" n_colors = 24 groups = 6 diff --git a/template.theme.yaml b/template.theme.yaml index d6c093e..69a04ed 100644 --- a/template.theme.yaml +++ b/template.theme.yaml @@ -27,11 +27,11 @@ window: active: fg_window: "DARK_GRAY" bg_window: "MIDDLE_GREEN" - fg_window_index: "DARK_GRAY" - bg_window_index: "DARK_GREEN" + fg_window_index: "DEEP_GRAY" + bg_window_index: "STRONG_GREEN" fg_icon: "DARK_GRAY" bg_icon: "DARK_GREEN" - fg_decorator: "DARK_GREEN" + fg_decorator: "STRONG_GREEN" bg_decorator: "DEEP_GRAY" icon: "" decorator: "" @@ -54,7 +54,7 @@ status_right: style: "nobold,nounderscore,noitalics" fg_option: "DARK_GRAY" bg_option: "STRONG_GRAY" - fg_icon: "DEEP_GRAY" + fg_icon: "MIDDLE_GRAY" bg_icon: "DARK_GRAY" fg_decorator: "DARK_GRAY" bg_decorator: "DEEP_GRAY" diff --git a/violet.py b/violet.py index cef6d5e..53137a0 100644 --- a/violet.py +++ b/violet.py @@ -533,7 +533,9 @@ def run_shell_command(command, default_output=None): .decode(UTF_8) .strip() ) - return value + if value is not None and value.strip() != EMPTY: + return value + return default_output except Exception: logger.opt(exception=True).debug( f"{command} is failed to run. use default value: \ diff --git a/violet.theme.yaml b/violet.theme.yaml deleted file mode 100644 index c0724e4..0000000 --- a/violet.theme.yaml +++ /dev/null @@ -1,60 +0,0 @@ ---- -status_line: - foreground: "#d0d0d0" - background: "#303446" - left_icon: "" - right_icon: "" - left_decorator: "" - right_decorator: "" - fg_option: "#c6d0f5" - bg_option: "#414559" - fg_icon: "#303030" - bg_icon: "#cc8400" - fg_decorator: "#454a64" - bg_decorator: "#303446" - style: "nobold,nounderscore,noitalics" -status_left: - fg_option: "#c6d0f5" - bg_option: "#414559" - fg_icon: "#ffff4f" - bg_icon: "#820000" - fg_decorator: "#820000" - bg_decorator: "#303446" - icon: "  " - decorator: "" - style: "nobold,nounderscore,noitalics" -window: - active: - fg_window: "#2a432a" - bg_window: "#84b384" - fg_window_index: "#2a432a" - bg_window_index: "#418100" - fg_icon: "#2a432a" - bg_icon: "#418100" - fg_decorator: "#418100" - bg_decorator: "#303446" - icon: "" - decorator: "" - style: "nobold,nounderscore,noitalics" - inactive: - fg_window: "#2a432a" - bg_window: "#646b91" - fg_window_index: "#646b91" - bg_window_index: "#454a64" - fg_icon: "" - bg_icon: "" - fg_decorator: "#454a64" - bg_decorator: "#303446" - icon: "" - decorator: "" - style: "nobold,nounderscore,noitalics" -status_right: - icon: "" - decorator: "" - style: "nobold,nounderscore,noitalics" - fg_option: "#2a432a" - bg_option: "#71789d" - fg_icon: "#303030" - bg_icon: "#cc8400" - fg_decorator: "#454a64" - bg_decorator: "#303446" diff --git a/violet.tmux b/violet.tmux index 5ea7b5e..e4883ed 100755 --- a/violet.tmux +++ b/violet.tmux @@ -1,16 +1,114 @@ #!/usr/bin/env bash _DIR="$(cd "$(dirname "$0")" && pwd)" +source "${_DIR}/utils.sh" + +TMUX_COMMANDS_FILENAME="tmux_commands.txt" +DEFAULT_PALETTE_FILENAME="default_palette.txt" +DYNAMIC_PALETTE_FILENAME="dynamic_palette.txt" +TEMPLATE_THEME_FILENAME="template.theme.yaml" +DEFAULT_CONFIG_FILENAME="violet.yaml" +DYNAMIC_THEME_NAME="dynamic" +PALETTE_FILENAME="${DEFAULT_PALETTE_FILENAME}" + +PLACE_HOLDERS=( + "PALE_RED" + "LIGHT_RED" + "MIDDLE_RED" + "STRONG_RED" + "DARK_RED" + "DEEP_RED" + "PALE_PURPLE" + "LIGHT_PURPLE" + "MIDDLE_PURPLE" + "STRONG_PURPLE" + "DARK_PURPLE" + "DEEP_PURPLE" + "PALE_ORANGE" + "LIGHT_ORANGE" + "MIDDLE_ORANGE" + "STRONG_ORANGE" + "DARK_ORANGE" + "DEEP_ORANGE" + "PALE_GREEN" + "LIGHT_GREEN" + "MIDDLE_GREEN" + "STRONG_GREEN" + "DARK_GREEN" + "DEEP_GREEN" + "PALE_BLUE" + "LIGHT_BLUE" + "MIDDLE_BLUE" + "STRONG_BLUE" + "DARK_BLUE" + "DEEP_BLUE" + "PALE_GRAY" + "LIGHT_GRAY" + "MIDDLE_GRAY" + "STRONG_GRAY" + "DARK_GRAY" + "DEEP_GRAY" +) +generate_palette_colors(){ + palette=$(python3 -c "import palette; palette = palette.create_theme_palette(); print(palette)") + echo $palette | grep -iEo '#[[:alnum:]]{6}' > "${DYNAMIC_PALETTE_FILENAME}" +} + +create_dynamic_theme_file(){ + dynamic_theme_file_name="${DYNAMIC_THEME_NAME}.theme.yaml" + tmux set-option -gq "@dynamic_theme_name" "${DYNAMIC_THEME_NAME}" + if [ -e "${dynamic_theme_file_name}" ];then + rm -f "${dynamic_theme_file_name}" + fi + cp "${TEMPLATE_THEME_FILENAME}" "${dynamic_theme_file_name}" + index=0 + while read -r _color;do + sed -i "s/${PLACE_HOLDERS[$index]}/${_color}/g" "${dynamic_theme_file_name}" + ((index++)) + done < "${PALETTE_FILENAME}" +} + +create_dynamic_config_file(){ + dynamic_config_file_name="${DYNAMIC_THEME_NAME}.violet.yaml" + tmux set-option -gq "@dynamic_config_file_name" "${dynamic_config_file_name}" + if [ -e "${dynamic_config_file_name}" ];then + rm -f "${dynamic_config_file_name}" + fi + cp "violet.yaml" "${dynamic_config_file_name}" + index=0 + while read -r _color;do + sed -i "s/${PLACE_HOLDERS[$index]}/${_color}/g" "${dynamic_config_file_name}" + ((index++)) + done < "${PALETTE_FILENAME}" +} + main(){ export PATH="${_DIR}:${PATH}" export PYTHONPATH="${_DIR}:${PATH}" find ${_DIR} -name "*.sh" -exec chmod u+x '{}' \; + tmux bind-key C-g "run -b 'violet.tmux -d'" tmux set-environment -g 'PATH' "${_DIR}:${PATH}" tmux set-environment -g 'PYTHONPATH' "${_DIR}:${PATH}" tmux bind-key g "run 'python -c \"import palette; palettes = palette.generate_palette(); print(palettes)\"'" tmux_commands="$(python3 -c "import violet; tmux_commands = violet.violet(); print(tmux_commands)")" - tmp_conf=$(mktemp) - echo "${tmux_commands}" | sed -e 's/True/on/g' | sed -e 's/False/off/g' | tr ';' '\n' > "${tmp_conf}" - tmux source "${tmp_conf}" + echo "${tmux_commands}" | sed -e 's/True/on/g' | sed -e 's/False/off/g' | tr ';' '\n' > "${TMUX_COMMANDS_FILENAME}" + tmux source "${TMUX_COMMANDS_FILENAME}" } +CREATE_DYNMIC_THEME=${FALSE} + +while getopts "d" opt; do + case $opt in + d) CREATE_DYNMIC_THEME=${TRUE};; + esac +done + +set -x +if [ $CREATE_DYNMIC_THEME -eq $TRUE ];then + PALETTE_FILENAME=${DYNAMIC_PALETTE_FILENAME} + generate_palette_colors +fi +create_dynamic_theme_file +create_dynamic_config_file + main +set +x diff --git a/violet.yaml b/violet.yaml index 44d43f2..93151f5 100644 --- a/violet.yaml +++ b/violet.yaml @@ -35,9 +35,11 @@ window: active: window_name: " #W " window_index: " #I" + icon: "" inactive: window_name: " #W " window_index: " #I" + icon: "" status_right: directory: enabled: on