-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinl-tools.nix
257 lines (233 loc) · 6.55 KB
/
inl-tools.nix
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
{ config, pkgs, ... }:
with pkgs;
let bluetoothScript = scriptName: regexPattern:
(writeScriptBin scriptName ''
#! ${bash}/bin/bash
set -x
export XDG_RUNTIME_DIR=/run/user/$UID
TRIES=0
until (bluetoothctl <<< show | grep -q 'Powered: yes')
do
bluetoothctl <<< 'power on'
[[ $((TRIES++)) -eq 20 ]] && exit 1
sleep 0.1
done
TRIES=0
until [ -n "$DEVICE" ]
do
DEVICE=$(bluetoothctl <<< devices | egrep '^Device.*${regexPattern}' | awk '{ print $2 }')
[[ $((TRIES++)) -eq 20 ]] && exit 1
sleep 0.1
done
TRIES=0
until bluetoothctl <<< "connect $DEVICE"
do
[[ $((TRIES++)) -eq 20 ]] && exit 1
sleep 0.1
done
TRIES=0
until [ -n "$TARGET_CARD" ]
do
TARGET_CARD=$(pacmd list-cards | grep 'name:' | egrep -o 'bluez.*[^>]')
[[ $((TRIES++)) -eq 20 ]] && exit 1
sleep 0.1
done
TRIES=0
until pacmd list-cards | egrep -q 'active profile: <a2dp_sink>'
do
pacmd set-card-profile $TARGET_CARD a2dp_sink
[[ $((TRIES++)) -eq 20 ]] && exit 1
sleep 0.1
done
TRIES=0
until [ -n "$TARGET_SINK" ]
do
TARGET_SINK=$(pacmd list-sinks | grep 'name:' | egrep -o 'bluez.*[^>]')
[[ $((TRIES++)) -eq 20 ]] && exit 1
sleep 0.1
done
pactl set-sink-volume $TARGET_SINK 50%
pacmd set-default-sink $TARGET_SINK
for index in $(pacmd list-sink-inputs $TARGET_SINK | grep index | awk '{ print $2 }')
do
pacmd move-sink-input $index $TARGET_SINK
done
'');
in
{ environment.systemPackages = [
(writeScriptBin "anders-handle-keybind" ''
#! ${bash}/bin/bash
case $1 in
F1)
pactl set-sink-mute @DEFAULT_SINK@ toggle
killall -SIGUSR1 i3status
;;
F2)
pactl set-sink-volume @DEFAULT_SINK@ -5%
killall -SIGUSR1 i3status
;;
F3)
pactl set-sink-volume @DEFAULT_SINK@ +5%
killall -SIGUSR1 i3status
;;
F7)
exec systemctl suspend
;;
F9)
exec browser
;;
F10)
exec anders-capture
;;
F11)
exec i3-rename
;;
F12)
exec i3-switch
;;
esac
'')
(writeScriptBin "i3-switch" ''
#! ${bash}/bin/bash
set -e
list_workspaces() {
${i3}/bin/i3-msg -t get_workspaces | ${jq}/bin/jq -r '.[] | .name'
}
WORKSPACE=$( list_workspaces | rofi -dmenu -p "switch to workspace " )
i3-msg workspace "$WORKSPACE"
'')
(writeScriptBin "i3-rename" ''
#! ${bash}/bin/bash
set -e
NAME=$( rofi -dmenu -p "rename workspace to " )
i3-msg "rename workspace to $NAME"
'')
(writeScriptBin "browser" ''
#! ${bash}/bin/bash
firefox "$@"
exec i3-msg focus tiling
'')
(writeScriptBin "toggle-invert" ''
#! ${bash}/bin/bash
FOO=$( ${xdotool}/bin/xdotool getactivewindow getwindowname )
if [[ $FOO == *" NOINVERT" ]];
then
FOO=''${FOO% NOINVERT};
else
FOO="$FOO NOINVERT";
fi
${xdotool}/bin/xdotool getactivewindow set_window --name "$FOO"
'')
(writeScriptBin "global-toggle-invert" ''
#! ${bash}/bin/bash
. ${config.system.build.setEnvironment}
if systemctl is-active compton-night > /dev/null
then
sudo systemctl start compton
else
sudo systemctl start compton-night
fi
'')
(writeScriptBin "external-drive-mount" ''
#! ${bash}/bin/bash
set -x
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
${cryptsetup}/bin/cryptsetup --type luks open /dev/sdb external
mount -t ext4 /dev/mapper/external /mnt
'')
(writeScriptBin "external-drive-umount" ''
#! ${bash}/bin/bash
set -x
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
umount /mnt
${cryptsetup}/bin/cryptsetup close external
'')
(writeScriptBin "backup-homedir" ''
#! ${bash}/bin/bash
if [[ $EUID -eq 0 ]]; then
echo "This script must not be run as root" 1>&2
exit 1
fi
rsync -aAXHv $HOME/* /mnt
'')
# TODO remove my-pager in favor of anders-pager once i've rebooted
(writeScriptBin "my-pager" ''
#! ${bash}/bin/bash
if [[ $TERM = dumb ]]; then
exec cat "$@"
else
exec less -R "$@"
fi
'')
(writeScriptBin "anders-pager" ''
#! ${bash}/bin/bash
if [[ $TERM = dumb ]]; then
exec cat "$@"
else
exec less -R "$@"
fi
'')
(writeScriptBin "editor" ''
#! ${bash}/bin/bash
exec nvim "$@"
'')
(writeScriptBin "disable-bluetooth" ''
#! ${bash}/bin/bash
set -x
export XDG_RUNTIME_DIR=/run/user/$UID
bluetoothctl <<< 'power off'
'')
(writeScriptBin "bluetooth-off" ''
#! ${bash}/bin/bash
set -x
bluetoothctl <<< 'power off'
'')
(bluetoothScript "bluetooth-tranya" "T1-L")
(bluetoothScript "bluetooth-oontz" "OontZ")
(writeScriptBin "dark-mode" ''
#! ${bash}/bin/bash
set -x
${redshift}/bin/redshift -O 2000
/run/wrappers/bin/sudo ${coreutils}/bin/tee /sys/class/backlight/intel_backlight/brightness <<< 250
'')
(writeScriptBin "twilight-mode" ''
#! ${bash}/bin/bash
set -x
${redshift}/bin/redshift -O 2500
/run/wrappers/bin/sudo ${coreutils}/bin/tee /sys/class/backlight/intel_backlight/brightness <<< 500
'')
(writeScriptBin "bright-mode" ''
#! ${bash}/bin/bash
set -x
${redshift}/bin/redshift -x
/run/wrappers/bin/sudo ${coreutils}/bin/tee /sys/class/backlight/intel_backlight/brightness <<< 852
'')
# (writeScriptBin "switch-to-headphones" ''
# #! ${bash}/bin/bash
# set -x
# pacmd set-sink-port alsa_output.pci-0000_00_1b.0.analog-stereo analog-output-headphones
# '')
# (writeScriptBin "switch-to-speakers" ''
# #! ${bash}/bin/bash
# set -x
# pacmd set-sink-port alsa_output.pci-0000_00_1b.0.analog-stereo analog-output-speaker
# '')
# (writeScriptBin "toggle-suspend-audio" ''
# #! ${bash}/bin/bash
# pacmd list-sinks | grep state: | grep -v -q SUSPENDED
# if [[ $? -eq 0 ]]
# then
# pacmd suspend 1
# else
# pacmd suspend 0
# fi
# '')
];
environment.variables = { PAGER = "anders-pager"; };
}