Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
neofetch
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ximper Linux
neofetch
Commits
d9e15e35
Commit
d9e15e35
authored
Oct 21, 2016
by
Dylan Araps
Committed by
GitHub
Oct 21, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #380 from dylanaraps/uptime-fix
Rewrite uptime for Linux/Windows/Solaris to match macOS/BSD
parents
b887756c
86cfc366
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
47 deletions
+26
-47
neofetch
neofetch
+26
-47
No files found.
neofetch
View file @
d9e15e35
...
...
@@ -268,73 +268,52 @@ getkernel() {
# Uptime {{{
getuptime() {
# Get uptime in seconds
case "
$os
" in
"
Linux
" | "
Windows
")
case "
$distro
" in
*"
Puppy
"* | "
Quirky
Werewolf
"* | "
Alpine
Linux
"* | "
OpenWRT
"* | "
Windows
"*)
uptime="
$(
uptime
|
awk
-F
':[0-9]{2}+ |(, ){1}+'
'{printf $2}'
)
"
;;
"
openSUSE
"*)
uptime="
$(
uptime
|
awk
-F
':[0-9]{2}+[a-z][a-z] |(, ){1}+'
'{printf $2}'
)
"
;;
*)
uptime="
$(
uptime
-p
)
"
[ "
$uptime
" == "
up
" ] && uptime="
up
$(
awk
-F
'.'
'{print $1}'
/proc/uptime
)
seconds
"
;;
esac
seconds="
$(
< /proc/uptime
)
"
seconds="
${
seconds
/.*
}
"
;;
"
Mac
OS X
" | "
iPhone
OS
" | "
BSD
")
# Get boot time in seconds
boot="
$(
sysctl
-n
kern.boottime
)
"
boot="
${
boot
/
'{ sec = '
}
"
boot="
${
boot
/,*
}
"
# Get current date in seconds
now="
$(
date
+%s
)
"
uptime="
$((
now
-
boot
))
"
# Convert uptime to days/hours/mins
minutes="
$((
uptime
/
60
%
60
))
"
hours="
$((
uptime
/
3600
%
24
))
"
days="
$((
uptime
/
86400
))
"
seconds="
$((
now
-
boot
))
"
;;
case "
$minutes
" in
1) minutes="
1
minute
" ;;
0) unset minutes ;;
*) minutes="
$minutes
minutes
"
;;
"
Solaris
")
seconds="
$(
kstat
-p
unix:0:system_misc:snaptime |
awk
'{print $2}'
)
"
seconds="
${
seconds
/.*
}
"
;;
esac
case "
$hours
" in
1) hours="
1
hour
" ;;
0) unset hours ;;
*) hours="
$hours
hours
" ;;
esac
days="
$((
seconds
/
60
/
60
/
24
))
days
"
hours="
$((
seconds
/
60
/
60
%
24
))
hours
"
minutes="
$((
seconds
/
60
%
60
))
minutes
"
case "
$days
" in
1) days="
1
day
" ;;
0) unset days ;;
*) days="
$days
days
" ;;
"
0
days
") unset days ;;
"
1
days
") days="
${
days
/s
}
" ;;
esac
[ "
$hours
" ] &&
\
[ "
$minutes
" ] &&
\
hours+="
,
"
[ "
$days
" ] &&
\
[ "
$hours
" ] &&
\
days+="
,
"
uptime="
up
$days
$hours
$minutes
"
;;
case "
$hours
" in
"
0
hours
") unset hours ;;
"
1
hours
") hours="
${
hours
/s
}
" ;;
esac
"
Solaris
")
uptime="
$(
uptime
| /usr/xpg4/bin/awk
-F
':[0-9]{2}+[a-z][a-z] |(, ){1}+'
'{printf $2}'
)
"
;;
case "
$minutes
" in
"
0
minutes
") unset minutes ;;
"
1
minutes
") minutes="
${
minutes
/s
}
"
;;
esac
uptime="
${
days
:+
$days
,
}${
hours
:+
$hours
,
}${
minutes
}
"
uptime="
${
uptime
%
', '
}
"
uptime="
up
${
uptime
:-${
seconds
}
seconds
}
"
# Make the output of uptime smaller.
case "
$uptime_shorthand
" in
"
on
")
...
...
@@ -353,7 +332,7 @@ getuptime() {
uptime="
${
uptime
/ minutes/m
}
"
uptime="
${
uptime
/ minute/m
}
"
uptime="
${
uptime
/ seconds/s
}
"
uptime="
${
uptime
/,
}
"
uptime="
${
uptime
/
/
,
}
"
;;
esac
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment