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

View File

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