Last active
August 18, 2016 20:08
-
-
Save mgregoro/9e68f8d06ef03aeb36908a4d6a9149fe to your computer and use it in GitHub Desktop.
Quick script to show total, used, free keybase.io kbfs space on OSX / Linux clients
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
# kbfree.pl | |
# cpanm JSON Number::Bytes::Human | |
# (c) 2016 Michael Gregorowicz | |
use Number::Bytes::Human; | |
use JSON; | |
use v5.10; | |
# set your KBFS root here | |
my $kb_root = '/keybase'; | |
my $nbh = Number::Bytes::Human->new( | |
precision => 2, | |
si => 1 | |
); | |
my $hr; | |
{ | |
local $/; | |
open my $fh, '<', "$kb_root/.kbfs_status" or die "Can't open $kb_root/.kbfs_status: $!\n"; | |
$hr = decode_json(<$fh>); | |
} | |
if (ref $hr eq "HASH") { | |
printf("%-8s %-8s %-8s %-8s\n", "Total", "Used", "Free", "%Used"); | |
say("-------- " x 4); | |
printf("%-8s %-8s %-8s %.02f%%\n", | |
$nbh->format($hr->{LimitBytes}), | |
$nbh->format($hr->{UsageBytes}), | |
$nbh->format($hr->{LimitBytes} - $hr->{UsageBytes}), | |
($hr->{UsageBytes} / $hr->{LimitBytes} * 100) | |
); | |
} else { | |
die "[error] failed to parse $kb_root/.kbfs_status'"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment