more consistent quoting and more comments

don't quote variable assignment unless it has special characters

use single quotes when not using any shell expansion (variables,
subshells)
This commit is contained in:
gk
2020-10-13 08:02:46 +10:00
parent ce53a54d4c
commit 5d432d2c67
+32 -28
View File
@@ -15,8 +15,8 @@ eq() { # equals | [ a = b ] with globbing
}
## DE
wm="$XDG_CURRENT_DESKTOP"
[ "$wm" ] || wm="$DESKTOP_SESSION"
wm=$XDG_CURRENT_DESKTOP
[ "$wm" ] || wm=$DESKTOP_SESSION
## Distro
# freedesktop.org/software/systemd/man/os-release.html
@@ -32,20 +32,24 @@ if [ -e /proc/$$/comm ]; then
# loop over lines in /proc/pid/status until it reaches PPid
# then save that to a variable and exit the file
while read -r line; do
eq "$line" "PPid*" && ppid=${line##*:?} && break
eq "$line" 'PPid*' && ppid=${line##*:?} && break
done < "/proc/${ppid:-$PPID}/status"
# Make sure not to do an infinite loop
[ "$pppid" = "$ppid" ] && break
pppid="$ppid"
pppid=$ppid
# get name of binary
read -r name < "/proc/$ppid/comm"
case $name in
*sh|"${0##*/}") ;; # skip shells
*[Ll]ogin*|*init*) break;; # exit when the top is reached
*) term="$name" # anything else can be assumed to be the terminal
*[Ll]ogin*|*init*|*systemd*) break;; # exit when the top is reached
# anything else can be assumed to be the terminal
# this has the side affect of catching tmux, but tmux
# detaches from the terminal and therefore ignoring that
# will just make the init the term
*) term=$name
esac
done
@@ -55,7 +59,7 @@ if [ -e /proc/$$/comm ]; then
for i in /proc/*/comm; do
read -r c < "$i"
case $c in
awesome|xmonad*|qtile|sway|i3|[bfo]*box|*wm*) wm="${c%%-*}"; break;;
awesome|xmonad*|qtile|sway|i3|[bfo]*box|*wm*) wm=${c%%-*}; break;;
esac
done
@@ -63,7 +67,7 @@ if [ -e /proc/$$/comm ]; then
# loop over lines in /proc/meminfo until it reaches MemTotal,
# then convert the amount (second word) from KB to MB
while read -r line; do
eq "$line" "MemTotal*" && set -- $line && break
eq "$line" 'MemTotal*' && set -- $line && break
done < /proc/meminfo
mem="$(( $2 / 1000 ))MB"
@@ -71,7 +75,7 @@ if [ -e /proc/$$/comm ]; then
while read -r line; do
case $line in
vendor_id*) vendor="${line##*: } ";;
model\ name*) cpu="${line##*: }"; break;;
model\ name*) cpu=${line##*: }; break;;
esac
done < /proc/cpuinfo
@@ -84,17 +88,17 @@ if [ -e /proc/$$/comm ]; then
## Kernel
read -r _ _ version _ < /proc/version
kernel="${version%%-*}"
eq "$version" "*Microsoft*" && ID="fake $ID"
kernel=${version%%-*}
eq "$version" '*Microsoft*' && ID="fake $ID"
## Motherboard // laptop
read -r model < /sys/devices/virtual/dmi/id/product_name
# invalid model handling
case $model in
# alternate file with slightly different info
# on my HP laptop it has the device model (instead of 'hp notebook')
# on my laptop it has the device model (instead of 'hp notebook')
# on my desktop it has the extended motherboard model
"System "*|"Default "*)
'System '*|'Default '*)
read -r model < /sys/devices/virtual/dmi/id/board_name
esac
@@ -118,7 +122,7 @@ elif [ -f /var/run/dmesg.boot ]; then
## OpenBSD cpu/mem/name
while read -r line; do
case $line in
"real mem"*)
'real mem'*)
# use the pre-formatted value which is in brackets
mem=${line##*\(}
mem=${mem%\)*}
@@ -159,7 +163,7 @@ elif [ -f /var/run/dmesg.boot ]; then
FreeBSD*)
# If the OS is already set, no need to set it again
[ "$ID" ] && continue
ID="${line%%-R*}"
ID=${line%%-R*}
;;
CPU:*)
@@ -173,7 +177,7 @@ elif [ -f /var/run/dmesg.boot ]; then
vendor="${vendor%%\"*} "
;;
"real memory"*)
'real memory'*)
# Get the pre-formatted amount which is inside brackets
mem=${line##*\(}
mem=${mem%\)*}
@@ -207,27 +211,27 @@ elif v=/System/Library/CoreServices/SystemVersion.plist; [ -f "$v" ]; then
done < "$v"
fi
eq "$0" "*fetish" && printf 'Step on me daddy\n' && exit
eq "$0" '*fetish' && printf 'Step on me daddy\n' && exit
# help i dont know if it's a capital consistently
eq "$wm" "*[Gg][Nn][Oo][Mm][Ee]*" && wm="foot DE"
eq "$wm" '*[Gg][Nn][Oo][Mm][Ee]*' && wm='foot DE'
## GTK
while read -r line; do
eq "$line" "gtk-theme*" && gtk="${line##*=}" && break
eq "$line" 'gtk-theme*' && gtk=${line##*=} && break
done < "${XDG_CONFIG_HOME:=$HOME/.config}/gtk-3.0/settings.ini"
# Shorten $cpu and $vendor
# this is so messy due to so many inconsistencies in the model names
vendor="${vendor##*Authentic}"
vendor="${vendor##*Genuine}"
cpu="${cpu##*) }"
cpu="${cpu%% @*}"
cpu="${cpu%% CPU}"
cpu="${cpu##CPU }"
cpu="${cpu##*AMD }"
cpu="${cpu%% with*}"
cpu="${cpu% *-Core*}"
vendor=${vendor##*Authentic}
vendor=${vendor##*Genuine}
cpu=${cpu##*) }
cpu=${cpu%% @*}
cpu=${cpu%% CPU}
cpu=${cpu##CPU }
cpu=${cpu##*AMD }
cpu=${cpu%% with*}
cpu=${cpu% *-Core*}
col() {
printf ' '