mirror of https://gitlab.com/ceda_ei/wish
Compare commits
No commits in common. "4bed328fa24884bb19b8e7948bd545bf60d93a27" and "d9e86e4421339bcf77456d5b1f2f26692ba015fe" have entirely different histories.
4bed328fa2
...
d9e86e4421
|
@ -16,17 +16,12 @@ function wish_battery_set_colors() {
|
||||||
|
|
||||||
function wish_battery_main() {
|
function wish_battery_main() {
|
||||||
local path=/sys/class/power_supply/$WISH_BATTERY_ID
|
local path=/sys/class/power_supply/$WISH_BATTERY_ID
|
||||||
local battery
|
local battery=$(($(cat $path/charge_now) * 100 / $(cat $path/charge_full)))%
|
||||||
if [[ -f $path/charge_now ]]; then
|
if [[ $(cat $path/status) == "Charging" ]] ||
|
||||||
battery=$(($(cat $path/charge_now) * 100 / $(cat $path/charge_full)))%
|
[[ $(cat $path/status) == "Full" ]]; then
|
||||||
if [[ $(cat $path/status) == "Charging" ]] ||
|
battery="$WISH_BATTERY_CHARGING $battery"
|
||||||
[[ $(cat $path/status) == "Full" ]]; then
|
|
||||||
battery="$WISH_BATTERY_CHARGING $battery"
|
|
||||||
else
|
|
||||||
battery="$WISH_BATTERY_DISCHARGING $battery"
|
|
||||||
fi
|
|
||||||
else
|
else
|
||||||
battery="$WISH_BATTERY_ID not found"
|
battery="$WISH_BATTERY_DISCHARGING $battery"
|
||||||
fi
|
fi
|
||||||
wish_append $WISH_BATTERY_BG $WISH_BATTERY_FG " $battery "
|
wish_append $WISH_BATTERY_BG $WISH_BATTERY_FG " $battery "
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,8 @@ local fg_gradient=(16 16 16 16 16 15 15)
|
||||||
local j=0
|
local j=0
|
||||||
for i in ${WISH_PLUGINS[@]}; do
|
for i in ${WISH_PLUGINS[@]}; do
|
||||||
[[ $i == "newline" ]] && j=0 && continue
|
[[ $i == "newline" ]] && j=0 && continue
|
||||||
eval WISH_${i^^}_BG=${gradient[$j]}
|
eval WISH_$(echo $i | tr '[:lower:]' '[:upper:]')_BG=${gradient[$j]}
|
||||||
eval WISH_${i^^}_FG=${fg_gradient[$j]}
|
eval WISH_$(echo $i | tr '[:lower:]' '[:upper:]')_FG=${fg_gradient[$j]}
|
||||||
((j++))
|
((j++))
|
||||||
if [[ $j -eq ${#gradient[@]} ]]; then
|
if [[ $j -eq ${#gradient[@]} ]]; then
|
||||||
j=0
|
j=0
|
||||||
|
|
|
@ -6,8 +6,8 @@ local gradient=(e7c547 c0e551 82e35a 62e177 6bdfb3 73d4dd 7aa6da)
|
||||||
local j=0
|
local j=0
|
||||||
for i in ${WISH_PLUGINS[@]}; do
|
for i in ${WISH_PLUGINS[@]}; do
|
||||||
[[ $i == "newline" ]] && j=0 && continue
|
[[ $i == "newline" ]] && j=0 && continue
|
||||||
eval WISH_${i^^}_BG=-1
|
eval WISH_$(echo $i | tr '[:lower:]' '[:upper:]')_BG=-1
|
||||||
eval WISH_${i^^}_FG=${gradient[$j]}
|
eval WISH_$(echo $i | tr '[:lower:]' '[:upper:]')_FG=${gradient[$j]}
|
||||||
((j++))
|
((j++))
|
||||||
if [[ $j -eq ${#gradient[@]} ]]; then
|
if [[ $j -eq ${#gradient[@]} ]]; then
|
||||||
j=0
|
j=0
|
||||||
|
|
|
@ -2,6 +2,6 @@ WISH_DEFAULT_BG=-1
|
||||||
WISH_DEFAULT_FG=-1
|
WISH_DEFAULT_FG=-1
|
||||||
WISH_POWERLINE=0
|
WISH_POWERLINE=0
|
||||||
for i in ${WISH_PLUGINS[@]}; do
|
for i in ${WISH_PLUGINS[@]}; do
|
||||||
eval WISH_${i^^}_BG=-1
|
eval WISH_$(echo $i | tr '[:lower:]' '[:upper:]')_BG=-1
|
||||||
eval WISH_${i^^}_FG=-1
|
eval WISH_$(echo $i | tr '[:lower:]' '[:upper:]')_FG=-1
|
||||||
done
|
done
|
||||||
|
|
|
@ -6,8 +6,8 @@ local fg_gradient=(000000 000000 000000 000000 000000 ffffff ffffff)
|
||||||
local j=0
|
local j=0
|
||||||
for i in ${WISH_PLUGINS[@]}; do
|
for i in ${WISH_PLUGINS[@]}; do
|
||||||
[[ $i == "newline" ]] && j=0 && continue
|
[[ $i == "newline" ]] && j=0 && continue
|
||||||
eval WISH_${i^^}_BG=${gradient[$j]}
|
eval WISH_$(echo $i | tr '[:lower:]' '[:upper:]')_BG=${gradient[$j]}
|
||||||
eval WISH_${i^^}_FG=${fg_gradient[$j]}
|
eval WISH_$(echo $i | tr '[:lower:]' '[:upper:]')_FG=${fg_gradient[$j]}
|
||||||
((j++))
|
((j++))
|
||||||
if [[ $j -eq ${#gradient[@]} ]]; then
|
if [[ $j -eq ${#gradient[@]} ]]; then
|
||||||
j=0
|
j=0
|
||||||
|
|
105
wish.sh
105
wish.sh
|
@ -2,78 +2,60 @@
|
||||||
|
|
||||||
function wish_init() {
|
function wish_init() {
|
||||||
# Source all plugins
|
# Source all plugins
|
||||||
local plugin
|
local i
|
||||||
local path
|
local j
|
||||||
for plugin in ${WISH_PLUGINS[@]}; do
|
for i in ${WISH_PLUGINS[@]}; do
|
||||||
for path in "$XDG_CONFIG_HOME" "/usr/share" "$HOME/.config"; do
|
for j in "$XDG_CONFIG_HOME" "/usr/share" "$HOME/.config"; do
|
||||||
source "$path/wish/plugins/$plugin.sh" &> /dev/null && break
|
source "$j/wish/plugins/$i.sh" &> /dev/null && break
|
||||||
done
|
done
|
||||||
[[ $? -ne 0 ]] && echo "Plugin $i not found." >&2
|
[[ $? -ne 0 ]] && echo "Plugin $i not found." >&2
|
||||||
done
|
done
|
||||||
|
|
||||||
# Source theme
|
# Source theme
|
||||||
WISH_THEME=${WISH_THEME:-plain}
|
WISH_THEME=${WISH_THEME:-plain}
|
||||||
while :; do
|
for i in "$XDG_CONFIG_HOME" "/usr/share" "$HOME/.config"; do
|
||||||
for theme in "$XDG_CONFIG_HOME" "/usr/share" "$HOME/.config"; do
|
source "$i/wish/themes/$WISH_THEME.sh" &> /dev/null && break
|
||||||
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
|
|
||||||
done
|
done
|
||||||
|
|
||||||
|
[[ $? -ne 0 ]] && echo "Theme $WISH_THEME not found." >&2
|
||||||
|
|
||||||
# Call plugins to set colors
|
# Call plugins to set colors
|
||||||
for plugin in ${WISH_PLUGINS[@]}; do
|
for i in ${WISH_PLUGINS[@]}; do
|
||||||
eval wish_$(echo $plugin)_set_colors $prev
|
eval wish_$(echo $i)_set_colors $prev
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
# Usage: color_to_escape_code [3|4] color
|
|
||||||
#
|
|
||||||
# Parameters:
|
|
||||||
# - [3|4]: Use 3 if escape code is for foreground, 4 for background
|
|
||||||
# - color: -1 to reset, 0-255 for terminal color codes. 6 digit hexadecimal
|
|
||||||
# value for true color.
|
|
||||||
#
|
|
||||||
# Return value: Prints escape code that sets the fg/bg as requested.
|
|
||||||
function color_to_escape_code() {
|
|
||||||
local choice=$1
|
|
||||||
local color=$2
|
|
||||||
if [[ $color == -1 ]]; then
|
|
||||||
echo "\[\033[0;5;0m\]"
|
|
||||||
else
|
|
||||||
if [[ ${#fg_code} -eq 6 ]]; then
|
|
||||||
local r=$(( 16#${color:0:2} ))
|
|
||||||
local g=$(( 16#${color:2:2} ))
|
|
||||||
local b=$(( 16#${color:4:2} ))
|
|
||||||
echo "\[\033[${choice}8;2;$r;$g;${b}m\]"
|
|
||||||
else
|
|
||||||
echo "\[\033[${choice}8;5;${fg_code}m\]"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
# Usage: wish_append bg fg text
|
# Usage: wish_append bg fg text
|
||||||
#
|
|
||||||
# Parameters:
|
|
||||||
# - fg, bg: -1 to reset, 0-255 for terminal color codes. 6 digit hexadecimal
|
|
||||||
# value for true color.
|
|
||||||
# - text: Text of the plugin
|
|
||||||
#
|
|
||||||
# Return value: None
|
|
||||||
function wish_append() {
|
function wish_append() {
|
||||||
local bg_code=$1
|
local bg_code=$1
|
||||||
local fg_code=$2
|
local fg_code=$2
|
||||||
local text=$3
|
local text=$3
|
||||||
local fg=$(color_to_escape_code 3 $fg_code)
|
if [[ $fg_code == -1 ]]; then
|
||||||
local bg=$(color_to_escape_code 4 $bg_code)
|
local fg="\[\033[0;5;0m\]"
|
||||||
|
else
|
||||||
|
if [[ ${#fg_code} -eq 6 ]]; then
|
||||||
|
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]} ))
|
||||||
|
local fg="\[\033[38;2;$r;$g;${b}m\]"
|
||||||
|
else
|
||||||
|
local fg="\[\033[38;5;${fg_code}m\]"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
if [[ $bg_code == -1 ]]; then
|
||||||
|
local bg="\[\033[0;5;0m\]"
|
||||||
|
else
|
||||||
|
if [[ ${#bg_code} -eq 6 ]]; then
|
||||||
|
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\]"
|
||||||
|
else
|
||||||
|
local bg="\[\033[48;5;${bg_code}m\]"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ $fg_code == -1 ]]; then
|
if [[ $fg_code == -1 ]]; then
|
||||||
PS1="$PS1$fg${bg}$text"
|
PS1="$PS1$fg${bg}$text"
|
||||||
|
@ -101,14 +83,17 @@ function wish_main() {
|
||||||
if wish_${WISH_PLUGINS[$(($i + 1))]}_start $prev; then
|
if wish_${WISH_PLUGINS[$(($i + 1))]}_start $prev; then
|
||||||
local plugin=${WISH_PLUGINS[$i]}
|
local plugin=${WISH_PLUGINS[$i]}
|
||||||
local next_plugin=${WISH_PLUGINS[$(($i+1))]}
|
local next_plugin=${WISH_PLUGINS[$(($i+1))]}
|
||||||
local fg_name="WISH_${plugin^^}_BG"
|
local fg=$(eval echo \$WISH_$(echo $plugin |
|
||||||
local bg_name="WISH_${next_plugin^^}_BG"
|
tr '[:lower:]' '[:upper:]')_BG)
|
||||||
wish_append ${!bg_name} ${!fg_name}
|
local bg=$(eval echo \$WISH_$(echo $next_plugin |
|
||||||
|
tr '[:lower:]' '[:upper:]')_BG)
|
||||||
|
wish_append $bg $fg
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
local plugin=${WISH_PLUGINS[$i]}
|
local plugin=${WISH_PLUGINS[$i]}
|
||||||
local fg_name="WISH_${plugin^^}_BG"
|
local fg=$(eval echo \$WISH_$(echo $plugin |
|
||||||
wish_append -1 ${!fg_name}
|
tr '[:lower:]' '[:upper:]')_BG)
|
||||||
|
wish_append -1 $fg
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in New Issue