1use Irssi; 2use Irssi::TextUI; 3use strict; 4 5use vars qw($VERSION %IRSSI); 6 7$VERSION="0.1.0"; 8%IRSSI = ( 9 authors=> 'Jochem Meyers', 10 contact=> 'jochem.meyers@gmail.com', 11 name=> 'df', 12 description=> 'Adds an item which displays the current disk usage.', 13 sbitems=> 'df', 14 license=> 'GPL v2 or later', 15 url=> 'http://kaede.kicks-ass.net/irssi.html', 16); 17 18######### 19# INFO 20### 21# 22# Type this to add the item: 23# 24# /statusbar window add df 25# 26# See 27# 28# /help statusbar 29# 30# for more help on how to custimize your statusbar. 31# 32# If you want to change the way the item looks, browse down to where it reads 33# 34# $output .= ' [' . $device . ': A: ' . $avail{$device} . ' U%%: ' . $use{$device} . ']'; 35# 36# and add or remove any of the following: 37# $size{$device} is the total size of the drive 38# $used{$device} is the total amount of used space 39# $avail{$device} is the amount of available space 40# $use{$device} is the percentage of space used 41# $mount{$device} is the mount point 42# 43# Next version, if I ever get around to making one, will have an easier system of changing the 44# way the statusbar item looks. 45# 46# There's a command defined, /dfupdate, which will instantly update the statusbar item. If you 47# want this information printed in the statuswindow, use /exec df -h in any window :). 48# 49############ 50# OPTIONS 51###### 52# 53# The irssi command /set can be used to change these settings (more to follow): 54# * df_refresh_time (default: 60) 55# The number of seconds between updates. 56# 57### 58######### 59# TODO 60### 61# 62# - Add format support so the display is more easily customizable. 63# - Add a list of devices to display. 64# - Add a setting that'll let user define the switches to pass to df? 65# 66######### 67 68#definte variables 69my $output; 70my ($df_refresh_tag); 71my $sbitem; 72my (%size, %used, %avail, %use, %mount); 73 74#get information about the harddrives 75sub getDiskInfo() 76{ 77 my @list; 78 my $skip_line_one = 1; 79 80 open(FID, "-|", "/bin/df"); 81 while (<FID>) 82 { 83 if ($skip_line_one > 0) 84 { 85 $skip_line_one--; 86 next; 87 } 88 my $line = $_; 89 $line =~ s/[\s:]/ /g; 90 @list = split(" ", $line); 91 $list[0] =~ s/\/dev\///g; 92 $size{$list[0]} = $list[1]; 93 $used{$list[0]} = $list[2]; 94 $avail{$list[0]} = $list[3]; 95 $use{$list[0]} = $list[4]; 96 $mount{$list[0]} = $list[5]; 97 $skip_line_one--; 98 if ($skip_line_one < -100) { 99 Irssi::print("More than 100 drives, this can't be."); 100 return; 101 } 102 } 103 close(FID); 104} 105 106#called by irssi to get the statusbar item 107sub sb_df() 108{ 109 my ($item, $get_size_only) = @_; 110 $item->default_handler($get_size_only, "{sb $sbitem}", undef, 1); 111} 112 113sub test() 114{ 115 refresh_df(); 116} 117#refresh the statusbar item 118sub refresh_df() 119{ 120 getDiskInfo(); 121 $output = ""; 122 $sbitem = ""; 123 my @devices = keys(%size); 124 my $device; 125 foreach $device (@devices) 126 { 127 $output .= ' [' . $device . ': A: ' . $avail{$device} . ' U%%: ' . $use{$device} . ']'; 128 } 129 $sbitem = 'DF' . $output; 130 Irssi::statusbar_items_redraw('df'); 131 if ($df_refresh_tag) 132 { 133 Irssi::timeout_remove($df_refresh_tag) 134 } 135 my $time = Irssi::settings_get_int('df_refresh_time'); 136 $df_refresh_tag = Irssi::timeout_add($time*1000, 'refresh_df', undef); 137} 138 139#register the statusbar item 140Irssi::statusbar_item_register('df', undef, 'sb_df'); 141 142#add settings 143Irssi::settings_add_int('misc', 'df_refresh_time', 60); 144 145Irssi::command_bind('dfupdate','test'); 146 147#run refresh_df() once so sbitem has a value 148refresh_df(); 149 150################ 151### 152# Changelog 153# Version 0.1.0 154# - initial release 155# 156### 157################ 158