Skip to content

Instantly share code, notes, and snippets.

@mgregoro
Last active August 18, 2016 20:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mgregoro/9e68f8d06ef03aeb36908a4d6a9149fe to your computer and use it in GitHub Desktop.
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
#!/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