Skip to content

Instantly share code, notes, and snippets.

@kedare
Created January 18, 2016 15:20
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 kedare/3f7e91786e8429a381b0 to your computer and use it in GitHub Desktop.
Save kedare/3f7e91786e8429a381b0 to your computer and use it in GitHub Desktop.
Powerline disk space widget
import os
import humanfriendly
def disk(pl, monitor="/", threshold_gig=10):
partition = os.statvfs(monitor)
available = partition.f_bsize * partition.f_bavail
available_gig = available / 1024 ** 2
threshold_crit_gig = threshold_gig*0.5
ret = []
color_pct = 0
if available_gig > threshold_gig:
color_pct = 0
elif available_gig > threshold_crit_gig:
color_pct = (available_gig - threshold_crit_gig) * 100 / threshold_gig
else:
color_pct = 100
ret.append({
'contents': humanfriendly.format_size(available),
'highlight_groups': ['disk_gradient'],
'divider_highlight_group': 'background:divider',
'gradient_level': color_pct,
})
return ret
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment