«前の日記(2008-02-03(日)) 最新 次の日記(2008-02-11(月))» 編集
RSS feed

からっぽの日記


2008-02-09(土) [長年日記]

awesome のステータスバーが変わった

Sawfish から awesome に乗り換えてしばらく立つのですが、Debian lenny の awesome が 2.0.final-1 -> 2.1-1 へアップデートに伴いステータスバーの表示方法が変わった。Google先生に尋ねてみたところ、ここ へ辿り着きました。なんか棒グラフ?とかも表示できる!さっそく参考にさせてもらい、修正したものを導入してみましたほとんどそのままですが^^;。一応、晒してみます。

参考にさせていただいたサイト

An example awesomerc \| Wisdom is the prime thing

#/bin/bash

CPUSTAT="/tmp/.cpustat"
mail=`ruby $HOME/bin/mail_checker.rb`

if [ -f "$CPUSTAT" ]; then
    touch $CPUSTAT
fi

while true;
do
date=`LC_ALL=C date +"%Y.%m.%d(%a) %H:%M" | sed 's/  / /g'`


### CPU
old_cpu_vals=(`head -1 "$CPUSTAT"`)
cpu_old_user=${old_cpu_vals[0]}
cpu_old_nice=${old_cpu_vals[1]}
cpu_old_system=${old_cpu_vals[2]}
cpu_old_idle=${old_cpu_vals[3]}
cpu_old_total=`echo "$cpu_old_user + $cpu_old_nice + $cpu_old_system + $cpu_old_idle" | bc`

cpu_vals_text=`cat /proc/stat  | head -1 | sed -e 's/^cpu[^0-9]*//g' -e 's/\([^ ]\+ [^ ]\+ [^ ]\+ [^ ]\+\).*/\1/g'`
cpu_vals=($cpu_vals_text)
cpu_user=${cpu_vals[0]}
cpu_nice=${cpu_vals[1]}
cpu_system=${cpu_vals[2]}
cpu_idle=${cpu_vals[3]}
cpu_total=`echo "$cpu_user + $cpu_nice + $cpu_system + $cpu_idle" | bc`
pcpu=`echo "(100 * ($cpu_system - $cpu_old_system + $cpu_user - $cpu_old_user)) / ($cpu_total - $cpu_old_total)" | bc`
echo $cpu_vals_text > "$CPUSTAT"


### MEMORY
mem_vals=`free -m | grep '^Mem:' | sed 's/Mem://g'`
mtot=`echo $mem_vals | sed 's/ .*//g'`
muse=`echo $(echo $mem_vals | cut -f2,5,6 -d" " | sed 's/ / - /g') | bc`
pmem=`echo "100 * $muse / $mtot" | bc`


### MPD
#mpc_lines=`mpc | wc -l`
#vol=`mpc | grep 'volume:' | sed -e 's/volume: //' -e 's/ .*//g'`
#mpc_text="stopped @ $vol"
#if [[ $mpc_lines -gt 1 ]]; then
#    song=`mpc | head -1`
#    status=`mpc | grep '^\[' | sed -e 's/ .*//' -e 's/[^a-zA-Z]//g'`
#    mpc_text="$song @ $vol"
#fi


### MAIL
#if [ -f "$MAIL" ]; then
#    mail_tot=`cat "$MAIL" | grep -c '^From '`
#    mail_old=`cat "$MAIL" | grep '^Status: ' | grep -c 'O'`
#    mail_new=`echo "$mail_tot-$mail_old" | bc`
#    if [[ $mail_new -eq 0 ]]; then
#        mail_new="-"
#    fi
#    if [[ $mail_tot -eq 0 ]]; then
#        mail_tot="-"
#    fi
#    mail_text="$mail_new/$mail_tot"
#else
#    mail_text="-/-"
#fi


### UPTIME
#uptime=`uptime | sed 's/.* \([0-9]\+ days\).*/\1/' | tr -d '[ a-zA-z]'`


### SWAP
#swap_vals=`free | grep 'Swap: ' | sed 's/.*: *\([0-9]\+\) \+\([0-9]*\).*/\1 \2/'`
#swap_tot=`echo $swap_vals | cut -f1 -d" "`
#swap_use=`echo $swap_vals | cut -f2 -d" "`
#pswap=`echo "100*$swap_use / $swap_tot" | bc`



### BATTERY
full_battery=`cat /proc/acpi/battery/BATA/info | grep ^last | sed 's/last full capacity:      \([0-9]*\) mWh/\1/g'`
if [ -n "$full_battery" ]; then
    remain_battery=`cat /proc/acpi/battery/BATA/state | grep ^remaining | sed 's/remaining capacity:      \([0-9]*\) mWh/\1/g'`
   battery=`echo "100 * $remain_battery / $full_battery" | bc`
   battery="$battery%"
else
   battery="-"
fi

### MAIL
min=`date +'%M'`
mail_check=`echo "$min % 10" | bc`

if [ "$mail_check" -eq 0 ]; then
    mail=`ruby $HOME/bin/mail_checker.rb`
fi



#echo 0 widget_tell tb_mpc "$mpc_text" | awesome-client
echo 0 widget_tell g_cpu "$pcpu" | awesome-client
echo 0 widget_tell tb_mem "$pmem%" | awesome-client
echo 0 widget_tell pb_mem "$pmem" | awesome-client
echo 0 widget_tell tb_date "$date" | awesome-client
echo 0 widget_tell tb_battery "$battery" | awesome-client
echo 0 widget_tell tb_mail "$mail" | awesome-client

sleep 3
done

.cpustat は tmp に変更、バッテリ残量表示、使わないものはコメントアウトしました。メールのカウントはよくわからんだので ruby で書いてみました。シェルスクリプトのみで完結したがったが良しとしてます。以下、メールチェック: mail_checker.rb

#!/usr/bin/env ruby

require 'mailread'
require 'net/pop'


mail_spool = [
    'path' => '/var/mail/user',
  ]

mail_account = [
    {
      'pop3'   => 'hogehoge',
      'port'   => 110,
      'user'   => 'user',
      'passwd' => 'password',
    },
  ]

def count_mailbox(mail_spool)
  mail_count = 0

  begin
    mailbox = File.open(mail_spool)

    until (Mail.new(mailbox)).header.empty?
      mail_count += 1
    end
  rescue
    mailbox.close
  end

  mail_count
end

def count_pop3_mail(pop3, port, user, passwd)
  mail_count = 0

	begin
		Net::POP3.start(pop3, port, user, passwd) do |pop|
      mail_count = pop.mails.size
    end
	end

  mail_count
end


### main ###

mail_count = 0

mail_spool.each do |ms|
  mail_count += count_mailbox(ms['path'])
end

mail_account.each do |m|
  mail_count += count_pop3_mail(m['pop3'], m['port'], m['user'], m['passwd'])
end

puts mail_count

.awesomerc の「statusbar」に以下を追加

	textbox tb1 { fg = "#3CB371" text = " CPU: " align = "right" }
	graph g_cpu
	{
		scale = false
		max = 100
		padding_left = 0
		width = 40
		height = "0.8"
		fg = "#CE00CE"
		bg = "#000000"
		bordercolor = "#666699"
	}
	textbox tb2 { fg = "#3CB371" text = " Mem: " }
	progressbar pb_mem
	{
		bar { fg = "#CE00CE" bg = "#000000" bordercolor = "#666699"  }
		width = "40"
		height = "0.4"
		gap = -1
		padding_left = 0
	}
	textbox tb_space { fg = "#336633" text = " " }
	textbox tb_mem { fg = "#3CB371" text = "" }
	textbox tb3 { fg = "#3CB371" text = " MAIL: " }
	textbox tb_mail { fg = "#3CB371" text = "" }
	textbox tb4 { fg = "#3CB371" text = " BAT: " }
	textbox tb_battery { fg = "#3CB371" text = "" }
	textbox tb5 { fg = "#336633" text = " | " }
	textbox tb_date { fg = "#DAA520" text = "" }

で、こんな感じになりました。 ステータスバー


«前の日記(2008-02-03(日)) 最新 次の日記(2008-02-11(月))» 編集
RSS feed