forked from zoddDev/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkspace-tracker.sh
executable file
·57 lines (41 loc) · 1.19 KB
/
workspace-tracker.sh
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
55
56
57
#!/bin/bash
WORKSPACE_REGISTRY=$HOME/.config/last-workspace
WORKSPACE_BUFFER=$HOME/.config/last-workspace-buffer
# Getters
function get_registry_content {
cat $WORKSPACE_REGISTRY
}
function get_buffer_content {
cat $WORKSPACE_BUFFER
}
function get_current_workspace {
echo "$(wmctrl -d | grep "*" | cut -d ' ' -f 1)"
}
function get_last_workspace {
get_registry_content
}
# Functionality
function update_last_workspace {
echo "UPDATING {current=$(get_current_workspace), last=$(get_last_workspace)}"
PRE=$(get_last_workspace)
# write the current workspace into the registry
get_current_workspace > $WORKSPACE_REGISTRY
# write PRE value into the buffer
echo $PRE > $WORKSPACE_BUFFER
}
function check {
echo "REGISTRY=$(get_registry_content) | BUFFER=$(get_buffer_content)"
if [[ $(get_current_workspace) -ne $(get_last_workspace) ]]
then
# workspace switch detected
update_last_workspace
fi
}
[ -f $WORKSPACE_REGISTRY ] || touch $WORKSPACE_REGISTRY
[ -f $WORKSPACE_BUFFER ] || touch $WORKSPACE_BUFFER && echo '' > $WORKSPACE_BUFFER
get_current_workspace > $WORKSPACE_REGISTRY
while true
do
check
sleep 0.075
done