Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

tmux status line

  • Loading branch information...
commit e5b71845396586c1012357e96ba49ab10be3f139 1 parent 7740296
@creaktive authored
Showing with 51 additions and 6 deletions.
  1. +2 −4 .tmux.conf
  2. +49 −2 bin/macbook-stats.pl
View
6 .tmux.conf
@@ -16,11 +16,9 @@ bind - split-window -v
set -g status-bg black
set -g status-fg white
set -g status-left '#[fg=green]#H'
-set -g status-right '#[fg=yellow]#(cut -d " " -f1-4 /proc/loadavg)'
-#set -g status-right '#[fg=yellow]#(macbook-stats.pl)'
-#set -g status-right '#[fg=yellow]#(uptime|cut -d " " -f10-)'
+set -g status-right '#[fg=yellow]#(macbook-stats.pl)'
set -g status-interval 60
-set -g status-right-length 60
+set -g status-right-length 64
# Highlight active window
set-window-option -g window-status-current-bg red
View
51 bin/macbook-stats.pl
@@ -1,2 +1,49 @@
-#!/usr/bin/env perl
-%m=map{/Pages (free|active|inactive|wired down):\s*(\d+)/;(substr($1,0,1)=>$2<<12)}qx{vm_stat};delete$m{q{}};@l=split/\s+/,qx{uptime};@b=map{(/(\d+)$/)[0]}grep{/(Max|Current)Capacity/}qx{ioreg -l};printf qq{%s l:%s/%s/%s b:%.01f%%\n},(join q{ },map{sprintf q(%s:%0.2fG),$_,$m{$_}/(2**30)}sort keys%m),@l[-3..-1],100*$b[1]/$b[0]
+#!/usr/bin/perl
+use strict;
+use warnings;
+
+my %memory;
+if (-x q{/usr/bin/vm_stat}) {
+ %memory = map {
+ /\bPages\s+(free|active|inactive|wired\s+down):\s*(\d+)/ix
+ ? (substr($1, 0, 1) => $2 << 2)
+ : ();
+ } qx{vm_stat};
+} elsif (open my $meminfo, q{<}, q{/proc/meminfo}) {
+ %memory = map {
+ /\b(?:Mem)?(Free|Cached|Active|Inactive):\s*(\d+)/ix
+ ? (substr($1, 0, 1) => $2)
+ : ();
+ } <$meminfo>;
+ close $meminfo;
+}
+
+%memory && print
+ map {
+ sprintf q( %s:%0.2fG),
+ lc,
+ $memory{$_} / (2 ** 20)
+ } sort keys %memory;
+
+my @load;
+if (open my $loadavg, q{<}, q{/proc/loadavg}) {
+ @load = (split /\s+/x, <$loadavg>)[0 .. 2];
+ close $loadavg;
+} elsif (-x q{/usr/bin/uptime}) {
+ @load = (split /\s+/x, qx{uptime})[-3 .. -1];
+}
+
+@load && print q{ l:}, join q{/}, @load;
+
+if (-x q{/usr/sbin/ioreg}) {
+ my @battery = map {
+ /"(?:(?:Max|Current)Capacity|ExternalConnected)"\s*=\s*(\d+|Yes|No)/ix
+ ? $1
+ : ()
+ } qx{ioreg -n AppleSmartBattery -r};
+ printf q{ b:%s%.01f%%},
+ $battery[2] =~ /^y/ix ? q{} : q{!},
+ 100 * $battery[1] / $battery[0];
+}
+
+printf qq{ %02d:%02d\n}, (localtime)[2, 1];
Please sign in to comment.
Something went wrong with that request. Please try again.