fix many stuff, apply uniform color handling ith right click

This commit is contained in:
koksnuss
2018-08-14 00:48:07 +02:00
parent 0b39bbeb46
commit 65d6bb9773
7 changed files with 66 additions and 50 deletions

View File

@ -1,7 +1,7 @@
# click interactions
[[ "$BLOCK_INSTANCE" =~ "color" ]] && COLORS=True
## toggle long and short preview
STATE="${HOME}/.config/i3blocks/modules/${1}.state"
STATE="${HOME}/.config/i3blocks/modules/${1}-${BLOCK_INSTANCE}.long"
COLORS="${HOME}/.config/i3blocks/modules/${1}-${BLOCK_INSTANCE}.color"
if [[ "$BLOCK_BUTTON" == 1 ]]; then
if [[ -f "$STATE" ]]; then
rm $STATE
@ -14,6 +14,18 @@ else
[[ -f "$STATE" ]] && LONG=true || LONG=false
fi
## toggle color and black/white mode
if [[ "$BLOCK_BUTTON" == 3 ]]; then
if [[ -f "$COLORS" ]]; then
rm $COLORS
COLORS=false
else
touch $COLORS
COLORS=true
fi
else
[[ -f "$COLORS" ]] && COLORS=true || COLORS=false
fi
# global variables
BAR=("▁" "▂" "▃" "▄" "▅" "▆" "▇" "█")
@ -24,7 +36,6 @@ BW=("#565656" "#6d6d6d" "#848485" "#9c9c9c" "#b1b1b1" "#c7c7c7" "#dcdcdc" "#f5f5
# get $LOAD, $LONG_TEXT and $SHORT_TEXT
source $HOME/.config/i3blocks/modules/${1}.sh
# text
if [[ "$LOAD" = false && "$LONG" = false ]]; then
echo $SHORT_TEXT
@ -45,6 +56,6 @@ fi
# colors
for i in "${!BW[@]}"; do
if [[ $LOAD -lt $((($i+1) * $INTERVAL)) ]]; then
[[ $COLORS ]] && echo "${COLOR[$i]}" || echo "${BW[$i]}"
[[ "$COLORS" = true ]] && echo "${COLOR[$i]}" || echo "${BW[$i]}"
fi
done

View File

@ -14,7 +14,7 @@ if [[ $(amixer get $DEV) =~ \[([0-9]+)\%\][[:space:]]\[(on|off)\] ]]; then
LOAD=false
fi
else
LONG_TEXT="no audio source"
LONG_TEXT="Audio source not found"
SHORT_TEXT="n/a"
LOAD=false
fi

0
modules/backlight-.color Normal file
View File

View File

@ -1,26 +1,16 @@
[[ "$BLOCK_BUTTON" == 2 ]] && i3-sensible-terminal -e htop
[[ $BLOCK_INSTANCE =~ (phys|swap) ]] && TYPE=${BASH_REMATCH[1]}
MEMINFO=$(cat /proc/meminfo)
if [[ $MEMINFO =~ MemTotal:[[:space:]]+([0-9]+) ]]; then
PHYS_TOTAL=${BASH_REMATCH[1]}
PHYS_TOTAL=$((${PHYS_TOTAL} / 1024**2))
fi
[[ $MEMINFO =~ MemTotal:[[:space:]]+([0-9]+) ]] && PHYS_TOTAL=$((${BASH_REMATCH[1]} / 1024**2))
if [[ $MEMINFO =~ MemAvailable:[[:space:]]+([0-9]+) ]]; then
PHYS_AVAILABLE=${BASH_REMATCH[1]}
PHYS_AVAILABLE=$((${PHYS_AVAILABLE} / 1024**2))
PHYS_AVAILABLE_M=$((${PHYS_AVAILABLE} / 1024))
fi
if [[ $MEMINFO =~ SwapTotal:[[:space:]]+([0-9]+) ]]; then
SWAP_TOTAL=${BASH_REMATCH[1]}
SWAP_TOTAL=$((${SWAP_TOTAL} / 1024**2))
[[ ${BASH_REMATCH[1]} -gt 2000000 ]] && PHYS_AVAILABLE=$((${BASH_REMATCH[1]} / 1024**2)) || PHYS_AVAILABLE=$((${BASH_REMATCH[1]} / 1024))
fi
[[ $MEMINFO =~ SwapTotal:[[:space:]]+([0-9]+) ]] && SWAP_TOTAL=$((${BASH_REMATCH[1]} / 1024**2))
if [[ $MEMINFO =~ SwapFree:[[:space:]]+([0-9]+) ]]; then
SWAP_AVAILABLE=${BASH_REMATCH[1]}
SWAP_AVAILABLE=$((${SWAP_AVAILABLE} / 1024**2))
SWAP_AVAILABLE_M=$((${SWAP_AVAILABLE} / 1024))
[[ ${BASH_REMATCH[1]} -gt 2000000 ]] && SWAP_AVAILABLE=$((${BASH_REMATCH[1]} / 1024**2)) || SWAP_AVAILABLE=$((${BASH_REMATCH[1]} / 1024))
fi
[[ ! $PHYS_AVAILABLE || ! $PHYS_TOTAL || ! $SWAP_AVAILABLE || ! $SWAP_TOTAL ]] && printf "Ram not found\nn/a\n" && exit 33
if [[ "$TYPE" == "" ]]; then
MEM_FREE=$((${PHYS_AVAILABLE} + ${SWAP_AVAILABLE}))
@ -29,13 +19,28 @@ if [[ "$TYPE" == "" ]]; then
LONG_TEXT="${PHYS_AVAILABLE}+${SWAP_AVAILABLE}G"
SHORT_TEXT="${PHYS_AVAILABLE}+${SWAP_AVAILABLE}G"
else
LONG_TEXT="${PHYS_AVAILABLE_M}+${SWAP_AVAILABLE}M"
SHORT_TEXT="${PHYS_AVAILABLE_M}+${SWAP_AVAILABLE}M"
LONG_TEXT="${PHYS_AVAILABLE}+${SWAP_AVAILABLE}M"
SHORT_TEXT="${PHYS_AVAILABLE}+${SWAP_AVAILABLE}M"
fi
elif [[ "$TYPE" == "ram" ]]; then
elif [[ "$TYPE" == "phys" ]]; then
MEM_FREE=${PHYS_AVAILABLE}
MEM_TOTAL=${PHYS_TOTAL}
if [[ "$MEM_FREE" -gt 2 ]]; then
LONG_TEXT="${PHYS_AVAILABLE}G"
SHORT_TEXT="${PHYS_AVAILABLE}G"
else
LONG_TEXT="${PHYS_AVAILABLE}M"
SHORT_TEXT="${PHYS_AVAILABLE}M"
fi
elif [[ "$TYPE" == "swap" ]]; then
MEM_FREE=${SWAP_AVAILABLE}
MEM_TOTAL=${SWAP_TOTAL}
if [[ "$MEM_FREE" -gt 2 ]]; then
LONG_TEXT="${SWAP_AVAILABLE}G"
SHORT_TEXT="${SWAP_AVAILABLE}G"
else
LONG_TEXT="${SWAP_AVAILABLE}M"
SHORT_TEXT="${SWAP_AVAILABLE}M"
fi
fi
LOAD=$(((${MEM_TOTAL} - ${MEM_FREE}) * 100 / ${MEM_TOTAL}))