Merge pull request #184 from dylanaraps/cleanup

Info function cleanup
This commit is contained in:
Dylan Araps 2016-03-27 12:22:59 +11:00
commit 65b7c2fc50
2 changed files with 26 additions and 68 deletions

7
1.6.md
View File

@ -16,15 +16,19 @@ Thanks to the following people for contributing this release.
- Fixed buggy colors in older versions of \*BSD, OS X and Linux.
- Added Travis CI support.
- Added `--test` which prints all functions.
- Cleanup of Distro, Uptime and CPU functions.
### Info
- Functions now no longer print `Unknown` when they fail, they now don't appear at all.
**OS**<br \>
- [ CRUX ] Also print the CRUX version. **[@onodera-punpun](https://github.com/onodera-punpun)**
**CPU**<br \>
- [ Windows ] Don't print CPU cores if detection fails.
- [ BSD ] Fixed extremely long output.
- Fixed broken CPU speed when source is `/proc/cpuinfo`.
**GPU**<br \>
- Don't show GPU output on unsupported OS.
@ -46,10 +50,12 @@ Thanks to the following people for contributing this release.
**Song**<br \>
- [ MPD ] Fixed function when mpd is running on another PC and not your own.
- Song now displays `Not Playing` instead of `Unknown` when no music player is found.
- Added support for Google Play Music Desktop Player (adds optional dependency of [`gpmdp-bash`](https://github.com/iandrewt/gpmdp-bash)) **[@iandrewt](https://github.com/iandrewt)**
**Disk**<br \>
- Added new display option `perc` to display just the percentage with the progress bar.
- Fixed disk usage not working on FreeBSD.
**Memory**<br \>
- [ OpenBSD ] Fixed completely broken memory output on OpenBSD.
@ -74,6 +80,7 @@ Thanks to the following people for contributing this release.
- Added ascii art for Qubes OS.
- Added ascii art for Travis CI.
- Revamped Alpine Linux's ascii art.
- Fixed missing ascii colors for Puppy Linux.
- [ OSX ] Fixed incorrect text colors.

View File

@ -456,21 +456,18 @@ x32="x86"
case "$os" in
"Linux" )
if type -p lsb_release >/dev/null 2>&1; then
distro="$(lsb_release -d 2>/dev/null | awk -F':' '/Description/ {printf $2}')"
distro="$(lsb_release -d 2>/dev/null | awk -F ':' '/Description/ {printf $2}')"
distro=${distro/[[:space:]]}
elif type -p crux >/dev/null 2>&1; then
distro="$(crux)"
else
distro="$(grep -h '^NAME=' /etc/*ease)"
distro="$(awk -F 'NAME="|"' '/^NAME=/ {printf $2}' /etc/*ease)"
# Workaround for distros that store the value differently.
[ -z "$distro" ] && distro="$(grep -h 'TAILS_PRODUCT_NAME' /etc/*ease)"
[ -z "$distro" ] && distro="$(awk -F 'TAILS_PRODUCT_NAME="|"' '/^TAILS_PRODUCT_NAME=/ {printf $2}' /etc/*ease)"
[ -z "$distro" ] && distro="$(awk '/BLAG/ {print $1; exit}' /etc/*ease)"
distro=${distro/*NAME\=}
distro=${distro//\"}
fi
;;
@ -514,10 +511,6 @@ case "$os" in
x64="64-bit"
x32="32-bit"
;;
*)
distro="Unknown"
;;
esac
ascii_distro="$distro"
@ -557,9 +550,9 @@ getkernel() {
getuptime () {
case "$os" in
"Linux")
"Linux" | "Windows")
case "$distro" in
"Puppy Linux"* | "Quirky Werewolf"* | "Precise Puppy"* | "Alpine Linux"*)
*"Puppy"* | "Quirky Werewolf"* | "Alpine Linux"* | "Windows"*)
uptime=$(uptime | awk -F ':[0-9]{2}+ |(, ){1}+' '{printf $2}')
uptime=${uptime/ / }
;;
@ -612,15 +605,6 @@ getuptime () {
uptime="up $uptime"
;;
"Windows")
uptime=$(uptime | awk -F ':[0-9]{2}+ |(, ){1}+' '{printf $2}')
uptime=${uptime/ / }
;;
*)
uptime="Unknown"
;;
esac
# Make the output of uptime smaller.
@ -740,8 +724,6 @@ getpackages () {
;;
esac
packages=${packages// }
[ -z "$packages" ] && packages="Unknown"
}
# }}}
@ -827,11 +809,7 @@ getcpu () {
case "$os" in
"Linux")
# Get cpu name
cpu="$(grep -F 'model name' /proc/cpuinfo)"
cpu=${cpu/model name*: }
cpu=${cpu/ @*}
cpu=${cpu// }
cpu=${cpu%% }
cpu="$(awk -F ': | @' '/model name/ {printf $2; exit}' /proc/cpuinfo)"
# Get cpu speed
if [ -d "/sys/devices/system/cpu/cpu0/cpufreq" ]; then
@ -848,13 +826,11 @@ getcpu () {
read -r speed < \
/sys/devices/system/cpu/cpu0/cpufreq/${speed_type}
speed=$((speed / 100000))
else
speed=$(awk -F ': ' '/cpu MHz/ {printf $2; exit}' /proc/cpuinfo)
speed=${speed/\.}
speed=$(awk -F ': |\\.' '/cpu MHz/ {printf $2; exit}' /proc/cpuinfo)
speed=$((speed / 100))
fi
# Convert mhz to ghz without bc
speed=$((speed / 100000))
speed=${speed:0:1}.${speed:1}
cpu="$cpu @ ${speed}GHz"
@ -910,10 +886,6 @@ getcpu () {
speed=${speed:0:1}.${speed:1}
cpu="$cpu @ ${speed}GHz"
;;
*)
cpu="Unknown"
;;
esac
# Remove uneeded patterns from cpu output
@ -982,7 +954,8 @@ getgpu () {
# If a GPU with a prefix of '3D' doesn't exist
# fallback to looking for a prefix of 'VGA'
[ -z "$gpu" ] && \
gpu="$(PATH="/sbin:$PATH" lspci | grep -F "VGA")"
gpu="$(PATH="/sbin:$PATH" lspci | grep -F "VGA")"
gpu=${gpu//??':'??'.'?}
# Count the number of GPUs
@ -1171,10 +1144,6 @@ getmemory () {
memory="$((${memused%% *} / 1024))MB / "
memory+="$((${memtotal%% *} / 1024))MB"
;;
*)
memory="Unknown"
;;
esac
# Progress bars
@ -1235,7 +1204,7 @@ getsong () {
state="$(osascript -e 'tell application "iTunes" to player state as string')"
else
song="Unknown"
song="Not Playing"
fi
case "$state" in
@ -1307,10 +1276,6 @@ getresolution () {
[ ! -z "$width" ] && \
resolution="${width}x${height}"
;;
"*")
resolution="Unknown"
;;
esac
resolution=${resolution%,*}
@ -1520,9 +1485,8 @@ getdisk () {
"Mac OS X") df_flags="-H / -l" ;;
*"BSD")
case "$os" in
"FreeBSD") df_flags="-h -c -l" ;;
*) disk="Unknown"; return ;;
case "$distro" in
"FreeBSD"*) df_flags="-h -c -l" ;;
esac
;;
esac
@ -1602,8 +1566,6 @@ getbattery () {
fi
battery="${batteries[0]}%"
fi
else
battery="None"
fi
;;
@ -1678,10 +1640,6 @@ getlocalip () {
"Windows")
localip="$(ipconfig | awk -F ': ' '/IPv4 Address/ {printf $2}')"
;;
*)
localip="Unknown"
;;
esac
}
@ -1694,9 +1652,6 @@ getpublicip () {
elif type -p wget >/dev/null 2>&1; then
publicip="$(wget -qO- "$public_ip_host"; printf "%s")"
else
publicip="Unknown"
fi
}
@ -1756,10 +1711,6 @@ getbirthday () {
birthday="$(ls -alctT /etc/defaults/rc.conf | awk '{printf $6 " " $7 " " $9 " " $8}')"
birthday_shorthand="on"
;;
*)
birthday="Unknown"
;;
esac
;;
@ -1767,11 +1718,6 @@ getbirthday () {
birthday="$(ls -alct --full-time /cygdrive/c/Windows/explorer.exe | awk '{printf $8 " " $9}')"
date_cmd="$(date -d"$birthday" +"$birthday_format")"
;;
*)
birthday="Unknown"
;;
esac
# Strip seconds from time output
@ -2324,6 +2270,11 @@ colors () {
setcolors 4 7 1
;;
"Puppy"* | "Quirky Werewolf"* | "Precise Puppy"*)
setcolors 4
ascii_distro="puppy"
;;
"Scientific"*)
setcolors 4 1 7
;;