-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpipe-toggle
More file actions
executable file
·83 lines (73 loc) · 1.65 KB
/
pipe-toggle
File metadata and controls
executable file
·83 lines (73 loc) · 1.65 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/sh
pipe_name="generic-pipe"
indicator_on="x"
indicator_off=" "
custom_condition=""
enable_command=""
disable_command=""
off="false"
init="false"
for arg in "$@"; do
case "$arg" in
--off)
off="true"
;;
--init)
init="true"
;;
--pipe=*)
pipe_name="${arg#*=}"
;;
--on-indicator=*)
indicator_on="${arg#*=}"
;;
--off-indicator=*)
indicator_off="${arg#*=}"
;;
--condition=*)
custom_condition="${arg#*=}"
;;
--enable=*)
enable_command="${arg#*=}"
;;
--disable=*)
disable_command="${arg#*=}"
;;
esac
done
if [ -z "$enable_command" ] || [ -z "$disable_command" ]; then
echo "Error: Both --enable and --disable arguments are required."
exit 1
fi
base_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
dir="$base_dir/.tmp"
mkdir -p $dir
pipe="$dir/$pipe_name"
if [[ ! -p $pipe ]]; then
mkfifo $pipe
fi
do_it () {
export DISPLAY=:0.0
eval_result="false"
if [ -n "$custom_condition" ]; then
eval "$custom_condition"
eval_result=$?
fi
if [ "$eval_result" -eq 0 ] && [ "$off" = "false" ]; then
eval "$enable_command"
echo "$indicator_on" | tee $pipe | tee $pipe-copy
else
eval "$disable_command"
echo "$indicator_off" | tee $pipe | tee $pipe-copy
fi
}
if [ "$init" = "true" ]; then
if [ ! -f "$pipe-copy" ]; then
off=true
do_it
else
cat "$pipe-copy" | tee $pipe
fi
else
do_it
fi