Merge pull request #599 from dylanaraps/disk_show2

Disk: Add option to specify which disks to show
This commit is contained in:
Dylan Araps 2017-01-08 19:13:42 +11:00 committed by GitHub
commit 45b852c6ff
3 changed files with 113 additions and 16 deletions

View file

@ -32,7 +32,7 @@ print_info() {
info "Memory" memory info "Memory" memory
# info "CPU Usage" cpu_usage # info "CPU Usage" cpu_usage
# info "Disk (root)" disk # info "Disk" disk
# info "Battery" battery # info "Battery" battery
# info "Font" font # info "Font" font
# info "Song" song # info "Song" song
@ -230,6 +230,7 @@ gpu_brand="on"
# GPU1: Intel Integrated Graphics # GPU1: Intel Integrated Graphics
gpu_type="all" gpu_type="all"
# Resolution # Resolution
@ -294,6 +295,43 @@ gtk3="on"
public_ip_host="http://ident.me" public_ip_host="http://ident.me"
# Disk
# Which disks to display.
# The values can be any /dev/sdXX, mount point or directory.
# NOTE: By default we only show the disk info for '/'.
#
# Default: '/'
# Values: '/', '/dev/sdXX', '/path/to/drive'.
# Flag: --disk_show
#
# Example:
# disk_show=('/' '/dev/sdb1'):
# 'Disk (/): 74G / 118G (66%)'
# 'Disk (/mnt/Videos): 823G / 893G (93%)'
#
# disk_show=('/'):
# 'Disk (/): 74G / 118G (66%)'
#
disk_show=('/')
# Disk subtitle.
# What to append to the Disk subtitle.
#
# Default: 'mount'
# Values: 'mount', 'name'
# Flag: --disk_subtitle
#
# Example:
# name: 'Disk (/dev/sda1): 74G / 118G (66%)'
# 'Disk (/dev/sdb2): 74G / 118G (66%)'
#
# mount: 'Disk (/): 74G / 118G (66%)'
# 'Disk (/mnt/Local Disk): 74G / 118G (66%)'
disk_subtitle="mount"
# Song # Song

View file

@ -11,6 +11,7 @@
bash_version="${BASH_VERSION/.*}" bash_version="${BASH_VERSION/.*}"
sys_locale="${LANG:-C}" sys_locale="${LANG:-C}"
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-${HOME}/.config}" XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-${HOME}/.config}"
old_ifs="$IFS"
# Speed up script by not using unicode. # Speed up script by not using unicode.
export LC_ALL=C export LC_ALL=C
@ -996,7 +997,9 @@ get_gpu() {
case "$os" in case "$os" in
"Linux") "Linux")
# Read GPUs into array. # Read GPUs into array.
readarray gpus < <(lspci -mm | awk -F '\\"|\\" \\"' '/"Display|"3D|"VGA/ {print $3 " " $4}') IFS=$'\n'
gpus=($(lspci -mm | awk -F '\\"|\\" \\"' '/"Display|"3D|"VGA/ {print $3 " " $4}'))
IFS="$old_ifs"
# Number the GPUs if more than one exists. # Number the GPUs if more than one exists.
((${#gpus[@]} > 1)) && gpu_num=1 ((${#gpus[@]} > 1)) && gpu_num=1
@ -1627,24 +1630,44 @@ get_disk() {
# Get "df" flags. # Get "df" flags.
case "$os" in case "$os" in
"Haiku") err "Disk doesn't work on Haiku due to the non-standard 'df'"; return ;; "Haiku") err "Disk doesn't work on Haiku due to the non-standard 'df'"; return ;;
"Minix") df_flags=(-h) ;; "Mac OS X") df_flags=(-P -h) ;;
*) df_flags=(-P -h) ;; *) df_flags=(-h) ;;
esac esac
# Get the info for "/". # Create an array called 'disks' where each element is a separate line from
disks=($(df "${df_flags[@]}" /)) || { err "Disk: 'df' exited with error code 1"; return; } # df's output. We then unset the first element which removes the column titles.
IFS=$'\n'
disks=($(df "${df_flags[@]}" "${disk_show[@]:-/}")) && unset 'disks[0]'
IFS="$old_ifs"
# Put it all together. # Stop here if 'df' fails to print disk info.
disk_perc="${disks[11]/'%'}" [[ -z "${disks[@]}" ]] && \
disk="${disks[9]/i} / ${disks[8]/i} (${disk_perc}%)" { err "Disk: df failed to print the disks, make sure the disk_show array is set properly."; return; }
# Bar. for disk in "${disks[@]}"; do
case "$disk_display" in # Create a second array and make each element split at whitespace this time.
"bar") disk="$(bar "$disk_perc" "100")" ;; disk_info=($disk)
"infobar") disk+=" $(bar "$disk_perc" "100")" ;; disk_perc="${disk_info[4]/'%'}"
"barinfo") disk="$(bar "$disk_perc" "100") $disk" ;;
"perc") disk="${disk_perc}% $(bar "$disk_perc" "100")" ;; disk="${disk_info[2]/i} / ${disk_info[1]/i} (${disk_perc}%)"
esac
# Subtitle
case "$disk_subtitle" in
"name") disk_sub="${disk_info[0]}" ;;
*) disk_sub="${disk_info[5]}" ;;
esac
# Bar.
case "$disk_display" in
"bar") disk="$(bar "$disk_perc" "100")" ;;
"infobar") disk+=" $(bar "$disk_perc" "100")" ;;
"barinfo") disk="$(bar "$disk_perc" "100") $disk" ;;
"perc") disk="${disk_perc}% $(bar "$disk_perc" "100")" ;;
esac
# Append '(disk mount point)' to the subtitle.
prin "${subtitle} (${disk_sub})" "$disk"
done
} }
get_battery() { get_battery() {
@ -3558,6 +3581,17 @@ INFO:
--gtk3 on/off Enable/Disable gtk3 theme/font/icons output --gtk3 on/off Enable/Disable gtk3 theme/font/icons output
--shell_path on/off Enable/Disable showing \$SHELL path --shell_path on/off Enable/Disable showing \$SHELL path
--shell_version on/off Enable/Disable showing \$SHELL version --shell_version on/off Enable/Disable showing \$SHELL version
--disk_show value Which disks to display.
Takes: '/', '/dev/sdXX', '/path/to/mount point'
NOTE: Multiple values can be given. (--disk_show '/' '/dev/sdc1')
--disk_subtitle name/mount What information to append to the Disk subtitle.
'name' shows the disk's name (sda1, sda2, etc)
'mount' shows the disk's mount point (/, /mnt/Local Disk, etc)
--ip_host url URL to query for public IP --ip_host url URL to query for public IP
--song_shorthand on/off Print the Artist/Title on separate lines --song_shorthand on/off Print the Artist/Title on separate lines
--install_time on/off Enable/Disable showing the time in Install Date output. --install_time on/off Enable/Disable showing the time in Install Date output.
@ -3722,6 +3756,18 @@ get_args() {
[[ "$cpu_temp" == "on" ]] && cpu_temp="C" [[ "$cpu_temp" == "on" ]] && cpu_temp="C"
;; ;;
"--disk_subtitle") disk_subtitle="$2" ;;
"--disk_show")
unset disk_show
for arg in "$@"; do
case "$arg" in
"--disk_show") ;;
"-"*) break ;;
*) disk_show+=($arg)
esac
done
;;
"--disable") "--disable")
for func in "$@"; do for func in "$@"; do
case "$func" in case "$func" in

View file

@ -90,6 +90,19 @@ Enable/Disable showing $SHELL path
\fB\-\-shell_version\fR on/off \fB\-\-shell_version\fR on/off
Enable/Disable showing $SHELL version Enable/Disable showing $SHELL version
.TP .TP
\fB\-\-disk_show\fR value
Which disks to display.
Takes: '/', '/dev/sdXX', '/path/to/mount point'
.IP
NOTE: Multiple values can be given. (\fB\-\-disk_show\fR '/' '/dev/sdc1')
.TP
\fB\-\-disk_subtitle\fR name/mount
What information to append to the Disk subtitle.
.IP
\&'name' shows the disk's name (sda1, sda2, etc)
.IP
\&'mount' shows the disk's mount point (/, \fI\,/mnt/Local\/\fP Disk, etc)
.TP
\fB\-\-ip_host\fR url \fB\-\-ip_host\fR url
URL to query for public IP URL to query for public IP
.TP .TP