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 "CPU Usage" cpu_usage
# info "Disk (root)" disk
# info "Disk" disk
# info "Battery" battery
# info "Font" font
# info "Song" song
@ -230,6 +230,7 @@ gpu_brand="on"
# GPU1: Intel Integrated Graphics
gpu_type="all"
# Resolution
@ -294,6 +295,43 @@ gtk3="on"
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

View File

@ -11,6 +11,7 @@
bash_version="${BASH_VERSION/.*}"
sys_locale="${LANG:-C}"
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-${HOME}/.config}"
old_ifs="$IFS"
# Speed up script by not using unicode.
export LC_ALL=C
@ -996,7 +997,9 @@ get_gpu() {
case "$os" in
"Linux")
# 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.
((${#gpus[@]} > 1)) && gpu_num=1
@ -1627,16 +1630,32 @@ get_disk() {
# Get "df" flags.
case "$os" in
"Haiku") err "Disk doesn't work on Haiku due to the non-standard 'df'"; return ;;
"Minix") df_flags=(-h) ;;
*) df_flags=(-P -h) ;;
"Mac OS X") df_flags=(-P -h) ;;
*) df_flags=(-h) ;;
esac
# Get the info for "/".
disks=($(df "${df_flags[@]}" /)) || { err "Disk: 'df' exited with error code 1"; return; }
# Create an array called 'disks' where each element is a separate line from
# 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.
disk_perc="${disks[11]/'%'}"
disk="${disks[9]/i} / ${disks[8]/i} (${disk_perc}%)"
# Stop here if 'df' fails to print disk info.
[[ -z "${disks[@]}" ]] && \
{ err "Disk: df failed to print the disks, make sure the disk_show array is set properly."; return; }
for disk in "${disks[@]}"; do
# Create a second array and make each element split at whitespace this time.
disk_info=($disk)
disk_perc="${disk_info[4]/'%'}"
disk="${disk_info[2]/i} / ${disk_info[1]/i} (${disk_perc}%)"
# Subtitle
case "$disk_subtitle" in
"name") disk_sub="${disk_info[0]}" ;;
*) disk_sub="${disk_info[5]}" ;;
esac
# Bar.
case "$disk_display" in
@ -1645,6 +1664,10 @@ get_disk() {
"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() {
@ -3558,6 +3581,17 @@ INFO:
--gtk3 on/off Enable/Disable gtk3 theme/font/icons output
--shell_path on/off Enable/Disable showing \$SHELL path
--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
--song_shorthand on/off Print the Artist/Title on separate lines
--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"
;;
"--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")
for func in "$@"; do
case "$func" in

View File

@ -90,6 +90,19 @@ Enable/Disable showing $SHELL path
\fB\-\-shell_version\fR on/off
Enable/Disable showing $SHELL version
.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
URL to query for public IP
.TP