Macbook battery status in tmux
Note: this post was migrated from my old Tumblr-backed blog
For the last couple of weeks, I’ve been using tmux
more and more and I have to say that I really like it. For those that don’t know, tmux
is a very scriptable “terminal multiplexer.” What this means is that you can create multiple virtual terminals in a single session and even arbitrarily split the window to run multiple applications in the same session. I like it a lot more than screen
in that it just has a better overall feel and I don’t think I can live without it.
After discovering iTerm2 and moving away from MacVim, towards straight-up vim
, and going full-screen with my terminal, I noticed one thing that I was missing, and that was being able to see my battery status. When iTerm2 full-screens, I lose my menu bar and once I start worrying about my battery status, I find myself obsessively moving the mouse to the top of the screen to display my menu bar to check the battery.
In walks batt
.
batt
is a commandline script that will display information about your Macbook’s battery. This includes whether it’s plugged in, how much time is left and what the % capacity is. I packaged it as a gem for easy distribution and released version 0.1.0 today.
Currently, batt
only supports OSX and has only been tested in 10.8 Mountain Lion.
To install batt
, you can run the following in your terminal:
gem install batt
If you’re not running rvm
, you may have to use sudo
to install it.
From there, you now have access to batt
and can get all kinds of information about your battery; for example:
batt all
will spit out:
source: Battery Power
capacity: 30%
status: discharging
remaining: 1:16 remaining
and:
batt capacity
will spit out
30%
For tmux, I added a --tmux
switch to the capacity
action to add some colour to the output, so you can use it in your status line. My current tmux.conf
contains the following lines:
set-option status-right-length 120
set-option status-right "[ #(batt source) #(batt capacity --tmux) ] #(date \"+%Y-%m-%d %H:%M\")"
You can read more in the readme on the project page:
https://github.com/spikegrobstein/batt
Please, let me know what you think of the project and I’m open to any kind of code contributions or ideas.