Skip to content

Commit

Permalink
Merge pull request #23 from wenijinew/3aaeffe
Browse files Browse the repository at this point in the history
code refactoring for config and theme loading
  • Loading branch information
wenijinew authored Sep 4, 2023
2 parents 2df8947 + 96a06cf commit da1b324
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 147 deletions.
36 changes: 36 additions & 0 deletions default_palette.txt
Original file line number Diff line number Diff line change
@@ -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
12 changes: 7 additions & 5 deletions dynamic.violet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
73 changes: 0 additions & 73 deletions dynamic_theme.sh

This file was deleted.

2 changes: 1 addition & 1 deletion palette.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions template.theme.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ""
Expand All @@ -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"
4 changes: 3 additions & 1 deletion violet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: \
Expand Down
60 changes: 0 additions & 60 deletions violet.theme.yaml

This file was deleted.

104 changes: 101 additions & 3 deletions violet.tmux
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions violet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit da1b324

Please sign in to comment.