commit 660c2ad
hovercats
·
2024-06-18 10:27:06 +0000 UTC
parent d11c2a6
nits
5 files changed,
+69,
-69
M
sh/focus
+4,
-4
1@@ -4,7 +4,7 @@
2 # window focus wrapper that sets borders and can focus next/previous window
3
4 # get current window id
5-CUR=$(pfw)
6+CUR="$(pfw)"
7
8 usage() {
9 printf "usage: %s $(basename "$0") <next|prev|wid>\n"
10@@ -12,15 +12,15 @@ usage() {
11 }
12
13 case $1 in
14- next) wid="$(lsw | grep -v "$CUR" | sed '1 p;d')" ;;
15- prev) wid="$(lsw | grep -v "$CUR" | sed '$ p;d')" ;;
16+ next) wid="$(lsw | grep -v "${CUR}" | sed '1 p;d')" ;;
17+ prev) wid="$(lsw | grep -v "${CUR}" | sed '$ p;d')" ;;
18 top) wid="$(lsw | sed '$ p;d')" ;;
19 0x*) wattr "$1" && wid="$1" ;;
20 *) usage ;;
21 esac
22
23 # exit if we can't find another window to focus
24-[ -z "$wid" ] && exit 1
25+[ -z "${wid}" ] && exit 1
26
27 chwso -r "${wid}" # put it on top of the stack
28 wtf "${wid}" # set focus on it
+1,
-1
1@@ -23,7 +23,7 @@ usage() {
2 # this way, there will only be one window in fullscreen at a time, and no window
3 # will loose their previous geometry info
4 # shellcheck disable=2046
5-[ -f "${FSFILE}" ] && wtp $(cat "${FSFILE}") && chwb -s "${BW}" -c "${ACTIVE}" $(pfw)
6+[ -f "${FSFILE}" ] && wtp $(cat "${FSFILE}") && chwb -s "${BW}" -c "${ACTIVE}" "$(pfw)"
7
8 # if file exist and contain our window id, it means that out window is in
9 # fullscreen mode
+48,
-48
1@@ -28,13 +28,13 @@ EOF
2
3 # I suggest it's under /tmp or somewhere that gets cleaned up at reboot or gets
4 # cleaned up after X stops running
5-FSDIR=${FSDIR:-/tmp/groups}
6+FSDIR="${FSDIR:-/tmp/groups}"
7
8 # define our functions
9
10 # clean WID ($1) from group files
11 clean_wid() {
12- t=$(mktemp /tmp/groups.XXXXXX)
13+ t="$(mktemp /tmp/groups.XXXXXX)"
14 for x in "${FSDIR}"/group.*; do
15 sed "/$1/d" "$x" >"$t"
16 mv "$t" "$x"
17@@ -45,16 +45,16 @@ clean_wid() {
18 # cleans group ($1) from (in)active files
19 clean_status() {
20 t="$(mktemp /tmp/groups.XXXXXX)"
21- sed "/$1/d" "${FSDIR}"/active >"$t"
22- mv "$t" "${FSDIR}"/active
23- sed "/$1/d" "${FSDIR}"/inactive >"$t"
24- mv "$t" "${FSDIR}"/inactive
25+ sed "/$1/d" "${FSDIR}/active" >"$t"
26+ mv "$t" "${FSDIR}/active"
27+ sed "/$1/d" "${FSDIR}/inactive" >"$t"
28+ mv "$t" "${FSDIR}/inactive"
29 }
30
31 # shows all the windows in group ($1)
32 map_group() {
33 # safety
34- if ! grep -q "$1" < "${FSDIR}"/all; then
35+ if ! grep -q "$1" < "${FSDIR}/all"; then
36 printf "Group doesn't exist\n"
37 exit 1
38 fi
39@@ -62,16 +62,16 @@ map_group() {
40 # clean statuses
41 clean_status "$1"
42 # add to active
43- printf "%s\n" "$1" >> "${FSDIR}"/active
44+ printf "%s\n" "$1" >> "${FSDIR}/active"
45
46 # loop through group and map windows
47- xargs mapw -m <"${FSDIR}"/group."$1"
48+ xargs mapw -m <"${FSDIR}/group.$1"
49 }
50
51 # hides all the windows in group ($1)
52 unmap_group() {
53 # safety
54- if ! grep -q "$1" < "${FSDIR}"/all; then
55+ if ! grep -q "$1" < "${FSDIR}/all"; then
56 printf "Group doesn't exist\n"
57 exit 1
58 fi
59@@ -79,57 +79,57 @@ unmap_group() {
60 # clean statuses
61 clean_status "$1"
62 # add to inactive
63- printf "%s\n" "$1" >> "${FSDIR}"/inactive
64+ printf "%s\n" "$1" >> "${FSDIR}/inactive"
65
66 # loop through group and unmap windows
67 while read -r line; do
68 mapw -u "$line"
69- done < "${FSDIR}"/group."$1"
70+ done < "${FSDIR}/group.$1"
71 }
72
73 # assigns WID ($1) to the group ($2)
74 set_group() {
75 #so that neither grep nor ls in clean_wid complain
76 #when group.$2 does not exist
77- touch "${FSDIR}"/group."$2"
78+ touch "${FSDIR}/group.$2"
79
80 # make sure we've no duplicates
81 clean_wid "$1"
82 clean_status "$2"
83
84 # insert WID into new group if not already there
85- grep -q "$1" < "${FSDIR}"/group."$2" || \
86- printf "%s\n" "$1" >> "${FSDIR}"/group."$2"
87+ grep -q "$1" < "${FSDIR}/group.$2" || \
88+ printf "%s\n" "$1" >> "${FSDIR}/group.$2"
89
90 # if we can't find the group add it to groups and make it active
91- grep -q "$2" < "${FSDIR}"/all || \
92- printf "%s\n" "$2" >> "${FSDIR}"/all && \
93- printf "%s\n" "$2" >> "${FSDIR}"/active
94+ grep -q "$2" < "${FSDIR}/all" || \
95+ printf "%s\n" "$2" >> "${FSDIR}/all" && \
96+ printf "%s\n" "$2" >> "${FSDIR}/active"
97
98 # map WID if group is active
99- grep -q "$2" < "${FSDIR}"/active && \
100+ grep -q "$2" < "${FSDIR}/active" && \
101 mapw -m "$1"
102
103 # unmap WID if group is inactive
104- grep -q "$2" < "${FSDIR}"/inactive && \
105+ grep -q "$2" < "${FSDIR}/inactive" && \
106 mapw -u "$1"
107 }
108
109 # toggles visibility state of all the windows in group ($1)
110 toggle_group() {
111 # safety
112- if ! grep -q "$1" < "${FSDIR}"/all; then
113+ if ! grep -q "$1" < "${FSDIR}/all"; then
114 printf "Group doesn't exist\n"
115 return
116 fi
117
118 # search through active groups first
119- grep -q "$1" < "${FSDIR}"/active && \
120+ grep -q "$1" < "${FSDIR}/active" && \
121 unmap_group "$1" && \
122 return
123
124 # search through inactive groups next
125- grep -q "$1" < "${FSDIR}"/inactive && \
126+ grep -q "$1" < "${FSDIR}/inactive" && \
127 map_group "$1" && \
128 return
129 }
130@@ -141,40 +141,40 @@ cleanup_everything() {
131 # clean WIDs that don't exist
132 # using `cat` instead of `<` because error suppression
133 cat "${FSDIR}"/group.* 2>/dev/null | while read -r wid; do
134- wattr "$wid" || \
135- clean_wid "$wid"
136+ wattr "${wid}" || \
137+ clean_wid "${wid}"
138 done
139
140 # clean group files that are empty
141 for file in "${FSDIR}"/group.*; do
142 # is the group empty?
143- if [ ! -s "$file" ]; then
144- rm -f "$file"
145+ if [ ! -s "${file}" ]; then
146+ rm -f "${file}"
147 fi
148 done
149
150- cp "${FSDIR}"/all "${FSDIR}"/tmpall
151+ cp "${FSDIR}/all" "${FSDIR}/tmpall"
152 # remove groups that don't exist from 'all'
153 while read -r line; do
154- if [ ! -f "${FSDIR}"/group."$line" ]; then
155+ if [ ! -f "${FSDIR}/group.${line}" ]; then
156 t="$(mktemp /tmp/groups.XXXXXX)"
157- sed "/$line/d" "${FSDIR}"/tmpall >"$t"
158- mv "$t" "${FSDIR}"/tmpall
159- clean_status "$line"
160+ sed "/$line/d" "${FSDIR}/tmpall" >"$t"
161+ mv "$t" "${FSDIR}/tmpall"
162+ clean_status "${line}"
163 fi
164- done < "${FSDIR}"/all
165- mv -f "${FSDIR}"/tmpall "${FSDIR}"/all
166+ done < "${FSDIR}/all"
167+ mv -f "${FSDIR}/tmpall" "${FSDIR}/all"
168 }
169
170 # actual run logic (including arguments and such)
171
172-# check "${FSDIR}" exists
173+# check $FSDIR exists
174 [ -d "${FSDIR}" ] || mkdir -p "${FSDIR}"
175
176 # touch all the files
177-[ -f "${FSDIR}"/active ] || :> "${FSDIR}"/active
178-[ -f "${FSDIR}"/inactive ] || :> "${FSDIR}"/inactive
179-[ -f "${FSDIR}"/all ] || :> "${FSDIR}"/all
180+[ -f "${FSDIR}/active" ] || :> "${FSDIR}/active"
181+[ -f "${FSDIR}/inactive" ] || :> "${FSDIR}/inactive"
182+[ -f "${FSDIR}/all" ] || :> "${FSDIR}/all"
183
184 cleanup_everything
185
186@@ -185,8 +185,8 @@ while getopts "hc:Cs:t:m:M:u:U" opt; do
187 usage
188 ;;
189 c)
190- clean_wid "$OPTARG"
191- mapw -m "$OPTARG"
192+ clean_wid "${OPTARG}"
193+ mapw -m "${OPTARG}"
194 break
195 ;;
196 C)
197@@ -194,33 +194,33 @@ while getopts "hc:Cs:t:m:M:u:U" opt; do
198 break
199 ;;
200 s)
201- set_group "$OPTARG" "$(eval printf "\$$OPTIND")"
202+ set_group "${OPTARG}" "$(eval printf "\$$OPTIND")"
203 break
204 ;;
205 t)
206- toggle_group "$OPTARG"
207+ toggle_group "${OPTARG}"
208 break
209 ;;
210 m)
211- map_group "$OPTARG"
212+ map_group "${OPTARG}"
213 break
214 ;;
215 M)
216 for file in "${FSDIR}"/group.*; do
217- group=${file##*.}
218- unmap_group "$group"
219+ group="${file##*.}"
220+ unmap_group "${group}"
221 done
222- map_group "$OPTARG"
223+ map_group "${OPTARG}"
224 break
225 ;;
226 u)
227- unmap_group "$OPTARG"
228+ unmap_group "${OPTARG}"
229 break
230 ;;
231 U)
232 for file in "${FSDIR}"/group.*; do
233 group="${file##*.}"
234- unmap_group "$group"
235+ unmap_group "${group}"
236 done
237 break
238 ;;
M
sh/home
+4,
-4
1@@ -2,9 +2,9 @@
2
3 upstream="$HOME/src/selfmade/dotfiles"
4
5-[ -e "$upstream/HEAD" ] || {
6- mkdir -p "$upstream"
7- git clone --bare git@github.com:hovercats/dotfiles "$upstream"
8+[ -e "${upstream}/HEAD" ] || {
9+ mkdir -p "${upstream}"
10+ git clone --bare git@github.com:hovercats/dotfiles "${upstream}"
11 }
12
13-git --git-dir="$upstream" --work-tree="$HOME" "$@"
14+git --git-dir="${upstream}" --work-tree="$HOME" "$@"
+12,
-12
1@@ -31,34 +31,34 @@ ws_init() {
2 # Saves all mapped windows to the current workspace.
3 save_ws() {
4 curr=$(cat /tmp/workspaces/curr)
5- lsw > /tmp/workspaces/ws"${curr}"
6+ lsw > "/tmp/workspaces/ws${curr}"
7 }
8 move_to_ws() {
9- ws_num=$1
10+ ws_num="$1"
11 if [ "${ws_num}" -gt "${NUM_WS}" ] || [ "${ws_num}" -lt 0 ]; then
12 echo "Workspace not found"
13 return
14 fi
15- curr_ws=$(cat /tmp/workspaces/curr);
16+ curr_ws="$(cat /tmp/workspaces/curr)";
17 if [ "${ws_num}" = "${curr_ws}" ]; then
18 # same workspace. ignore flicker
19 return
20 fi
21 save_ws
22- curr_windows=$(lsw)
23+ curr_windows="$(lsw)"
24 if [ "${curr_windows}" ]; then
25 mapw -u "$(lsw)"
26 fi
27 new_windows="$(cat /tmp/workspaces/ws"${ws_num}")"
28- if [ "$new_windows" ]; then
29- mapw -m "$new_windows"
30+ if [ "${new_windows}" ]; then
31+ mapw -m "${new_windows}"
32 fi
33 echo "${ws_num}" > /tmp/workspaces/curr
34 }
35 next_ws() {
36 # Get what ws we're currently in.
37- curr=$(cat /tmp/workspaces/curr)
38- curr=$(echo "${curr}" + 1 | bc)
39+ curr="$(cat /tmp/workspaces/curr)"
40+ curr="$(echo "${curr}" + 1 | bc)"
41
42 # Take care of loopback.
43 if [ "${curr}" -gt "${NUM_WS}" ]; then
44@@ -69,8 +69,8 @@ next_ws() {
45 }
46 prev_ws() {
47 # Get what ws we're currently in.
48- curr=$(cat /tmp/workspaces/curr)
49- curr=$(echo "${curr}" - 1 | bc)
50+ curr="$(cat /tmp/workspaces/curr)"
51+ curr="$(echo "${curr}" - 1 | bc)"
52
53 # Take care of loopback.
54 if [ "${curr}" -lt 0 ]; then
55@@ -88,12 +88,12 @@ move_focused_window() {
56 wid="$(pfw)"
57 curr_ws="$(cat /tmp/workspaces/curr)";
58 if [ "${ws_num}" != "${curr_ws}" ]; then
59- pfw >> /tmp/workspaces/ws"$1"
60+ pfw >> "/tmp/workspaces/ws$1"
61 mapw -u "${wid}"
62 fi
63 }
64 while getopts ":m:g:npi" opt; do
65- case $opt in
66+ case "${opt}" in
67 n)
68 next_ws;;
69 p)