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
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
50 deletions
+29
-50
neofetch
neofetch
+29
-50
No files found.
neofetch
View file @
d9e15e35
...
@@ -268,73 +268,52 @@ getkernel() {
...
@@ -268,73 +268,52 @@ getkernel() {
# Uptime {{{
# Uptime {{{
getuptime() {
getuptime() {
# Get uptime in seconds
case "
$os
" in
case "
$os
" in
"
Linux
" | "
Windows
")
"
Linux
" | "
Windows
")
case "
$distro
" in
seconds="
$(
< /proc/uptime
)
"
*"
Puppy
"* | "
Quirky
Werewolf
"* | "
Alpine
Linux
"* | "
OpenWRT
"* | "
Windows
"*)
seconds="
${
seconds
/.*
}
"
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
;;
;;
"
Mac
OS X
" | "
iPhone
OS
" | "
BSD
")
"
Mac
OS X
" | "
iPhone
OS
" | "
BSD
")
# Get boot time in seconds
boot="
$(
sysctl
-n
kern.boottime
)
"
boot="
$(
sysctl
-n
kern.boottime
)
"
boot="
${
boot
/
'{ sec = '
}
"
boot="
${
boot
/
'{ sec = '
}
"
boot="
${
boot
/,*
}
"
boot="
${
boot
/,*
}
"
# Get current date in seconds
# Get current date in seconds
now="
$(
date
+%s
)
"
now="
$(
date
+%s
)
"
uptime="
$((
now
-
boot
))
"
seconds="
$((
now
-
boot
))
"
;;
# Convert uptime to days/hours/mins
minutes="
$((
uptime
/
60
%
60
))
"
hours="
$((
uptime
/
3600
%
24
))
"
days="
$((
uptime
/
86400
))
"
case "
$minutes
" in
1) minutes="
1
minute
" ;;
0) unset minutes ;;
*) minutes="
$minutes
minutes
" ;;
esac
case "
$hours
" in
1) hours="
1
hour
" ;;
0) unset hours ;;
*) hours="
$hours
hours
" ;;
esac
case "
$days
" in
"
Solaris
")
1) days="
1
day
" ;;
seconds="
$(
kstat
-p
unix:0:system_misc:snaptime |
awk
'{print $2}'
)
"
0) unset days ;;
seconds="
${
seconds
/.*
}
"
*) days="
$days
days
"
;;
;;
esac
esac
[ "
$hours
" ] &&
\
days="
$((
seconds
/
60
/
60
/
24
))
days
"
[ "
$minutes
" ] &&
\
hours="
$((
seconds
/
60
/
60
%
24
))
hours
"
hours+="
,
"
minutes="
$((
seconds
/
60
%
60
))
minutes
"
[ "
$days
" ] &&
\
case "
$days
" in
[ "
$hours
" ] &&
\
"
0
days
") unset days ;;
days+="
,
"
"
1
days
") days="
${
days
/s
}
" ;;
esac
uptime="
up
$days
$hours
$minutes
"
case "
$hours
" in
;;
"
0
hours
") unset hours ;;
"
1
hours
") hours="
${
hours
/s
}
" ;;
esac
"
Solaris
")
case "
$minutes
" in
uptime="
$(
uptime
| /usr/xpg4/bin/awk
-F
':[0-9]{2}+[a-z][a-z] |(, ){1}+'
'{printf $2}'
)
"
"
0
minutes
") unset minutes ;;
;;
"
1
minutes
") minutes="
${
minutes
/s
}
"
;;
esac
esac
uptime="
${
days
:+
$days
,
}${
hours
:+
$hours
,
}${
minutes
}
"
uptime="
${
uptime
%
', '
}
"
uptime="
up
${
uptime
:-${
seconds
}
seconds
}
"
# Make the output of uptime smaller.
# Make the output of uptime smaller.
case "
$uptime_shorthand
" in
case "
$uptime_shorthand
" in
"
on
")
"
on
")
...
@@ -353,7 +332,7 @@ getuptime() {
...
@@ -353,7 +332,7 @@ getuptime() {
uptime="
${
uptime
/ minutes/m
}
"
uptime="
${
uptime
/ minutes/m
}
"
uptime="
${
uptime
/ minute/m
}
"
uptime="
${
uptime
/ minute/m
}
"
uptime="
${
uptime
/ seconds/s
}
"
uptime="
${
uptime
/ seconds/s
}
"
uptime="
${
uptime
/,
}
"
uptime="
${
uptime
/
/
,
}
"
;;
;;
esac
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