Variable substitution, remove useless forward slashes and quotes
This commit is contained in:
parent
92cda8174c
commit
2b04747804
164
fetch
164
fetch
|
@ -328,7 +328,7 @@ case "$os" in
|
||||||
|
|
||||||
elif type -p lsb_release >/dev/null 2>&1; then
|
elif type -p lsb_release >/dev/null 2>&1; then
|
||||||
distro="$(lsb_release -a 2>/dev/null | awk -F':' '/Description/ {printf $2}')"
|
distro="$(lsb_release -a 2>/dev/null | awk -F':' '/Description/ {printf $2}')"
|
||||||
distro=${distro/[[:space:]]/}
|
distro=${distro/[[:space:]]}
|
||||||
|
|
||||||
else
|
else
|
||||||
distro="$(grep -h '^NAME=' /etc/*ease)"
|
distro="$(grep -h '^NAME=' /etc/*ease)"
|
||||||
|
@ -404,7 +404,7 @@ getuptime () {
|
||||||
"Mac OS X" | *"BSD")
|
"Mac OS X" | *"BSD")
|
||||||
# Get boot time in seconds
|
# Get boot time in seconds
|
||||||
boot="$(sysctl -n kern.boottime)"
|
boot="$(sysctl -n kern.boottime)"
|
||||||
boot="${boot/{ sec = /}"
|
boot="${boot/{ sec = }"
|
||||||
boot=${boot/,*}
|
boot=${boot/,*}
|
||||||
|
|
||||||
# Get current date in seconds
|
# Get current date in seconds
|
||||||
|
@ -418,20 +418,20 @@ getuptime () {
|
||||||
|
|
||||||
case "$mins" in
|
case "$mins" in
|
||||||
0) ;;
|
0) ;;
|
||||||
1) uptime="up ${mins} minute" ;;
|
1) uptime="up $mins minute" ;;
|
||||||
*) uptime="up ${mins} minutes" ;;
|
*) uptime="up $mins minutes" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case "$hours" in
|
case "$hours" in
|
||||||
0) ;;
|
0) ;;
|
||||||
1) uptime="up ${hours} hour, ${uptime/up /}" ;;
|
1) uptime="up $hours hour, ${uptime/up }" ;;
|
||||||
*) uptime="up ${hours} hours, ${uptime/up /}" ;;
|
*) uptime="up $hours hours, ${uptime/up }" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
case "$days" in
|
case "$days" in
|
||||||
0) ;;
|
0) ;;
|
||||||
1) uptime="up ${days} day, ${uptime/up /}" ;;
|
1) uptime="up $days day, ${uptime/up }" ;;
|
||||||
*) uptime="up ${days} days, ${uptime/up /}" ;;
|
*) uptime="up $days days, ${uptime/up }" ;;
|
||||||
esac
|
esac
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
@ -448,21 +448,21 @@ getuptime () {
|
||||||
|
|
||||||
case "$uptime_shorthand" in
|
case "$uptime_shorthand" in
|
||||||
"on")
|
"on")
|
||||||
uptime=${uptime/up/}
|
uptime=${uptime/up}
|
||||||
uptime=${uptime/minutes/mins}
|
uptime=${uptime/minutes/mins}
|
||||||
uptime=${uptime/minute/min}
|
uptime=${uptime/minute/min}
|
||||||
uptime=${uptime# }
|
uptime=${uptime# }
|
||||||
;;
|
;;
|
||||||
|
|
||||||
"tiny")
|
"tiny")
|
||||||
uptime=${uptime/'up'/}
|
uptime=${uptime/up}
|
||||||
uptime=${uptime/' days'/'d'}
|
uptime=${uptime/ days/d}
|
||||||
uptime=${uptime/' day'/'d'}
|
uptime=${uptime/ day/d}
|
||||||
uptime=${uptime/' hours'/'h'}
|
uptime=${uptime/ hours/h}
|
||||||
uptime=${uptime/' hour'/'h'}
|
uptime=${uptime/ hour/h}
|
||||||
uptime=${uptime/' minutes'/'m'}
|
uptime=${uptime/ minutes/m}
|
||||||
uptime=${uptime/' minute'/'m'}
|
uptime=${uptime/ minute/m}
|
||||||
uptime=${uptime/','}
|
uptime=${uptime/,}
|
||||||
uptime=${uptime# }
|
uptime=${uptime# }
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
@ -550,15 +550,15 @@ getshell () {
|
||||||
getwindowmanager () {
|
getwindowmanager () {
|
||||||
if type -p wmctrl >/dev/null 2>&1; then
|
if type -p wmctrl >/dev/null 2>&1; then
|
||||||
windowmanager="$(wmctrl -m | head -n1)"
|
windowmanager="$(wmctrl -m | head -n1)"
|
||||||
windowmanager=${windowmanager/Name: /}
|
windowmanager=${windowmanager/Name: }
|
||||||
|
|
||||||
elif [ "$XDG_CURRENT_DESKTOP" ]; then
|
elif [ "$XDG_CURRENT_DESKTOP" ]; then
|
||||||
windowmanager="$XDG_CURRENT_DESKTOP"
|
windowmanager="$XDG_CURRENT_DESKTOP"
|
||||||
|
|
||||||
elif [ -e "$HOME/.xinitrc" ]; then
|
elif [ -e "$HOME/.xinitrc" ]; then
|
||||||
xinitrc=$(grep "^[^#]*exec" "${HOME}/.xinitrc")
|
xinitrc=$(grep "^[^#]*exec" "${HOME}/.xinitrc")
|
||||||
windowmanager="${xinitrc/exec /}"
|
windowmanager="${xinitrc/exec }"
|
||||||
windowmanager="${windowmanager/-session/}"
|
windowmanager="${windowmanager/-session}"
|
||||||
windowmanager="${windowmanager^}"
|
windowmanager="${windowmanager^}"
|
||||||
|
|
||||||
else
|
else
|
||||||
|
@ -585,9 +585,9 @@ getcpu () {
|
||||||
"Linux")
|
"Linux")
|
||||||
# Get cpu name
|
# Get cpu name
|
||||||
cpu="$(grep -F 'model name' /proc/cpuinfo)"
|
cpu="$(grep -F 'model name' /proc/cpuinfo)"
|
||||||
cpu=${cpu/model name*: /}
|
cpu=${cpu/model name*: }
|
||||||
cpu=${cpu%% *}
|
cpu=${cpu%% *}
|
||||||
cpu=${cpu/@*/}
|
cpu=${cpu/@*}
|
||||||
|
|
||||||
# Get cpu speed
|
# Get cpu speed
|
||||||
if [ -d "/sys/devices/system/cpu/cpu0/cpufreq" ]; then
|
if [ -d "/sys/devices/system/cpu/cpu0/cpufreq" ]; then
|
||||||
|
@ -606,7 +606,7 @@ getcpu () {
|
||||||
|
|
||||||
else
|
else
|
||||||
speed=$(awk -F ': ' '/cpu MHz/ {printf $2; exit}' /proc/cpuinfo)
|
speed=$(awk -F ': ' '/cpu MHz/ {printf $2; exit}' /proc/cpuinfo)
|
||||||
speed=${speed/\./}
|
speed=${speed/\.}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Convert mhz to ghz without bc
|
# Convert mhz to ghz without bc
|
||||||
|
@ -625,8 +625,8 @@ getcpu () {
|
||||||
"OpenBSD")
|
"OpenBSD")
|
||||||
# Get cpu name
|
# Get cpu name
|
||||||
cpu="$(sysctl -n hw.model)"
|
cpu="$(sysctl -n hw.model)"
|
||||||
cpu=${cpu/ @*/}
|
cpu=${cpu/ @*}
|
||||||
cpu=${cpu// /}
|
cpu=${cpu// }
|
||||||
cpu=${cpu% }
|
cpu=${cpu% }
|
||||||
|
|
||||||
# Get cpu speed
|
# Get cpu speed
|
||||||
|
@ -637,8 +637,8 @@ getcpu () {
|
||||||
"FreeBSD")
|
"FreeBSD")
|
||||||
# Get cpu name
|
# Get cpu name
|
||||||
cpu="$(sysctl -n hw.model)"
|
cpu="$(sysctl -n hw.model)"
|
||||||
cpu=${cpu/ @*/}
|
cpu=${cpu/ @*}
|
||||||
cpu=${cpu// /}
|
cpu=${cpu// }
|
||||||
cpu=${cpu% }
|
cpu=${cpu% }
|
||||||
|
|
||||||
# Get cpu speed
|
# Get cpu speed
|
||||||
|
@ -649,15 +649,15 @@ getcpu () {
|
||||||
"NetBSD")
|
"NetBSD")
|
||||||
# Get cpu name
|
# Get cpu name
|
||||||
cpu="$(grep -F 'model name' /proc/cpuinfo)"
|
cpu="$(grep -F 'model name' /proc/cpuinfo)"
|
||||||
cpu=${cpu/model name*: /}
|
cpu=${cpu/model name*: }
|
||||||
cpu=${cpu/ @*/}
|
cpu=${cpu/ @*}
|
||||||
cpu=${cpu// /}
|
cpu=${cpu// }
|
||||||
cpu=${cpu% }
|
cpu=${cpu% }
|
||||||
|
|
||||||
# Get cpu speed
|
# Get cpu speed
|
||||||
speed="$(grep -F 'cpu MHz' /proc/cpuinfo)"
|
speed="$(grep -F 'cpu MHz' /proc/cpuinfo)"
|
||||||
speed=${speed/cpu MHz*: /}
|
speed=${speed/cpu MHz*: }
|
||||||
speed=${speed/\./}
|
speed=${speed/\.}
|
||||||
speed=$((speed / 10000))
|
speed=$((speed / 10000))
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
@ -669,15 +669,15 @@ getcpu () {
|
||||||
"Windows")
|
"Windows")
|
||||||
# Get cpu name
|
# Get cpu name
|
||||||
cpu="$(grep -F 'model name' /proc/cpuinfo)"
|
cpu="$(grep -F 'model name' /proc/cpuinfo)"
|
||||||
cpu=${cpu/model name*: /}
|
cpu=${cpu/model name*: }
|
||||||
cpu=${cpu/ @*/}
|
cpu=${cpu/ @*}
|
||||||
cpu=${cpu// /}
|
cpu=${cpu// }
|
||||||
cpu=${cpu% }
|
cpu=${cpu% }
|
||||||
|
|
||||||
# Get cpu speed
|
# Get cpu speed
|
||||||
speed=$(grep -F 'cpu MHz' /proc/cpuinfo)
|
speed=$(grep -F 'cpu MHz' /proc/cpuinfo)
|
||||||
speed=${speed/cpu MHz*: /}
|
speed=${speed/cpu MHz*: }
|
||||||
speed=${speed/\./}
|
speed=${speed/\.}
|
||||||
|
|
||||||
# Convert mhz to ghz without bc
|
# Convert mhz to ghz without bc
|
||||||
speed=$((speed / 100000))
|
speed=$((speed / 100000))
|
||||||
|
@ -692,14 +692,14 @@ getcpu () {
|
||||||
|
|
||||||
# Remove uneeded patterns from cpu output
|
# Remove uneeded patterns from cpu output
|
||||||
# This is faster than sed/gsub
|
# This is faster than sed/gsub
|
||||||
cpu=${cpu//'(tm)'}
|
cpu=${cpu//(tm)}
|
||||||
cpu=${cpu//'(TM)'}
|
cpu=${cpu//(TM)}
|
||||||
cpu=${cpu//'(r)'}
|
cpu=${cpu//(r)}
|
||||||
cpu=${cpu//'(R)'}
|
cpu=${cpu//(R)}
|
||||||
cpu=${cpu// 'CPU'}
|
cpu=${cpu// CPU}
|
||||||
cpu=${cpu// 'Processor'}
|
cpu=${cpu// Processor}
|
||||||
cpu=${cpu// 'Six-Core'}
|
cpu=${cpu// Six-Core}
|
||||||
cpu=${cpu// 'with Radeon HD Graphics'}
|
cpu=${cpu// with Radeon HD Graphics}
|
||||||
}
|
}
|
||||||
|
|
||||||
getgpu () {
|
getgpu () {
|
||||||
|
@ -712,30 +712,30 @@ getgpu () {
|
||||||
shopt -s nocasematch
|
shopt -s nocasematch
|
||||||
case "$gpu" in
|
case "$gpu" in
|
||||||
intel*)
|
intel*)
|
||||||
gpu=${gpu/'Intel Corporation' }
|
gpu=${gpu/Intel Corporation }
|
||||||
gpu=${gpu/'Haswell-'??? }
|
gpu=${gpu/Haswell-??? }
|
||||||
|
|
||||||
brand="Intel "
|
brand="Intel "
|
||||||
;;
|
;;
|
||||||
|
|
||||||
advanced*)
|
advanced*)
|
||||||
gpu=${gpu/'Advanced Micro Devices, Inc.' }
|
gpu=${gpu/Advanced Micro Devices, Inc\. }
|
||||||
gpu=${gpu/'[AMD/ATI]' }
|
gpu=${gpu/'[AMD/ATI]' }
|
||||||
gpu=${gpu/'Tahiti PRO'}
|
gpu=${gpu/Tahiti PRO}
|
||||||
gpu=${gpu/'Seymour'}
|
gpu=${gpu/Seymour}
|
||||||
gpu=${gpu/' ['}
|
gpu=${gpu/ \[}
|
||||||
gpu=${gpu/']'}
|
gpu=${gpu/\]}
|
||||||
|
|
||||||
brand="AMD "
|
brand="AMD "
|
||||||
;;
|
;;
|
||||||
|
|
||||||
nvidia*)
|
nvidia*)
|
||||||
gpu=${gpu/'NVIDIA Corporation' }
|
gpu=${gpu/NVIDIA Corporation }
|
||||||
gpu=${gpu/'nVidia Corporation' }
|
gpu=${gpu/nVidia Corporation }
|
||||||
gpu=${gpu/G????M }
|
gpu=${gpu/G????M }
|
||||||
gpu=${gpu/G???? }
|
gpu=${gpu/G???? }
|
||||||
gpu=${gpu/'['}
|
gpu=${gpu/\[}
|
||||||
gpu=${gpu/']'}
|
gpu=${gpu/\]}
|
||||||
|
|
||||||
brand="Nvidia "
|
brand="Nvidia "
|
||||||
;;
|
;;
|
||||||
|
@ -761,10 +761,10 @@ getgpu () {
|
||||||
case "$distro" in
|
case "$distro" in
|
||||||
"FreeBSD")
|
"FreeBSD")
|
||||||
gpu=$(pciconf -lv 2>/dev/null | grep -B 4 "VGA" | grep "device")
|
gpu=$(pciconf -lv 2>/dev/null | grep -B 4 "VGA" | grep "device")
|
||||||
gpu=${gpu/device*= /}
|
gpu=${gpu/device*= }
|
||||||
gpu=${gpu//\'/}
|
gpu=${gpu//\'}
|
||||||
gpu=${gpu//[[:space:]]/ }
|
gpu=${gpu//[[:space:]]/ }
|
||||||
gpu=${gpu// /}
|
gpu=${gpu// }
|
||||||
;;
|
;;
|
||||||
|
|
||||||
*)
|
*)
|
||||||
|
@ -776,20 +776,20 @@ getgpu () {
|
||||||
|
|
||||||
"Windows")
|
"Windows")
|
||||||
gpu=$(wmic path Win32_VideoController get caption)
|
gpu=$(wmic path Win32_VideoController get caption)
|
||||||
gpu=${gpu/Caption /}
|
gpu=${gpu/Caption }
|
||||||
gpu=${gpu//[[:space:]]/ }
|
gpu=${gpu//[[:space:]]/ }
|
||||||
gpu=${gpu// /}
|
gpu=${gpu// }
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [ "$gpu_shorthand" == "on" ]; then
|
if [ "$gpu_shorthand" == "on" ]; then
|
||||||
gpu=${gpu// 'Rev. '?}
|
gpu=${gpu// Rev\. ?}
|
||||||
gpu=${gpu//'AMD/ATI'/AMD}
|
gpu=${gpu//AMD\/ATI/AMD}
|
||||||
gpu=${gpu// 'Tahiti'}
|
gpu=${gpu// Tahiti}
|
||||||
gpu=${gpu// 'PRO'}
|
gpu=${gpu// PRO}
|
||||||
gpu=${gpu// 'OEM'}
|
gpu=${gpu// OEM}
|
||||||
gpu=${gpu// 'Mars'}
|
gpu=${gpu// Mars}
|
||||||
gpu=${gpu// 'Series'}
|
gpu=${gpu// Series}
|
||||||
gpu=${gpu/\/*}
|
gpu=${gpu/\/*}
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -806,10 +806,10 @@ getmemory () {
|
||||||
exec 6<&-
|
exec 6<&-
|
||||||
|
|
||||||
# Do some substitution on each line
|
# Do some substitution on each line
|
||||||
memtotal=${memtotal/MemTotal:/}
|
memtotal=${memtotal/MemTotal:}
|
||||||
memtotal=${memtotal/kB*/}
|
memtotal=${memtotal/kB*}
|
||||||
memavail=${memavail/MemAvailable:/}
|
memavail=${memavail/MemAvailable:}
|
||||||
memavail=${memavail/kB*/}
|
memavail=${memavail/kB*}
|
||||||
|
|
||||||
memused=$((memtotal - memavail))
|
memused=$((memtotal - memavail))
|
||||||
memory="$((memused / 1024))MB / $((memtotal / 1024))MB"
|
memory="$((memused / 1024))MB / $((memtotal / 1024))MB"
|
||||||
|
@ -827,11 +827,11 @@ getmemory () {
|
||||||
case "$distro" in
|
case "$distro" in
|
||||||
"OpenBSD")
|
"OpenBSD")
|
||||||
memtotal=$(dmesg | awk '/real mem/ {printf $5}')
|
memtotal=$(dmesg | awk '/real mem/ {printf $5}')
|
||||||
memtotal=${memtotal/\(/}
|
memtotal=${memtotal/\(}
|
||||||
memtotal=${memtotal/MB\)/}
|
memtotal=${memtotal/MB\)}
|
||||||
|
|
||||||
memfree=$(top -d 1 | awk '/Real:/ {printf $6}')
|
memfree=$(top -d 1 | awk '/Real:/ {printf $6}')
|
||||||
memfree=${memfree/M/}
|
memfree=${memfree/M}
|
||||||
|
|
||||||
memused=$((memtotal - memfree))
|
memused=$((memtotal - memfree))
|
||||||
memory="${memused}MB / ${memtotal}MB"
|
memory="${memused}MB / ${memtotal}MB"
|
||||||
|
@ -839,11 +839,11 @@ getmemory () {
|
||||||
|
|
||||||
"FreeBSD")
|
"FreeBSD")
|
||||||
memtotal=$(dmesg | awk '/real mem/ {printf $5}')
|
memtotal=$(dmesg | awk '/real mem/ {printf $5}')
|
||||||
memtotal=${memtotal/\(/}
|
memtotal=${memtotal/\(}
|
||||||
memtotal=${memtotal/MB\)/}
|
memtotal=${memtotal/MB\)}
|
||||||
|
|
||||||
memfree=$(top -d 1 | awk '/Mem:/ {printf $10}')
|
memfree=$(top -d 1 | awk '/Mem:/ {printf $10}')
|
||||||
memfree=${memfree/M/}
|
memfree=${memfree/M}
|
||||||
|
|
||||||
memused=$((memtotal - memfree))
|
memused=$((memtotal - memfree))
|
||||||
memory="${memused}MB / ${memtotal}MB"
|
memory="${memused}MB / ${memtotal}MB"
|
||||||
|
@ -953,15 +953,15 @@ getgtk () {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Format the strings
|
# Format the strings
|
||||||
gtk2theme=${gtk2theme/${name}*=/}
|
gtk2theme=${gtk2theme/${name}*=}
|
||||||
gtk2theme=${gtk2theme//\"/}
|
gtk2theme=${gtk2theme//\"}
|
||||||
|
|
||||||
[ "$gtk2theme" ] && \
|
[ "$gtk2theme" ] && \
|
||||||
gtk2theme="$gtk2theme [GTK2], "
|
gtk2theme="$gtk2theme [GTK2], "
|
||||||
|
|
||||||
# Format the string
|
# Format the string
|
||||||
gtk3theme=${gtk3theme/${name}*=/}
|
gtk3theme=${gtk3theme/${name}*=}
|
||||||
gtk3theme=${gtk3theme//\"/}
|
gtk3theme=${gtk3theme//\"}
|
||||||
gtk3theme=${gtk3theme/[[:space:]]/ }
|
gtk3theme=${gtk3theme/[[:space:]]/ }
|
||||||
gtktheme="${gtk2theme}${gtk3theme} [GTK3] "
|
gtktheme="${gtk2theme}${gtk3theme} [GTK3] "
|
||||||
|
|
||||||
|
|
Reference in New Issue