2019-02-15 15:02:32 +01:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2019-02-15 15:27:48 +01:00
|
|
|
function wish_init() {
|
|
|
|
# Source all plugins
|
2019-09-06 15:51:53 +02:00
|
|
|
local plugin
|
|
|
|
local path
|
|
|
|
for plugin in ${WISH_PLUGINS[@]}; do
|
|
|
|
for path in "$XDG_CONFIG_HOME" "/usr/share" "$HOME/.config"; do
|
|
|
|
source "$path/wish/plugins/$plugin.sh" &> /dev/null && break
|
2019-02-15 15:27:48 +01:00
|
|
|
done
|
|
|
|
[[ $? -ne 0 ]] && echo "Plugin $i not found." >&2
|
2019-02-15 15:02:32 +01:00
|
|
|
done
|
|
|
|
|
2019-02-15 15:27:48 +01:00
|
|
|
# Source theme
|
|
|
|
WISH_THEME=${WISH_THEME:-plain}
|
2019-09-06 15:51:53 +02:00
|
|
|
while :; do
|
|
|
|
for theme in "$XDG_CONFIG_HOME" "/usr/share" "$HOME/.config"; do
|
|
|
|
source "$theme/wish/themes/$WISH_THEME.sh" &> /dev/null && break
|
|
|
|
done
|
|
|
|
if [[ $? -eq 0 ]]; then
|
|
|
|
break
|
|
|
|
else
|
|
|
|
echo "Theme $WISH_THEME not found. Using theme plain." >&2
|
|
|
|
if [[ $WISH_THEME == "plain" ]]; then
|
|
|
|
break
|
|
|
|
else
|
|
|
|
WISH_THEME=plain
|
|
|
|
fi
|
|
|
|
fi
|
2019-02-15 15:27:48 +01:00
|
|
|
done
|
|
|
|
|
2019-02-16 07:59:33 +01:00
|
|
|
# Call plugins to set colors
|
2019-09-06 15:51:53 +02:00
|
|
|
for plugin in ${WISH_PLUGINS[@]}; do
|
|
|
|
eval wish_$(echo $plugin)_set_colors $prev
|
2019-02-16 07:59:33 +01:00
|
|
|
done
|
2019-02-15 15:27:48 +01:00
|
|
|
}
|
2019-02-15 15:02:32 +01:00
|
|
|
|
2019-02-16 09:00:42 +01:00
|
|
|
# Usage: wish_append bg fg text
|
|
|
|
function wish_append() {
|
|
|
|
local bg_code=$1
|
|
|
|
local fg_code=$2
|
|
|
|
local text=$3
|
2019-02-16 13:43:11 +01:00
|
|
|
if [[ $fg_code == -1 ]]; then
|
2019-02-16 09:00:42 +01:00
|
|
|
local fg="\[\033[0;5;0m\]"
|
|
|
|
else
|
2019-02-16 13:05:58 +01:00
|
|
|
if [[ ${#fg_code} -eq 6 ]]; then
|
2019-02-16 13:43:11 +01:00
|
|
|
local color=($(echo $fg_code | grep -o .))
|
|
|
|
local r=$(( 16#${color[0]}${color[1]} ))
|
|
|
|
local g=$(( 16#${color[2]}${color[3]} ))
|
|
|
|
local b=$(( 16#${color[4]}${color[5]} ))
|
2019-02-16 13:05:58 +01:00
|
|
|
local fg="\[\033[38;2;$r;$g;${b}m\]"
|
|
|
|
else
|
|
|
|
local fg="\[\033[38;5;${fg_code}m\]"
|
|
|
|
fi
|
2019-02-16 09:00:42 +01:00
|
|
|
fi
|
2019-02-16 13:43:11 +01:00
|
|
|
if [[ $bg_code == -1 ]]; then
|
2019-02-16 09:00:42 +01:00
|
|
|
local bg="\[\033[0;5;0m\]"
|
|
|
|
else
|
2019-02-16 13:05:58 +01:00
|
|
|
if [[ ${#bg_code} -eq 6 ]]; then
|
2019-02-16 13:43:11 +01:00
|
|
|
local color=($(echo $bg_code | grep -o .))
|
|
|
|
local r=$(( 16#${color[0]}${color[1]} ))
|
|
|
|
local g=$(( 16#${color[2]}${color[3]} ))
|
|
|
|
local b=$(( 16#${color[4]}${color[5]} ))
|
|
|
|
local bg="\[\033[48;2;$r;$g;${b}m\]"
|
2019-02-16 13:05:58 +01:00
|
|
|
else
|
|
|
|
local bg="\[\033[48;5;${bg_code}m\]"
|
|
|
|
fi
|
2019-02-16 09:00:42 +01:00
|
|
|
fi
|
2019-02-16 13:43:11 +01:00
|
|
|
|
|
|
|
if [[ $fg_code == -1 ]]; then
|
2019-02-16 09:00:42 +01:00
|
|
|
PS1="$PS1$fg${bg}$text"
|
|
|
|
else
|
|
|
|
PS1="$PS1$bg${fg}$text"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2019-02-15 19:46:17 +01:00
|
|
|
|
|
|
|
function wish_main() {
|
|
|
|
local prev=$?
|
|
|
|
PS1=""
|
|
|
|
local i
|
2019-06-10 13:18:40 +02:00
|
|
|
if [[ $WISH_AUTONEWLINE != 0 ]]; then
|
|
|
|
echo -ne "\033[6n" ; read -s -d ';'; read -s -d R WISH_CURSOR_POSITION
|
|
|
|
if [[ $WISH_CURSOR_POSITION != "1" ]]; then
|
|
|
|
PS1="\n"
|
|
|
|
fi
|
|
|
|
fi
|
2019-02-15 19:46:17 +01:00
|
|
|
for i in $(seq 0 $((${#WISH_PLUGINS[@]} - 1))); do
|
|
|
|
wish_${WISH_PLUGINS[i]}_main $prev
|
2019-02-16 06:34:56 +01:00
|
|
|
if [[ -v WISH_POWERLINE ]] && [[ $WISH_POWERLINE != 0 ]]; then
|
|
|
|
if wish_${WISH_PLUGINS[$i]}_end $prev; then
|
|
|
|
if [[ $i -lt $((${#WISH_PLUGINS[@]} - 1)) ]]; then
|
|
|
|
if wish_${WISH_PLUGINS[$(($i + 1))]}_start $prev; then
|
|
|
|
local plugin=${WISH_PLUGINS[$i]}
|
|
|
|
local next_plugin=${WISH_PLUGINS[$(($i+1))]}
|
2019-09-06 14:35:12 +02:00
|
|
|
local fg_name=$(echo WISH_$(echo $plugin |
|
2019-02-16 06:34:56 +01:00
|
|
|
tr '[:lower:]' '[:upper:]')_BG)
|
2019-09-06 14:35:12 +02:00
|
|
|
local bg_name=$(echo WISH_$(echo $next_plugin |
|
2019-02-16 06:34:56 +01:00
|
|
|
tr '[:lower:]' '[:upper:]')_BG)
|
2019-09-06 14:35:12 +02:00
|
|
|
wish_append ${!bg_name} ${!fg_name}
|
2019-02-16 06:34:56 +01:00
|
|
|
fi
|
|
|
|
else
|
|
|
|
local plugin=${WISH_PLUGINS[$i]}
|
2019-09-06 14:35:12 +02:00
|
|
|
local fg_name=$(echo WISH_$(echo $plugin |
|
2019-02-16 06:34:56 +01:00
|
|
|
tr '[:lower:]' '[:upper:]')_BG)
|
2019-09-06 14:35:12 +02:00
|
|
|
wish_append -1 ${!fg_name}
|
2019-02-16 06:34:56 +01:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ $i -eq $((${#WISH_PLUGINS[@]} - 1)) ]]; then
|
|
|
|
PS1="$PS1\[\033[0;5;0m\]"
|
|
|
|
fi
|
2019-02-15 19:46:17 +01:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2019-02-15 15:27:48 +01:00
|
|
|
wish_init
|
2019-02-15 19:46:17 +01:00
|
|
|
PROMPT_COMMAND="wish_main; $PROMPT_COMMAND"
|