old
#DATE=$(date "+ %a-%b-%d-%Y %I:%M %S%p")
#date=$(date "+%I:%M%p")
#bstat=$(head -c 1 /sys/class/power_supply/BAT0/status)
#bper=$(cat /sys/class/power_supply/BAT0/capacity)
#vol=$( wpctl get-volume @DEFAULT_AUDIO_SINK@ | cut -d : -f 2)
#vol=${vol##*0.}%
#wifi="$(awk '/^\s*w/ { print "wifi", int($3 * 100 / 70) "% " }' /proc/net/wireless)"
#kblay=$(swaymsg -t get_inputs | grep -m1 'xkb_active_layout_name' | awk -F '"' '{print $4}'| head -c 3)
#bness="$(brightnessctl get)"
#max="$(brightnessctl max)"
#bperc="$((bness*100/max))"
#echo $kblay $bperc $vol $bstat$bper% $date
json bar
-----------------------------
#!/bin/sh
bg_bar_color="#282A36"
separator() {
echo -n "{"
echo -n "\"full_text\"\"\":," # CTRL+Ue0b2
echo -n "\"separator\":false,"
echo -n "\"separator_block_width\":0,"
echo -n "\"border\":\"$bg_bar_color\","
echo -n "\"border_left\":0,"
echo -n "\"border_right\":0,"
echo -n "\"border_top\":2,"
echo -n "\"border_bottom\":2,"
echo -n "\"color\":\"$1\","
echo -n "\"background\":\"$2\""
echo -n "}"
}
common() {
echo -n "\"border\": \"$bg_bar_color\","
echo -n "\"separator\":false,"
echo -n "\"separator_block_width\":0,"
echo -n "\"border_top\":2,"
echo -n "\"border_bottom\":2,"
echo -n "\"border_left\":0,"
echo -n "\"border_right\":0"
}
battery0() {
if [ -f /sys/class/power_supply/BAT0/uevent ]; then
local bg="#D69E2E"
1
bg_separator_previous=$bg
prct=$(cat /sys/class/power_supply/BAT0/capacity)
charging=$(cat /sys/class/power_supply/BAT0/status)
icon=""
if [ "$charging" == "Charging" ]; then
icon=""
fi
echo -n ",{"
echo -n "\"name\":\"battery0\","
echo -n "\"full_text\":\" ${icon} ${prct}% \","
echo -n "\"color\":\"#000000\","
echo -n "\"background\":\"$bg\","
common
echo -n "},"
else
bg_separator_previous="#E0E0E0"
fi
}
mydate() {
local bg="#E0E0E0"
separator $bg "#546E7A"
echo -n ",{"
echo -n "\"name\":\"id_time\","
echo -n "\"full_text\":\" $(date "+%a %d/%m %H:%M") \","
echo -n "\"color\":\"#000000\","
echo -n "\"background\":\"$bg\","
common
echo -n "},"
}
volume() {
local bg="#673AB7"
separator $bg $bg_separator_previous
vol=$(wpctl get-volume @DEFAULT_AUDIO_SINK@ | cut -d : -f 2)
echo -n ",{"
echo -n "\"name\":\"id_volume\","
if [ $vol -le 0 ]; then
echo -n "\"full_text\":\" ${vol}% \","
else
echo -n "\"full_text\":\" ${vol}% \","
fi
echo -n "\"background\":\"$bg\","
common
echo -n "},"
separator $bg_bar_color $bg
}
logout() {
echo -n ",{"
echo -n "\"name\":\"id_logout\","
echo -n "\"full_text\":\" \""
echo -n "}"
}
# Send the header so that i3bar knows we want to use JSON:
echo '{ "version": 1 , "click_events":true,"cont_signal": 18,"stop_signal": 19}'
# Begin the endless array.
echo '['
# We send an empty first array of blocks to make the loop simpler:
echo '[]'
# launched in a background process
while :;
do
echo -n ",["
mydate
battery0
volume
logout
echo "]"
sleep 10
done
# click events
while read line;
do
echo $line > /tmp/tmp.txt
# on click, we get from STDIN :
{"name":"id_time","button":1,"modifiers":["Mod2"],"x":2982,"y":9,"relative_x":67,"relative_y":9,"width":95,"height":22}
# DATE click
if [[ $line == *"name"*"id_time"* ]]; then
foot /home/kai/.config/sway/click_time.sh &
fi
# VOLUME
elif [[ $line == *"name"*"id_volume"* ]]; then
foot alsamixer &
elif [[ $line == *"name"*"id_logout"* ]]; then
swaynag -t warning -m 'Log out ?' -b 'yes' 'i3-msg exit' > /dev/null &
fi
done
---------------------------------
for alsa
vol=$(amixer get Master | sed -En 's/.*\[([0-9]+)%\].*/\1/p')
for debian pipewire
vol=$(pulsemixer --get-volume | cut -d ' ' -f 1)
https://github.com/i3/i3/blob/next/contrib/trivial-bar-script.sh
https://en.jeffprod.com/blog/2020/create-your-own-i3-sway-status-bar/
https://github.com/Tazeg/i3status/blob/master/i3status/mybar.sh
for mouse press
cat /tmp/tmp.txt
,{ "name": "id_volume", "button": 1, "event": 272, "x": 1878, "y": 0, "relative_x": 57, "relative_y": 0, "width": 79, "height": 23, "scale": 1 }
{ "name": "clock", "instance": "edt", "x": 1900, "y": 10, "button": 1, "event": 274, "relative_x": 100, "relative_y": 8, "width": 120, "height": 18 }
left click = event 272 , button 1
middle click= event274, button 2
right click = event 273, button 3
scroll up = event 768 , button 4
scroll down = event 769 , button 5
scroll left = event 770 , button 6
scroll right = event 771 , button 7
button
new status.sh
#!/bin/bash
bg_bar_color="#000000"
common() {
echo -n "\"border\": \"$bg_bar_color\","
echo -n "\"separator_block_width\":0,"
}
battery0() {
local bg="#D69E2E"
prct=$(cat /sys/class/power_supply/BAT0/capacity)
chrg=$(cat /sys/class/power_supply/BAT0/status)
icon=""
case $chrg in
"Charging") icon="";bg="#0000ff"; ;;
"Not charging") icon="";bg="#ff0000" ;;
"Unknown") icon="";bg="ff00ff" ;;
"Full") icon="⚡"; bg="ffff00" ;;
esac
echo -n "{"
echo -n "\"name\":\"battery0\","
echo -n "\"full_text\":\" ${icon}${prct}\","
echo -n "\"color\":\"#000000\","
echo -n "\"background\":\"$bg\","
common
echo -n "},"
}
mydate() {
local bg="#E0E0E0"
echo -n "{"
echo -n "\"name\":\"id_time\","
echo -n "\"full_text\":\" $(date "+%a %d/%m %H:%M") \","
echo -n "\"color\":\"#000000\","
echo -n "\"background\":\"$bg\","
common
echo -n "},"
}
volume() {
local bg="#673AB7"
vol=$(wpctl get-volume @DEFAULT_AUDIO_SINK@ | cut -d : -f 2)
echo -n "{"
echo -n "\"name\":\"id_volume\","
echo -n "\"background\":\"$bg\","
echo -n "\"full_text\":\" ${vol}% \","
common
echo -n "},"
}
logout() {
echo -n "{"
echo -n "\"name\":\"id_logout\","
echo -n "\"full_text\":\" \","
echo -n '"align": "left"'
echo -n "}"
}
echo '{ "version": 1 , "click_events":true}'
echo '[[],'
while :;
do
echo -n "["
mydate
battery0
volume
echo -n "],"
sleep 1
read line
echo $line >/tmp/tmp.txt
done
status.sh
DATE=$(date "+%a-%b-%d-%Y %I:%M%p")
BATSTAT=$(cat /sys/class/power_supply/BAT0/status)
BATPERC=$(cat /sys/class/power_supply/BAT0/capacity)
VSTAT="$(amixer get Master)"
VMUTE=" "
echo "$VSTAT" | grep "\[off\]" >/dev/null && VMUTE="muted"
VOLUME=$(echo "$VSTAT" | grep -o "\[[0-9]\+%\]" | sed "s/[^0-9]*//g;1q")
WIFI="$(awk '/^\s*w/ { print "", int($3 * 100 / 70) "% " }' /proc/net/wireless)"
KBLAYOUT=$(swaymsg -t get_inputs | grep -m1 'xkb_active_layout_name' | awk -F '"' '{print $4}')
BNESS="$(brightnessctl get)"
MAX="$(brightnessctl max)"
BLPERC="$((BNESS*100/MAX))"
NIGHT=
pgrep wlsunset && NIGHT=
echo $KBLAYOUT $NIGHT $BLPERC $VMUTE $VOLUME $WIFI $BATPERC% $BATSTAT $DATE
bar {
position top
#swaybar_command waybar
status_command while ~/.config/sway/status.sh; do sleep 1; done
}
.......
#!/bin/sh
printf "{\"version\":1}\n"
printf "[\n"
while true
do
printf "["
printf "{\"full_text\":\"%s\"}," "$(makoctl list | jq -r '.data[0][0].summary.data | select(type == "string")')"
printf "{\"full_text\":\"%s\"}," "$(swaymsg -t get_inputs | jq -r '[.[] | select(.type == "keyboard")][0].xkb_active_layout_name')"
printf "{\"full_text\":\"%s\"}," "$(cat /sys/class/power_supply/BAT0/capacity)"
printf "{\"full_text\":\"%s\"}," "$(date +%c)"
printf "],"
timeout 1 swaymsg -t subscribe '["input","binding"]' >/dev/null
done
The range of available signal numbers is 1 to N, where SIGRTMIN+N = SIGRTMAX.
(Note: there are 31 real-time signals in Linux.)
Comments
Post a Comment