diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c359d7f --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.state diff --git a/config b/config index ebf0e7b..9885a0d 100644 --- a/config +++ b/config @@ -9,14 +9,14 @@ interval=5 label=☼ # label=☀,☼,✱,✲,✳,✴,✵,✺ signal=3 -instance=long,color -# instance=color,bw,long +instance=color +# instance=color,bw # [iface] # label=iface -[storage] -label=⛁ +# [storage] +# label=⛁ # label=⛀,⛁,⛂,⛃ # interval=60 @@ -24,20 +24,17 @@ label=⛁ # with instance=ram or instance=swap [ram] label=⚟ -# instance=long instance=ram # [ram] # instance=swap [cpu] label=☷ -# instance=long interval=2 [temp] label=ϑ interval=2 -# instance=long [ip] # label=ip diff --git a/modules/abstract.sh b/modules/abstract.sh index de8c8c7..924eeec 100755 --- a/modules/abstract.sh +++ b/modules/abstract.sh @@ -1,6 +1,19 @@ # click interactions [[ "$BLOCK_INSTANCE" =~ "color" ]] && COLORS=True -[[ "$BLOCK_INSTANCE" =~ "long" || "$BLOCK_BUTTON" == 1 ]] && LONG=True +## toggle long and short preview +STATE="${HOME}/.config/i3blocks/modules/${1}.state" +if [[ "$BLOCK_BUTTON" == 1 ]]; then + if [[ -f "$STATE" ]]; then + rm $STATE + LONG=false + else + touch $STATE + LONG=true + fi +else + [[ -f "$STATE" ]] && LONG=true || LONG=false +fi + # global variables BAR=("▁" "▂" "▃" "▄" "▅" "▆" "▇" "█") @@ -11,8 +24,9 @@ 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 [[ "$LONG" || "$LONG_TEXT" == "off" ]]; then +if [[ "$LONG" = true || "$LONG_TEXT" == "off" ]]; then echo "$LONG_TEXT" echo "$SHORT_TEXT" else diff --git a/modules/audio.sh b/modules/audio.sh index ed783c7..af53f43 100644 --- a/modules/audio.sh +++ b/modules/audio.sh @@ -11,7 +11,6 @@ if [[ $(amixer get $DEV) =~ \[([0-9]+)\%\][[:space:]]\[(on|off)\] ]]; then else LONG_TEXT="off" SHORT_TEXT="X" - EXIT=True fi else LONG_TEXT="no audio source" diff --git a/modules/ip.sh b/modules/ip.sh index 357a245..9b817b4 100644 --- a/modules/ip.sh +++ b/modules/ip.sh @@ -1,5 +1,5 @@ # start firefox -[[ "$BLOCK_BUTTON" == 3 ]] && firefox +[[ "$BLOCK_BUTTON" == 2 ]] && firefox # get interface if [[ -n "$BLOCK_INSTANCE" ]]; then diff --git a/modules/storage.sh b/modules/storage.sh index df26c4e..67ad49a 100644 --- a/modules/storage.sh +++ b/modules/storage.sh @@ -1,6 +1,6 @@ [[ "$BLOCK_BUTTON" == 2 ]] && i3-sensible-terminal -e ranger -df | gawk -v BAR="${BAR[*]}" -v BW="${BW[*]}" -v COLORS="$COLORS" -v COLOR="${COLOR[*]}" -v LONG="$LONG" ' +df -l | gawk -v BAR="${BAR[*]}" -v BW="${BW[*]}" -v COLORS="$COLORS" -v COLOR="${COLOR[*]}" -v LONG="$LONG" ' BEGIN { split(BAR, bar, / /) diff --git a/modules/temp.sh b/modules/temp.sh index 8ab208e..a1270e3 100644 --- a/modules/temp.sh +++ b/modules/temp.sh @@ -1,42 +1,11 @@ [[ "$BLOCK_BUTTON" == 2 ]] && i3-sensible-terminal -e htop -sensors *-isa-* | awk -v BAR="${BAR[*]}" -v BW="${BW[*]}" -v COLORS="$COLORS" -v COLOR="${COLOR[*]}" -v LONG="$LONG" ' - - BEGIN { - split(BAR, bar, / /) - split(COLOR, color, / /) - split(BW, bw, / /) - interval = 100 / length(bar) - } - - match($0, /^Package[^\+]*\+([0-9]{1,3})[^\+]*\+([0-9]{1,3})/, matches) { - temp = matches[1] - high = matches[2] - step = high / 8 - treshold = 40 - load = (temp - treshold) / (high - treshold) * 100 - } - - END { - if (LONG) { - printf("%d°C\n%d°C\n", temp, temp) - } else { - for (i in bar) { - if (load <= i * interval) { - printf("%s\n%s\n", bar[i], bar[i]) - break - } - } - } - for (i in bw) { - if (load <= i * interval) { - if (COLORS) { - printf("%s\n", color[i]) - } else { - printf("%s\n", bw[i]) - } - break - } - } - } -' +SENSORS=$(sensors *-isa-*) +if [[ $SENSORS =~ Package[^\+]*\+([0-9]{1,3})[^\+]*\+([0-9]{1,3}) ]]; then + TEMP="${BASH_REMATCH[1]}" + HIGH="${BASH_REMATCH[2]}" + TRESHOLD=40 + LOAD=$((($TEMP - $TRESHOLD) * 100 / ($HIGH - $TRESHOLD))) + LONG_TEXT="$(($LOAD + $TRESHOLD))°C" + SHORT_TEXT="$((${LOAD} + ${TRESHOLD}))" +fi