Skip to content

Commit

Permalink
converted theme system to json
Browse files Browse the repository at this point in the history
  • Loading branch information
napalm255 committed Dec 14, 2014
1 parent 06f62b4 commit 008db16
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 64 deletions.
46 changes: 34 additions & 12 deletions powertmux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,37 @@ __powertmux_dir_home() {
}

__powertmux_settings() {
[ -z "$POWERTMUX_THEME" ] && export POWERTMUX_THEME="${POWERTMUX_THEME_DEFAULT}"

eval POWERTMUX_DIR_USER_PLUGINS="$POWERTMUX_DIR_USER_PLUGINS"
eval POWERTMUX_DIR_USER_THEMES="$POWERTMUX_DIR_USER_THEMES"
if [ -n "$POWERTMUX_DIR_USER_THEMES" ] && [ -f "${POWERTMUX_DIR_USER_THEMES}/${POWERTMUX_THEME}.sh" ]; then
source "${POWERTMUX_DIR_USER_THEMES}/${POWERTMUX_THEME}.sh"
else
source "${POWERTMUX_DIR_THEMES}/${POWERTMUX_THEME}.sh"
fi
[ -z "$POWERTMUX_THEME" ] && export POWERTMUX_THEME="default"

# read json using lib/jq
local jq=${POWERTMUX_DIR_LIB}/jq
local js=${POWERTMUX_DIR_THEMES}/${POWERTMUX_THEME}.json
local old=${POWERTMUX_DIR_THEMES}/${POWERTMUX_THEME}.sh

tmux set-env "POWERTMUX_STATUS_LEFT" "$($jq ".left.display" $js)"
tmux set-env "POWERTMUX_STATUS_RIGHT" "$($jq ".right.display" $js)"
POWERTMUX_SEPARATOR_LEFT_BOLD=$($jq ".left.separators.bold" $js)
POWERTMUX_SEPARATOR_LEFT_THIN=$($jq ".left.separators.thin" $js)
POWERTMUX_SEPARATOR_RIGHT_BOLD=$($jq ".right.separators.bold" $js)
POWERTMUX_SEPARATOR_RIGHT_THIN=$($jq ".left.separators.thin" $js)
POWERTMUX_DEFAULT_BACKGROUND_COLOR=$($jq ".defaults.colors.background" $js)
POWERTMUX_DEFAULT_FOREGROUND_COLOR=$($jq ".defaults.colors.foreground" $js)
POWERTMUX_DEFAULT_LEFTSIDE_SEPARATOR=$($jq ".defaults.separators.left" $js | tr '[:lower:]' '[:upper:]' | sed -e 's/\"//g')
POWERTMUX_DEFAULT_RIGHTSIDE_SEPARATOR=$($jq ".defaults.separators.right" $js | tr '[:lower:]' '[:upper:]' | sed -e 's/\"//g')
POWERTMUX_DEFAULT_LEFTSIDE_SEPARATOR=$(eval "echo \$$(echo POWERTMUX_SEPARATOR_$(echo ${POWERTMUX_DEFAULT_LEFTSIDE_SEPARATOR}))")
POWERTMUX_DEFAULT_RIGHTSIDE_SEPARATOR=$(eval "echo \$$(echo POWERTMUX_SEPARATOR_$(echo ${POWERTMUX_DEFAULT_RIGHTSIDE_SEPARATOR}))")

PLUGINS=($($jq ".left.plugins[]" $js | sed -e 's/\ /,/g' ))
for ((i = 0; i < ${#PLUGINS[@]}; i++))
do
POWERTMUX_LEFT_STATUS_PLUGINS[${i}]=$(echo "${PLUGINS[$i]}" | sed -e 's/,/ /g' -e 's/\"//g')
done
PLUGINS=($($jq ".right.plugins[]" $js | sed -e 's/\ /,/g' ))
for ((i = 0; i < ${#PLUGINS[@]}; i++))
do
POWERTMUX_RIGHT_STATUS_PLUGINS[${i}]=$(echo "${PLUGINS[$i]}" | sed -e 's/,/ /g' -e 's/\"//g')
done

}

__powertmux_print() {
Expand Down Expand Up @@ -264,15 +286,15 @@ roll_text() {
echo "${text}"
}

# clear all variables
unset $(env | grep POWERTMUX | sed -e 's/=.*//g')

# configure variables
export POWERTMUX_DIR_HOME="$(__powertmux_dir_home)"
export POWERTMUX_DIR_LIB="${POWERTMUX_DIR_HOME}/lib"
export POWERTMUX_DIR_THEMES="${POWERTMUX_DIR_HOME}/themes"
export POWERTMUX_DIR_PLUGINS="${POWERTMUX_DIR_HOME}/plugins"
export POWERTMUX_DIR_TEMPORARY="/tmp/powertmux_${USER}"
export POWERTMUX_THEME_DEFAULT="default"
export POWERTMUX_STATUS_LEFT="on"
export POWERTMUX_STATUS_RIGHT="on"

[ ! -d "$POWERTMUX_DIR_TEMPORARY" ] && mkdir "$POWERTMUX_DIR_TEMPORARY"

Expand Down
48 changes: 26 additions & 22 deletions themes/default.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,38 @@
{
"default colors": {
"background": "236",
"foreground": "255"
"defaults": {
"colors": {
"background": "236",
"foreground": "255"
},
"separators": {
"left": "right_bold",
"right": "left_bold"
}
},
"left": {
"display": "on",
"display": "off",
"separators": {
"left-bold": "",
"left-thin": "",
"left-side": "right-bold"
"bold": "",
"thin": "",
"test": "\u00BB"
},
"plugins": {
"lan_ip": "239 255",
"wan_ip": "239 255 left-thin",
"battery": "137 127",
"datetime": "252 0"
}
"plugins": [
"tmux_session_info 252 0",
"hostname 239 255"
]
},
"right": {
"display": "on",
"separators": {
"right-bold": "",
"right-thin": "",
"left-side": "left-bold"
"bold": "",
"thin": "",
"test": "\u00BB"
},
"plugins": {
"lan_ip": "239 255",
"wan_ip": "239 255 left-thin",
"battery": "137 127",
"datetime": "252 0"
}
"plugins": [
"lan_ip 239 255",
"wan_ip 239 255 left_thin",
"battery 137 127",
"datetime 252 0"
]
}
}
30 changes: 0 additions & 30 deletions themes/default.sh

This file was deleted.

0 comments on commit 008db16

Please sign in to comment.