Created
January 18, 2016 15:20
-
-
Save kedare/3f7e91786e8429a381b0 to your computer and use it in GitHub Desktop.
Powerline disk space widget
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
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