Updated uptime display so it works when no days are displayed
This commit is contained in:
parent
fbba2d170a
commit
97b5e068e5
@ -111,62 +111,65 @@
|
|||||||
set NC '\033[0m'
|
set NC '\033[0m'
|
||||||
|
|
||||||
function display_slider # used total
|
function display_slider # used total
|
||||||
set -l slider_length 39
|
set -l slider_length 39
|
||||||
set -l used $argv[1]
|
set -l used $argv[1]
|
||||||
set -l total $argv[2]
|
set -l total $argv[2]
|
||||||
set -l used_slider (math -s0 "($used * $slider_length) / $total")
|
set -l used_slider (math -s0 "($used * $slider_length) / $total")
|
||||||
set -l unused_slider (math -s0 "$slider_length - $used_slider")
|
set -l unused_slider (math -s0 "$slider_length - $used_slider")
|
||||||
echo -en "["
|
echo -en "["
|
||||||
echo -en $RED
|
echo -en $RED
|
||||||
echo -en (string repeat -n $used_slider '=')
|
echo -en (string repeat -n $used_slider '=')
|
||||||
echo -en $GREEN
|
echo -en $GREEN
|
||||||
echo -en (string repeat -n $unused_slider '=')
|
echo -en (string repeat -n $unused_slider '=')
|
||||||
echo -en $NC
|
echo -en $NC
|
||||||
echo -en "]"
|
echo -en "]"
|
||||||
end
|
end
|
||||||
|
|
||||||
function fish_greeting
|
function fish_greeting
|
||||||
set -l ruler_length 79
|
set -l ruler_length 79
|
||||||
set -l ruler (string repeat -n $ruler_length "=")
|
set -l ruler (string repeat -n $ruler_length "=")
|
||||||
|
|
||||||
set -l osname (cat /etc/os-release | grep -i pretty_name | sed 's/.*"\(.*\)".*/\1/')
|
set -l osname (cat /etc/os-release | grep -i pretty_name | sed 's/.*"\(.*\)".*/\1/')
|
||||||
|
set -l uptime (uptime | sed 's/\(.*\):\(.*\):\(.*\) up.*/\1 hours \2 minutes/' | sed 's/ *\(.*\)/\1/')
|
||||||
|
|
||||||
set -l uptime (uptime | awk '{print $1}' | string split ':')
|
set -l root (df -Ph | grep -E "/\$")
|
||||||
set -l uptime_days (uptime | awk '{print $3}')
|
set -l root_p (echo $root | awk '{print $5}' | tr -d '%')
|
||||||
|
set -l root_used (echo $root | awk '{print $3}')
|
||||||
|
set -l root_total (echo $root | awk '{print $2}')
|
||||||
|
|
||||||
set -l root (df -Ph | grep -E "/\$")
|
set -l ram (free -tm | grep Mem)
|
||||||
set -l root_p (echo $root | awk '{print $5}' | tr -d '%')
|
set -l ram_total (echo $ram | awk '{print $2}')
|
||||||
set -l root_used (echo $root | awk '{print $3}')
|
set -l ram_used (echo $ram | awk '{print $3}')
|
||||||
set -l root_total (echo $root | awk '{print $2}')
|
set -l ram_p (math -s0 "$ram_used / $ram_total * 100")
|
||||||
set -l home (df -Ph | grep -E "/home\$")
|
|
||||||
set -l home_p (echo $home | awk '{print $5}' | tr -d '%')
|
|
||||||
set -l home_used (echo $home | awk '{print $3}')
|
|
||||||
set -l home_total (echo $home | awk '{print $2}')
|
|
||||||
|
|
||||||
set -l ram (free -tm | grep Mem)
|
set -l swap (free -tm | grep Swap)
|
||||||
set -l ram_total (echo $ram | awk '{print $2}')
|
set -l swap_total (echo $swap | awk '{print $2}')
|
||||||
set -l ram_used (echo $ram | awk '{print $3}')
|
set -l swap_used (echo $swap | awk '{print $3}')
|
||||||
set -l ram_p (math -s0 "$ram_used / $ram_total * 100")
|
set -l swap_p (math -s0 "$swap_used / $swap_total * 100")
|
||||||
|
|
||||||
set -l swap (free -tm | grep Swap)
|
set -l connections (nmcli c s | grep -E "wifi|ethernet" | grep -v '\-\-')
|
||||||
set -l swap_total (echo $swap | awk '{print $2}')
|
set -l wifi (echo $connections | grep "wifi" | awk '{print $1}')
|
||||||
set -l swap_used (echo $swap | awk '{print $3}')
|
set -l ethernet (test "$connections" = "*ethernet*" && echo -e $GREEN"UP"$NC || echo -e $RED"DOWN"$NC)
|
||||||
set -l swap_p (math -s0 "$swap_used / $swap_total * 100")
|
set -l wifi (test -n wifi && echo -e $GREEN$wifi$NC || echo - $RED"DOWN"$NC)
|
||||||
|
|
||||||
set -l connections (nmcli c s | grep -E "wifi|ethernet" | grep -v '\-\-')
|
echo $ruler
|
||||||
set -l wifi (echo $connections | grep "wifi" | awk '{print $1}')
|
printf "OS......: %-30sKernel: %s %s\n" $osname (uname -s) (uname -r)
|
||||||
set -l ethernet (test "$connections" = "*ethernet*" && echo -e $GREEN"UP"$NC || echo -e $RED"DOWN"$NC)
|
printf "Hostname: %-30sUptime: %s\n" (hostname) $uptime
|
||||||
set -l wifi (test -n wifi && echo -e $GREEN$wifi$NC || echo - $RED"DOWN"$NC)
|
printf "Ethernet: %-41sWifi..: %s\n" $ethernet $wifi
|
||||||
|
printf "Disks...: %-5s %s %6s / %6s (%2d%%)\n" "/" (display_slider $root_p 100) $root_used $root_total $root_p
|
||||||
|
|
||||||
echo $ruler
|
# loop other mountpoints
|
||||||
printf "OS......: %-30sKernel: %s %s\n" $osname (uname -s) (uname -r)
|
for mp in (df -Ph 2> /dev/null | egrep "sd|tank" | egrep -v "boot|/\$")
|
||||||
printf "Hostname: %-30sUptime: %d days, %d hours, %d minutes\n" (hostname) $uptime_days $uptime[1] $uptime[2]
|
set -l mp_p (echo $mp | awk '{print $5}' | tr -d '%')
|
||||||
printf "Ethernet: %-41sWifi: %s\n" $ethernet $wifi
|
set -l mp_used (echo $mp | awk '{print $3}')
|
||||||
printf "Disks...: %-5s %s %6s / %6s (%2d%%)\n" "/" (display_slider $root_p 100) $root_used $root_total $root_p
|
set -l mp_total (echo $mp | awk '{print $2}')
|
||||||
printf " %-5s %s %6s / %6s (%2d%%)\n" "/home" (display_slider $home_p 100) $home_used $home_total $home_p
|
set -l mp_name (echo $mp | awk '{print $6}')
|
||||||
printf "Ram.....: %s %5dM / %5dM (%2d%%)\n" (display_slider $ram_used $ram_total) $ram_used $ram_total $ram_p
|
printf " %-5s %s %6s / %6s (%2d%%)\n" $mp_name (display_slider $mp_p 100) $mp_used $mp_total $mp_p
|
||||||
printf "Swap....: %s %5dM / %5dM (%2d%%)\n" (display_slider $swap_used $swap_total) $swap_used $swap_total $swap_p
|
end
|
||||||
echo $ruler
|
|
||||||
|
printf "Ram.....: %s %5dM / %5dM (%2d%%)\n" (display_slider $ram_used $ram_total) $ram_used $ram_total $ram_p
|
||||||
|
printf "Swap....: %s %5dM / %5dM (%2d%%)\n" (display_slider $swap_used $swap_total) $swap_used $swap_total $swap_p
|
||||||
|
echo $ruler
|
||||||
end
|
end
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user