Here you can use awk
to parse the output of uptime
to suit your needs like this:
set -g status-right '#[fg=red,bg=default]#(uptime | awk '{print $3}'|sed 's/,//') #[fg=blue]%a%d-%m-%Y %H:%M:%S'
Normally uptime
returns this type of output:
$ uptime
15:30:24 up 1:59, 4 users, load average: 2.39, 2.08, 2.12
By using awk
we can get rid of everything around the uptime.
$ uptime | awk '{print $3}'|sed 's/,//'
2:47
You could also use /proc/uptime
to get the actual seconds that the system has been up and then use awk
or perl
to convert the seconds to days, hours, minutes, etc.
$ awk '{printf("%d:%02d:%02d:%02d",($1/60/60/24),($1/60/60%24),($1/60%60),($1%60))}' /proc/uptime
0:02:49:55
This shows the seconds of uptime in DD:HH:MM:SS.
You could also show them using Perl:
$ cat /proc/uptime | perl -ne '/(\d*)/ ; printf "%02d:%02d:%02d:%02d\n",int($1/86400),int(($1%86400)/36003600)/60),$1%60'
00:02:50:53
tmux quoting?
As @JasonwRyan mentioned in the comments, tmux
can be notoriously difficult to quote the commands just right. Here's how you could quote the awk
example that I provided above.
set -g status-right '#[fg=red,bg=default]#(uptime | awk \"{print \\$3}\"|sed \"s/,//\") #[fg=blue]%a%d-%m-%Y %H:%M:%S'
However it's probably easier to just put the commands in a shell script and call that from within the tmux
config file:
set -g status-right '#[fg=red,bg=default]#(somecommand.bash) #[fg=blue]%a%d-%m-%Y %H:%M:%S'
References