~smlavine/dots

ref: 9a16213514f293447bfe6e755d4f4505c6dc8db6 dots/src/.xinitrc -rw-r--r-- 3.8 KiB
9a162135Sebastian LaVine Add qutebrowser config 6 months ago
                                                                                
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
#!/bin/sh

pvpn_file="${PVPN_STATUS_FILE:-$XDG_DATA_HOME/smlss/toggle-pvpn-status}"
[ ! -d "$(dirname "$pvpn_file")" ] && mkdir -p "$(dirname "$pvpn_file")"

get_last_pvpn_modify() {
	stat "$pvpn_file" | grep ^Modify | cut -d' ' -f2-
}

protoninfo() {
	# Timeout after 15 seconds, to prevent the statusbar being
	# frozen if a connection cannot be made.
	status="$(timeout 15 protonvpn status)"
	# If there is an error connecting to the VPN, then display some number
	# of exclamation points in the status bar and display a warning
	# notification.  Otherwise, display the VPN information as normal.
	if echo "$status" | grep -o '!'; then
		# Only show notification if the hardware kill switch isn't
		# flipped. In that case, the notification is just annoying.
		if ! nmcli radio | cut -d' ' -f1 | grep -q disabled; then
			dunstify -t 14500 -u 2 "$status"
		fi
	else
		echo "$status" | grep -E 'Server|Load' | awk '{print $2}' | \
			paste - - | tr '\t' ':'
	fi
}

keyinfo() {
	if setxkbmap -query | grep -q 'variant:    intl'; then
		echo 'INTL'
	else
		echo 'US'
	fi
}

# Print battery percentage, time remaining to full/dead, and status
batinfo() {
	if acpi 2>&1 | grep -qv 'No support for device type'; then
		acpi | awk '{
			# Do not end print statements with a newline
			ORS = ""

			# Remove the comma from the end of the percentage,
			# if it is present.
			sub(",", "", $4);

			# Replace the first colon with an hour label.
			# Replace the second colon with a minute label,
			# and also get rid of the seconds field.
			sub(":", "h", $5);
			sub(/:.*$/, "m", $5);

			print $4 " ";
			if (length($5) > 0)
				print $5 " ";

			if ($3 == "Charging,") {
				print "CHR"
			} else if ($3 == "Discharging,") {
				print "DRN"
			} else if ($3 == "Full,") {
				print "FULL"
			} else {
				print "?"
			}
		}'
	fi
}

dateinfo() {
	date '+%a %b %d %r %Z'
}

setxkbmap -option caps:escape

# This will probably be useful only on a Thinkpad X220 Tablet.
# The touch screen will not respond to touch from a finger, but it will still
# respond to the digitizer pen.
# I did this because it is annoying that things are clicked and higlighted
# when I am wiping dust off the screen.
xinput disable 'Wacom ISDv4 E6 Finger'

# `protonvpn status` takes an extra bit of time to run, so we don't want to
# update protonvpn info every second. For this reason, it is read into a
# variable which is only updated every "$imax" iterations.
imax=15
i="$imax"

# To change whether or not to print ProtonVPN status information in the status
# bar, users will touch this file. If it is detected that the file has been
# modified (`touch`-ed) since the last time it was checked, then this value
# will be toggled.
touch "$pvpn_file"
pvpn_last_modify="$(get_last_pvpn_modify)"
pvpn_status=1

# If Wi-Fi is present but disabled, don't print ProtonVPN status information.
ip link | grep wlp | grep -q 'state DOWN' && pvpn_status=

while true
do
	pvpn_new_modify="$(get_last_pvpn_modify)"
	if [ "$pvpn_last_modify" != "$pvpn_new_modify" ]; then
		pvpn_last_modify="$pvpn_new_modify"
		if [ "$pvpn_status" ]; then
			pvpn_status=
		else
			# Set i so that if VPN status info is re-enabled, we
			# don't have to wait for i to reach imax as it starts
			# counting again to see VPN status info and receive '!'
			# notifications.
			i="$imax"
			pvpn_status=1
		fi
	fi

	if [ ! "$pvpn_status" ]; then
		proton="<> "
	elif [ "$i" -ge "$imax" ]; then
		# We append a space here to be in between proton and keyinfo,
		# if proton isn't empty.
		proton="$(protoninfo)" && [ -n "$proton" ] && proton="$proton "
		i=0
	else
		i="$(( i + 1 ))"
	fi
	xsetroot -name " $proton$(keyinfo) $(vol) $(dateinfo) $(batinfo)"
	sleep 1
done &

dunst -font "monospace 11" &

# Happy Holidays!
xsetroot -bitmap /usr/include/X11/bitmaps/xsnow -bg rgb:14/13/7E -fg rgb:2A/89/F5

exec dwm