From 0f123081fdba7c1cfe88d8c1ce0e83b2313bc29d Mon Sep 17 00:00:00 2001 From: q3aql Date: Fri, 15 Apr 2022 20:20:42 +0200 Subject: [PATCH] Dotfiles config update (2022-04-15) --- .bashrc | 25 +++++++++++++++++++++---- .config/fish/config.fish | 17 ++++++++++++++++- .zshrc | 25 +++++++++++++++++++++---- 3 files changed, 58 insertions(+), 9 deletions(-) diff --git a/.bashrc b/.bashrc index 8d54109..28afacc 100644 --- a/.bashrc +++ b/.bashrc @@ -160,11 +160,28 @@ else os_system=$(echo ${os_system}) fi kernel=$(uname -r) -uptime=$(uptime 2> /dev/null | tr -s " " | cut -d "," -f 1) -if [ -z "${uptime}" ] ; then - uptime="Unknown" +if [ -f /proc/uptime ] ; then + uptime_sec=$(cat /proc/uptime) + uptime_sec_cut=$(echo ${uptime_sec} | tr -s " " | cut -d " " -f 1 | cut -d "." -f 1) + uptime_min=$(expr ${uptime_sec_cut} / 60) + if [ ${uptime_min} -le 59 ] ; then + uptime="${uptime_min}min" + else + uptime_hour=$(expr ${uptime_min} / 60) + if [ ${uptime_hour} -le 23 ] ; then + uptime="${uptime_hour}h" + else + uptime_day=$(expr ${uptime_hour} / 24) + uptime="${uptime_day}d" + fi + fi else - uptime=$(echo ${uptime}) + uptime=$(uptime 2> /dev/null | tr -s " " | cut -d "," -f 1) + if [ -z "${uptime}" ] ; then + uptime="Unknown" + else + uptime=$(echo ${uptime}) + fi fi #shell="5.1.4" # Run bash --version shell=$(bash --version | head -1 | tr -s " " | cut -d " " -f 4 | cut -d "(" -f 1 | cut -d "-" -f 1) diff --git a/.config/fish/config.fish b/.config/fish/config.fish index 13dd9d5..56c97bf 100644 --- a/.config/fish/config.fish +++ b/.config/fish/config.fish @@ -28,7 +28,22 @@ else set os_system (uname -o) end set kernel (uname -r) -if test -f /usr/bin/uptime +if test -f /proc/uptime + set uptime_sec (cat /proc/uptime) + set uptime_sec_cut (echo $uptime_sec | tr -s " " | cut -d " " -f 1 | cut -d "." -f 1) + set uptime_min (expr $uptime_sec_cut / 60) + if test "$uptime_min" -le "59" + set uptime {$uptime_min}min + else + set uptime_hour (expr $uptime_min / 60) + if test "$uptime_hour" -le "23" + set uptime {$uptime_hour}h + else + set uptime_day (expr $uptime_hour / 24) + set uptime {$uptime_day}d + end + end +else if test -f /usr/bin/uptime set uptime (uptime | tr -s " " | cut -d "," -f 1) set uptime (echo {$uptime} | cut -f 2) else diff --git a/.zshrc b/.zshrc index 9bb8f96..86d6036 100644 --- a/.zshrc +++ b/.zshrc @@ -252,11 +252,28 @@ echo "" echo -e -n "\e[32m# Preparing to start \e[0m\e[35mzsh\e[0m \e[32mshell...\e[0m" os_system=$(uname -o) kernel=$(uname -r) -uptime=$(uptime 2> /dev/null | tr -s " " | cut -d "," -f 1) -if [ -z "${uptime}" ] ; then - uptime="Unknown" +if [ -f /proc/uptime ] ; then + uptime_sec=$(cat /proc/uptime) + uptime_sec_cut=$(echo ${uptime_sec} | tr -s " " | cut -d " " -f 1 | cut -d "." -f 1) + uptime_min=$(expr ${uptime_sec_cut} / 60) + if [ ${uptime_min} -le 59 ] ; then + uptime="${uptime_min}min" + else + uptime_hour=$(expr ${uptime_min} / 60) + if [ ${uptime_hour} -le 23 ] ; then + uptime="${uptime_hour}h" + else + uptime_day=$(expr ${uptime_hour} / 24) + uptime="${uptime_day}d" + fi + fi else - uptime=$(echo ${uptime}) + uptime=$(uptime 2> /dev/null | tr -s " " | cut -d "," -f 1) + if [ -z "${uptime}" ] ; then + uptime="Unknown" + else + uptime=$(echo ${uptime}) + fi fi #shell="5.8" # Run zsh --version shell=$(zsh --version | cut -d " " -f 2)