-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhyprland_status
executable file
·54 lines (40 loc) · 1.86 KB
/
hyprland_status
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh
command -v hyprctl >/dev/null 2>&1 || { echo >&2 "hyprctl was not found"; exit 1; }
command -v socat >/dev/null 2>&1 || { echo >&2 "socat was not found"; exit 1; }
command -v date >/dev/null 2>&1 || { echo >&2 "date was not found"; exit 1; }
command -v sed >/dev/null 2>&1 || { echo >&2 "sed was not found"; exit 1; }
command -v tr >/dev/null 2>&1 || { echo >&2 "tr was not found"; exit 1; }
unset status_dump
unset status_handle
status_dump(){
t=$(LC_ALL=en_US.utf8 date +"%s-%3N")
tmp_path=".hyprland_logger.tmp"
res="$(hyprctl activewindow)"
if [ "$res" = "Invalid" ]; then
res=" title: Desktop
pid: 00000
class: Desktop"
fi
# title=$(echo "$res" | grep -E "*title" | sed 's/^[^:]*: //g') # Does not work if "title" is in title !
# title=$(echo "$res" | jq -r '.title') # hyprctl activewindow -j
# title=$(echo "$res" | awk -F': ' '/^[[:space:]]*title:/ {print $2}')
# title=$(echo "$res" | sed -n 's/^[[:space:]]*title: //p')
# Almost as fast, but stronger regex
title=$(printf "%s" "$res" | sed -n 's/^[[:space:]]*title: //p' | sed 's/%/%%/g') # ;s/\\n/\\\\n/g')
class=$(printf "%s" "$res" | sed -n 's/^[[:space:]]*class: //p')
pid=$(printf "%05d" "$(printf "%s" "$res" | sed -n 's/^[[:space:]]*pid: //p')")
pid=${pid:-0}
new=$(printf "[%s] [%s] %s" "$pid" "$class" "$title")
# echo "NEW : $new;"
# echo "OLD : $(cat $tmp_path);"
[ "$new" = "$(cat $tmp_path)" ] || printf "%s\n" "[$t] $new"
printf "$new" > $tmp_path
}
status_handle() {
case $1 in
activewindow*) status_dump >> "$filename" ;;
esac
}
filename="$(LC_ALL=en_US.utf8 date +"%d-%m-%Y_%Hh%Mm%S").wins"
printf "%s" "Starting at $(LC_ALL=en_US.utf8 date +"%a %b %d %T %Y")\n\n" > "$filename"
socat -U - UNIX-CONNECT:/tmp/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock | while read -r line; do status_handle "$line"; done