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
--------------------------
audio,mic amixer
audio amixer
battery none, searches in /sys/class/power_supply/BAT...
cpu top
datetime date
ip curl
ram,swap none, searches in /proc/meminfo
ram none, searches in /proc/meminfo
storage df
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
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.
- The default shortcut is `mod + SHIFT + r`, you should see a flickering.
- Adjust `~/.config/i3blocks/config` to control i3 status bar output (see [Usage](#usage)).
- Finally reload your `i3` window manager. The default shortcut is `mod + SHIFT + r`, you should see a flickering.
# Usage
Via the instance id you can choose:
- `instance=short` in every module provides even shorter output without units
- `instance=swap` in the module `ram` to show swap usage
- `instance=1` in the module `battery` to show the status of BAT1 of you have more than one battery attached to your device.
# Usage
- 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.
- module *audio*: `instance=mic` will show the microphone level instead. With a left mouse click the device is muted/unmuted.
- 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.
- *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
## Modules
- [x] datetime
- [x] ram, swap
- [x] ram/swap
- [x] cpu
- [x] audio, mic
- [x] audio/mic
- [x] storage
- [x] ip
- [x] battery
@ -47,8 +48,8 @@ Via the instance id you can choose:
- [ ] ethernet bandwith
## Click interactions
- [ ] datetime: left: show date, middle: show date and time, right: show time
- [ ] audio, mic: toggle mute
- [x] datetime: left: show date and seconds
- [x] audio/mic: left: toggle mute
- [ ] external storage: mount it somewhere
## Signals

31
config
View File

@ -13,39 +13,42 @@ label=
# label=storage
label=
# if you want to display ram and swap seperately, you can assign another [ram] module
# with instance=ram or instance=swap
[ram]
# label=ram
label=
[ram]
# instance=ram
# [ram]
# label=swap
label=
instance=swap
# instance=swap
# separator_block_width=0
[cpu]
# label=cpu
label=
[ip]
# label=ip
label=
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]
# label=battery
label=⚡
separator_block_width=5
[battery]
instance=1
# label=⚡
# [battery]
# instance=1
# separator_block_width=0
[audio]
# label=audio
label=
separator_block_width=5
label=♪
separator_block_width=0
[audio]
label= m
# label=mic
instance=mic
[datetime]
label=
instance=short
# instance=short

View File

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

View File

@ -1,19 +1,23 @@
#!/bin/bash
DIR="/sys/class/backlight/"
if [[ -d "${DIR}acpi_video0" ]]; then
DIR="${DIR}acpi_video0"
elif [[ -d "${DIR}intel_backlight" ]]; then
DIR="${DIR}intel_backlight"
DIR="/sys/class/backlight"
if [[ -d "$DIR/acpi_video0" ]]; then
DIR="$DIR/acpi_video0"
elif [[ -d "$DIR/intel_backlight" ]]; then
DIR="$DIR/intel_backlight"
else
echo "not found "
echo " no backlight "
echo "n/a"
exit 33
fi
cat "${DIR}/brightness" "${DIR}/max_brightness" | gawk '
NR==1 { cbr=$1 }
NR==2 { mbr=$1 }
cat "$DIR/brightness" "$DIR/max_brightness" | gawk '
NR==1 { cbr = $1 }
NR==2 { mbr = $1 }
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")
}
'

View File

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

View File

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

View File

@ -1,9 +1,13 @@
#!/bin/bash
SHORT=$(date '+%_H:%M')
FULL=$(date '+%A, %_d.%_m. %_H:%M:%S')
case ${BLOCK_INSTANCE} in
short) LONG=false ;;
*) LONG=true ;;
esac
[[ ${BLOCK_BUTTON} == 1 ]] && LONG=true
[[ "$LONG" == "true" ]] && echo $FULL || echo $SHORT
SHORT=$(date '+%_H:%M')
a=$I3_LONG_DATETIME/1
[[ "$BLOCK_INSTANCE" == "short" ]] && export I3_LONG_DATETIME=false
a+=$I3_LONG_DATETIME/2
[[ "$BLOCK_BUTTON" == "1" && $I3_LONG_DATETIME == "true" ]] && echo a; export I3_LONG_DATETIME=false;
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
[[ ${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" '
$0 ~ type {
mfg=$2/1024^2
mfm=$2/1024
}
/^MemAvailable/ {
rfg = $2 / 1024^2
rfm = $2 / 1024
}
/^SwapFree/ {
sfg = $2 / 1024^2
sfm = $2 / 1024
}
END {
if (mfg > 2) {
printf("%.1f GB", mfg)
} else {
printf("%.0f MB", mfm)
if (type == "") {
mfg = rfg + sfg
mfm = rfm + sfm
if (mfg > 2) {
printf("%d+%d G\n", rfg, sfg)
printf("%d+%dG\n", rfg, sfg)
} else {
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) {
print("#04B431\n")
} else if (mfg > 4) {

View File

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