-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathi3configure.sh
executable file
·60 lines (43 loc) · 1.4 KB
/
i3configure.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
58
59
#! /bin/bash
set -e
repo_dir=$(realpath "$(dirname "$0")")
i3baseconfig=$repo_dir/i3/baseconfig
i3config=$repo_dir/i3/config
i3statusbaseconfig=$repo_dir/i3status/baseconfig
i3statusconfig=$repo_dir/i3status/config
config_regex='^[ #]*\(.*\)#[ ]*--\([^#]\+\)--[ ]*$'
mapfile -t configs < <( \
grep -h "$config_regex" "$i3baseconfig" "$i3statusbaseconfig" |
sed -e "s/$config_regex/\2/" |
sort -u)
echo "Configurations: ${configs[*]}"
if [ $# -lt 1 ]; then
echo "Usage: $0 <configurations...>"
exit 1
fi
configurations=( "$@" )
for configuration in "${configurations[@]}"; do
ok=0
for conf in "${configs[@]}"; do
if [ "$configuration" = "$conf" ]; then
ok=1
break
fi
done
if [ "$ok" != 1 ]; then
echo "Invalid Config: $conf"
exit 1
fi
done
echo "Copying $i3baseconfig to $i3config"
cp "$i3baseconfig" "$i3config"
echo "Copying $i3statusbaseconfig to $i3statusconfig"
cp "$i3statusbaseconfig" "$i3statusconfig"
echo "Commenting Out Unwanted Lines in $i3config $i3statusconfig"
sed -i -e "s/$config_regex/#\1 # --\2--/" "$i3config" "$i3statusconfig"
for configuration in "${configurations[@]}"; do
echo "Enabling Wanted Lines for $configuration in $i3config $i3statusconfig"
curconfig_regex="^[ #]*\(.*\)#[ ]*--$configuration--[ ]*$"
sed -i -e "s/$curconfig_regex/\1/" "$i3config" "$i3statusconfig"
done
echo DONE