diff --git a/.gitignore b/.gitignore index c359d7f..489c2e2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1 @@ -*.state +*.long diff --git a/README.md b/README.md index f3fd3b4..21b03cf 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,10 @@ This is a simple collection of i3blocks-modules accompagnied by a config file with the aim to display only important information in favor of not spilling lots of numbers into the status bar. # Usage -- *datetime* -- A left click will toggle long and short displays. The short version is displayed in the format `HH:MM`. The long version also shows the day of the week, weeknumber, date and seconds. -- *audio* -- Current audio output level. `instance=mic` will show the microphone input level instead. -- *ram* -- Free ram and swap are shown in the format `a+b G` where `a` is ram and `b` is swap. If you want to show ram and swap seperatly, use `instance=ram` or `instance=swap`. -- *cpu* -- Total idle cpu time of all cores together. Use `instance=long` to show the percentage instead. -- *temp* -- Current temperature of the cpu. -- *battery* -- Total energy left of all batteries. Use `instance=x` to show the status of `BATx` in case you have more than one battery in `/sys/class/powersupply`. -- *backlight* -- Brightness level. Use `instance=long` to show the brightness percentage. Use `instance="color"` to print the brightness level colored which is nice when using a device in battery mode. +Some modules accept an `instance` argument: +-- audio: default instance is audio output. The optional instance `mic` shows microphone information. +-- battery: default instance collects informations from all attached batteries and treats them as one battery. The optional instance `BAT#` can be specified to display results only for battery #. +-- ram: default instance collects information from physical memory and swap. The optional instances `phys` and `swap` only collect information for physical- and swap-memory respectiveley. # Requirements Install [i3 window manager](https://i3wm.org) alongside with [i3blocks](https://github.com/vivien/i3blocks) and `git`. The following shows the requirements for each module: @@ -39,7 +36,6 @@ One-Liner: Open up a terminal and paste: `bash <(curl -s https://will.kein.hk/gi - Make sure you've added `bar { status_command i3blocks }` in your i3-config file (i.e. `~/config/i3/config`). - Finally reload your `i3` window manager. The default shortcut is `mod + SHIFT + r`, you should see a flickering. - # Roadmap ## Modules @@ -59,23 +55,28 @@ One-Liner: Open up a terminal and paste: `bash <(curl -s https://will.kein.hk/gi ## Refractor - [x] centralize color palette and progress bar in abstract.sh - [x] centralize long/short view in abstract.sh -- [ ] make long/short permanent: rewrite config + i3reload? how to make it permanent? -- [ ] the progress bar logic seems to repeat itself again and again, this can be done better +- [x] centralize color/blackwhite view in abstract.sh +- [x] make long/short permanent +- [x] make color/blackwhite permanent +- [x] the progress bar logic seems to repeat itself again and again, this can be done better ## Click interactions -### Long/Short preview: Middle click -- [ ] Toggle long (numbers and units) and short (representative bar) preview +### Long/Short preview: Left click +- [x] Toggle long (numbers and units) and short (representative bar) preview + +### Color/Blackwhite preview: right click +- [x] Toggle color and blackwhite preview ### Open another program: Left click -- [c] audio/mic: open pavucontrol -- [c] ram/cpu/temp: open htop -- [c] storage: open ranger -- [c] ip: middle: open firefox +- [x] audio/mic: pavucontrol +- [x] ram/cpu/temp: htop +- [x] storage: ranger +- [x] ip: firefox - [ ] mount: mount it somewhere (with pmount?) and open ranger ### Other behaviour -- [c] audio/mic: toggle mute +- [c] audio/mic: toggle mute, TODO: conflicte with color toggle - [ ] onn/off behaviour: backlight, ethernet, audio, mic ## Signals diff --git a/config b/config index 9885a0d..2d36f75 100644 --- a/config +++ b/config @@ -9,8 +9,7 @@ interval=5 label=☼ # label=☀,☼,✱,✲,✳,✴,✵,✺ signal=3 -instance=color -# instance=color,bw +# instance=color # [iface] # label=iface @@ -20,11 +19,11 @@ instance=color # label=⛀,⛁,⛂,⛃ # interval=60 -# if you want to display ram and swap seperately, you can assign another [ram] module -# with instance=ram or instance=swap +# if you want to display physical ram and swap seperately, you can assign another [ram] module +# with instance=phys or instance=swap [ram] label=⚟ -instance=ram +# instance=phys # [ram] # instance=swap @@ -61,16 +60,16 @@ interval=60 [audio] label=◍ +# label=♩,♪,♫,♬ signal=1 interval=once -instance=color -# label=♩,♪,♫,♬ +# instance=color # separator_block_width=0 [audio] label=◎ -signal=2 # label=⋓ℹ⋒ⅈ -instance=mic,color +signal=2 +instance=mic interval=once [datetime] diff --git a/modules/abstract.sh b/modules/abstract.sh index b6823a2..04c44f9 100755 --- a/modules/abstract.sh +++ b/modules/abstract.sh @@ -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 diff --git a/modules/audio.sh b/modules/audio.sh index 53bd5c7..38ecb8f 100644 --- a/modules/audio.sh +++ b/modules/audio.sh @@ -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 diff --git a/modules/backlight-.color b/modules/backlight-.color new file mode 100644 index 0000000..e69de29 diff --git a/modules/ram.sh b/modules/ram.sh index c666192..fd01c1a 100644 --- a/modules/ram.sh +++ b/modules/ram.sh @@ -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}))