mittags sprint

This commit is contained in:
koksnuss 2018-05-14 14:08:47 +02:00
parent 7b368aba19
commit 2f1e471eb1
9 changed files with 156 additions and 89 deletions

View File

@ -6,12 +6,12 @@ Install [i3 window manager](https://i3wm.org) alongside with [i3blocks](https://
``` ```
module dependency module dependency
-------------------------- --------------------------
audio,mic amixer audio amixer
battery none, searches in /sys/class/power_supply/BAT... battery none, searches in /sys/class/power_supply/BAT...
cpu top cpu top
datetime date datetime date
ip curl ip curl
ram,swap none, searches in /proc/meminfo ram none, searches in /proc/meminfo
storage df storage df
backlight none, searches in /sys/class/backlight, intel and ati/amd supported backlight none, searches in /sys/class/backlight, intel and ati/amd supported
``` ```
@ -21,23 +21,24 @@ backlight none, searches in /sys/class/backlight, intel and ati/amd supported
```bash ```bash
git clone https://will.kein.hk/git/koksnuss/simple-i3blocks.git ~/.config/i3blocks git clone https://will.kein.hk/git/koksnuss/simple-i3blocks.git ~/.config/i3blocks
``` ```
- Adjust `~/.config/i3blocks/config` to control i3 status bar output (see [Usage](#usage)). Finally reload your `i3` window manager. - Adjust `~/.config/i3blocks/config` to control i3 status bar output (see [Usage](#usage)).
- The default shortcut is `mod + SHIFT + r`, you should see a flickering. - Finally reload your `i3` window manager. The default shortcut is `mod + SHIFT + r`, you should see a flickering.
# Usage # Usage
Via the instance id you can choose: - module *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.
- `instance=short` in every module provides even shorter output without units - module *audio*: `instance=mic` will show the microphone level instead. With a left mouse click the device is muted/unmuted.
- `instance=swap` in the module `ram` to show swap usage - module *ram*: by default 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`. If you left click on the block, `top` will be openend.
- `instance=1` in the module `battery` to show the status of BAT1 of you have more than one battery attached to your device. - *cpu*: by default total idle cpu time of all cores together is displayed. If you left click on the block, `top` will be openend.
- module *battery*: by default the total left energy of all attached batteries is shown. If you want to display the batteries seperatly, use `instance=x` will show the status of BATx in case you have more than one battery attached to your device.
# Roadmap # Roadmap
## Modules ## Modules
- [x] datetime - [x] datetime
- [x] ram, swap - [x] ram/swap
- [x] cpu - [x] cpu
- [x] audio, mic - [x] audio/mic
- [x] storage - [x] storage
- [x] ip - [x] ip
- [x] battery - [x] battery
@ -47,8 +48,8 @@ Via the instance id you can choose:
- [ ] ethernet bandwith - [ ] ethernet bandwith
## Click interactions ## Click interactions
- [ ] datetime: left: show date, middle: show date and time, right: show time - [x] datetime: left: show date and seconds
- [ ] audio, mic: toggle mute - [x] audio/mic: left: toggle mute
- [ ] external storage: mount it somewhere - [ ] external storage: mount it somewhere
## Signals ## Signals

31
config
View File

@ -13,39 +13,42 @@ label=
# label=storage # label=storage
label= label=
# if you want to display ram and swap seperately, you can assign another [ram] module
# with instance=ram or instance=swap
[ram] [ram]
# label=ram # label=ram
label= # instance=ram
# [ram]
[ram]
# label=swap # label=swap
label= # instance=swap
instance=swap # separator_block_width=0
[cpu] [cpu]
# label=cpu # label=cpu
label=
[ip] [ip]
# label=ip # label=ip
label= label=
interval=once interval=once
# if you have more than one batteries attached to your device and ou like
# to see the single state of BATx where x is the number of your battery in
# /sys/class/power_supply/BATx you can use the instance=x command
[battery] [battery]
# label=battery # label=battery
label=⚡ # label=⚡
separator_block_width=5 # [battery]
[battery] # instance=1
instance=1 # separator_block_width=0
[audio] [audio]
# label=audio # label=audio
label= label=♪
separator_block_width=5 separator_block_width=0
[audio] [audio]
label= m # label=mic
instance=mic instance=mic
[datetime] [datetime]
label= label=
instance=short # instance=short

View File

@ -1,21 +1,21 @@
#!/bin/bash #!/bin/bash
case ${BLOCK_INSTANCE} in
mic) DEV="Capture";; [[ $BLOCK_INSTANCE == "mic" ]] && DEV="Capture" || DEV="Master"
*) DEV="Master";;
esac [[ $BLOCK_BUTTON == 1 ]] && amixer set $DEV toggle &> /dev/null
[[ ${BLOCK_BUTTON} == 1 ]] && amixer set $DEV toggle &> /dev/null
amixer get $DEV | gawk ' amixer get $DEV | gawk '
match($0, /\[([0-9]+)\%\] \[(on|off)\]/, matches) { match($0, /\[([0-9]+)\%\] \[(on|off)\]/, matches) {
audio=matches[1] audio=matches[1]
} }
END { END {
if (matches[2]=="off") { if (matches[2] == "off") {
print("off \n") print(" off \n")
print("off \n") print("off\n")
exit 33 exit 33
} }
printf("%d% \n", audio) printf("%d% \n", audio)
printf("%d\n", audio) printf("%d%\n", audio)
if (audio < 75) { if (audio < 75) {
print("#04B431\n") print("#04B431\n")
} else if (audio < 80) { } else if (audio < 80) {

View File

@ -1,19 +1,23 @@
#!/bin/bash #!/bin/bash
DIR="/sys/class/backlight/"
if [[ -d "${DIR}acpi_video0" ]]; then DIR="/sys/class/backlight"
DIR="${DIR}acpi_video0"
elif [[ -d "${DIR}intel_backlight" ]]; then if [[ -d "$DIR/acpi_video0" ]]; then
DIR="${DIR}intel_backlight" DIR="$DIR/acpi_video0"
elif [[ -d "$DIR/intel_backlight" ]]; then
DIR="$DIR/intel_backlight"
else else
echo "not found " echo " no backlight "
echo "n/a"
exit 33 exit 33
fi fi
cat "${DIR}/brightness" "${DIR}/max_brightness" | gawk '
NR==1 { cbr=$1 } cat "$DIR/brightness" "$DIR/max_brightness" | gawk '
NR==2 { mbr=$1 } NR==1 { cbr = $1 }
NR==2 { mbr = $1 }
END { END {
printf("%d%\n", cbr/mbr*100) printf("%d%\n", cbr / mbr * 100)
printf("%d\n", cbr/mbr*100) printf("%d\n", cbr / mbr * 100)
print("\n") print("\n")
} }
' '

View File

@ -1,31 +1,47 @@
#!/bin/bash #!/bin/bash
[[ ${BLOCK_INSTANCE} == '' ]] && BAT=0 || BAT=${BLOCK_INSTANCE} DIR="/sys/class/power_supply"
DIR="/sys/class/power_supply/BAT"
if [ ! -f "${DIR}${BAT}/uevent" ]; then if [[ "$BLOCK_INSTANCE" == "" ]]; then
echo " not found " for BAT in $DIR/BAT*/; do
[[ -f "${BAT}uevent" ]] && BATS+="$BAT/uevent "
done
else
[[ -f "$DIR/BAT$BLOCK_INSTANCE/uevent" ]] && BATS="$DIR/BAT$BLOCK_INSTANCE/uevent"
fi
if [[ "${BATS}" == "" ]]; then
echo " no battery "
echo "n/a" echo "n/a"
exit 33 exit 33
fi fi
cat /sys/class/power_supply/BAT${BAT}/uevent | gawk -F '=' '
cat $BATS | gawk -F '=' '
BEGIN {
efull = 0
enow = 0
status = ""
}
/POWER_SUPPLY_STATUS=/ { /POWER_SUPPLY_STATUS=/ {
status=$2 if (status == "") {
status = $2
if (status == "Discharging") {
status = "↓"
} else if (status == "Charging") {
status = "⚡"
} else {
status = ""
}
}
} }
/POWER_SUPPLY_ENERGY_FULL=/ { /POWER_SUPPLY_ENERGY_FULL=/ {
efull=$2 efull += $2
} }
/POWER_SUPPLY_ENERGY_NOW=/ { /POWER_SUPPLY_ENERGY_NOW=/ {
enow=$2 enow += $2
} }
END { END {
charge=enow/efull*100 charge = enow / efull * 100
if (status == "Discharging") {
status="↓"
} else if (status == "Charging") {
status="↑"
} else {
status=""
}
printf("%s%d%\n", status, charge) printf("%s%d%\n", status, charge)
printf("%s%d\n", status, charge) printf("%s%d\n", status, charge)
if (charge > 25) { if (charge > 25) {

View File

@ -1,12 +1,13 @@
#!/bin/bash #!/bin/bash
[[ "$BLOCK_BUTTON" == 1 ]] && i3-sensible-terminal -e htop
top -bn1 | gawk ' top -bn1 | gawk '
/^\%CPU/ { /^\%CPU/ {
cpu=100-$8 cpu = 100 - $8
} }
END { END {
printf("%d%", cpu) printf("%d%\n", cpu)
print("\n") printf("%d\n", cpu)
if (cpu < 50) { if (cpu < 50) {
print("#04B431\n") print("#04B431\n")
} else if (cpu < 60) { } else if (cpu < 60) {

View File

@ -1,9 +1,13 @@
#!/bin/bash #!/bin/bash
SHORT=$(date '+%_H:%M')
FULL=$(date '+%A, %_d.%_m. %_H:%M:%S') FULL=$(date '+%A, %_d.%_m. %_H:%M:%S')
case ${BLOCK_INSTANCE} in SHORT=$(date '+%_H:%M')
short) LONG=false ;; a=$I3_LONG_DATETIME/1
*) LONG=true ;; [[ "$BLOCK_INSTANCE" == "short" ]] && export I3_LONG_DATETIME=false
esac a+=$I3_LONG_DATETIME/2
[[ ${BLOCK_BUTTON} == 1 ]] && LONG=true [[ "$BLOCK_BUTTON" == "1" && $I3_LONG_DATETIME == "true" ]] && echo a; export I3_LONG_DATETIME=false;
[[ "$LONG" == "true" ]] && echo $FULL || echo $SHORT a+=$I3_LONG_DATETIME/3
[[ "$BLOCK_BUTTON" == "1" && $I3_LONG_DATETIME == "false" ]] && echo b; export I3_LONG_DATETIME=true;
a+=$I3_LONG_DATETIME/4
echo $a
[[ "$I3_LONG_DATETIME" == "true" ]] && echo $FULL || echo $SHORT

View File

@ -1,17 +1,52 @@
#!/bin/bash #!/bin/bash
[[ ${BLOCK_INSTANCE} == 'swap' ]] && TYPE="SwapFree" || TYPE="MemAvailable"
[[ "$BLOCK_BUTTON" == 1 ]] && i3-sensible-terminal -e htop
case ${BLOCK_INSTANCE} in
swap) TYPE="swap";;
ram) TYPE="ram";;
*) TYPE="";;
esac
gawk -v type="$TYPE" ' gawk -v type="$TYPE" '
$0 ~ type { /^MemAvailable/ {
mfg=$2/1024^2 rfg = $2 / 1024^2
mfm=$2/1024 rfm = $2 / 1024
}
/^SwapFree/ {
sfg = $2 / 1024^2
sfm = $2 / 1024
} }
END { END {
if (type == "") {
mfg = rfg + sfg
mfm = rfm + sfm
if (mfg > 2) { if (mfg > 2) {
printf("%.1f GB", mfg) printf("%d+%d G\n", rfg, sfg)
printf("%d+%dG\n", rfg, sfg)
} else { } else {
printf("%.0f MB", mfm) printf("%d+%d M\n", rfm, sfm)
printf("%d+%dM\n", rfm, sfm)
}
} else if (type == "ram") {
if (rfg > 2) {
printf("%d G\n", rfg)
printf("%dG\n", rfg)
mfg = rfg
} else {
printf("%d M\n", rfm)
printf("%dM\n", rfm)
}
} else if (type == "swap") {
if (sfg > 2) {
printf("%d G\n", sfg)
printf("%dG\n", sfg)
mfg = sfg
} else {
printf("%d M\n", sfm)
printf("%dM\n", sfm)
}
} }
print("\n")
if (mfg > 5) { if (mfg > 5) {
print("#04B431\n") print("#04B431\n")
} else if (mfg > 4) { } else if (mfg > 4) {

View File

@ -5,12 +5,17 @@ df | gawk '
sfm=$4/1024 sfm=$4/1024
} }
END { END {
if (sfg > 5) { if (sfg < 1) {
printf("%.1f GB", sfg) printf(" full \n")
printf("full\n")
exit 33
} else if (sfg > 5) {
printf("%.1f G \n", sfg)
printf("%dG\n", sfg)
} else { } else {
printf("%.0f MB", sfm) printf("%.0f M \n", sfm)
printf("%dG\n", sfm)
} }
print("\n")
if (sfg > 20) { if (sfg > 20) {
print("#04B431\n") print("#04B431\n")
} else if (sfg > 15) { } else if (sfg > 15) {
@ -21,8 +26,6 @@ df | gawk '
print("#FFAE00\n") print("#FFAE00\n")
} else if (sfg > 1) { } else if (sfg > 1) {
print("#FF0000\n") print("#FF0000\n")
} else {
exit 33
} }
} }
' '