|
|
听别人说有个好东西叫conky,贴在桌面壁纸上的系统监视器。看看官方文档,得知是使用torsmo代码的一个东东,晚上闲着没事,装一个玩玩,结果玩上瘾了,一看十二点了。。。。还是写点东西把,没有心得也有辛苦阿。
我装的是Gentoo linux,使用fvwm,UTF8的locale。装conky比较容易,不用动脑筋,emerge conky。(记得有个老大说我是用gentoo的懒人,不知道是说我是懒人还是Gentoo让人变懒了)
运行一下,基本不错,就是什么都看不清楚,废话,没写配置嘛。linux下的软件没写配置大都是垃圾,但是一旦配好了,哈哈,就是漂亮。

关于conky的配置,示例文件写的比较清楚,就是有几点:
1. 设置这样你的漂亮的字体就可以用了,不然用点阵的把。
2 设置我的locale是utf8,不加这个配置文件里的中文就显示不了了。另外,编辑.conkyrc时,最好确认保存成utf8格式。
3 不要在TEXT标签以后写注释,就是注释了也会显示出来。。。
我有个疑问,就是似乎只能够启动一个conky,要是能启动多个就好了,不知道是我不会用还是软件不支持。请那位老大告诉我一下?
conky可以显示文件,就像示例中的一样,使用${exec command},这样的话,就可以想些小花招了
花招1 gmail邮件提示:
呵呵,这个是官方网站上的一个perl脚本,使用这个脚本生成一个写有新邮件信息的gmail_top文件,然后在conky中把它显示出来,就使conky可以检查邮件了。
http://conky.sourceforge.net/gmail.pl
花招2 xmms信息:
还是官方网站上的东西,使用xmms插件xmms-infopipe,这样在xmms播放的时候在/tmp可以找到一个xmms-pipe文件,里面是当前xmms的状态,有个老外写了个脚本生成了一个播放的进度条,但是似乎有问题,我也写了一个- if ls /tmp/xmms-info_crazyapple.0 >> null
- then
- title=`sed -n '13p' /tmp/xmms-info |cut -c8-`
- filename=`sed -n '14p' /tmp/xmms-info |cut -c7-`
- tunetime=`sed -n '9p' /tmp/xmms-info|cut -c7-`
- nowtime=`sed -n '7p' /tmp/xmms-info|cut -c11-`
- bitrate=`sed -n '10p' /tmp/xmms-info|cut -c18-`
- tune=`sed -n '4p' /tmp/xmms-info|cut -c20-`
- currenttune=`sed -n '5p' /tmp/xmms-info|cut -c20-`
- _time=`sed -n '6p' /tmp/xmms-info|cut -c15-`
- _ftime=`sed -n '8p' /tmp/xmms-info|cut -c11-`
- (( pos=_time*35/_ftime ))
- echo xmms online.
- echo "专 辑:$title"
- echo "文 件:$filename"
- echo "曲 目:$currenttune / $tune"
- echo "比特率:$bitrate"
- echo "总时间:$tunetime"
- for (( i=0 ; i<35 ; i++ ))
- do
- if [ "$i" -eq "$pos" ]
- then
- echo -n '0'
- else
- echo -n '='
- fi
- done
- echo
- else
- echo xmms offline.
- fi
复制代码 由于我刚刚学写脚本,这个东西实用性不强---运行一次要8~9秒,严重影响了conky的刷新速度,那位大哥帮我改改就好了。我最后只好使用sed抓了xmms-info文件中的几个有用行让conky显示,这样没有技术含量,但是速度快了一点。
花招3 天气预报
这个也是很多人都使用的小伎俩,把人家网站上的天气预报抓下来改头换面。我使用人民网的天气预报,有24小时和48小时两种,都抓下来
- w3m -dump_source "http://card.people.com.cn/forecast/inland24.jsp?aboard=0&interval="|sed -n '393,398p'|iconv -f GB18030 -t UTF8 |cut -d\> -f3|sed 's/<\/font//'|sed 's/ /风速:/'|tr -d '\<' > ~/.weather/Wuhan.weather
- w3m -dump_source "http://card.people.com.cn/forecast/inland48.jsp?aboard=0&interval="|sed -n '393,398p'|iconv -f GB18030 -t UTF8 |cut -d\> -f3|sed 's/<\/font//'|sed 's/ /风速:/'|tr -d '\<' >> ~/.weather/Wuhan.weather
复制代码
我是武汉的,使用网页上的第393到398行,地区不同自行修改。(当然把脚本改成自动搜索也可以,本人初学,不是太懂,懒得麻烦)
这样24/48小时日夜天气预报的天气,风力,气温都有了,分12行装着,让conky显示时还得组装一下:
show_weather.sh- #Wrtter by woodenapple
- w3m -dump_source "http://card.people.com.cn/forecast/inland24.jsp?aboard=0&interval=24"|sed -n '393,398p'|iconv -f GB18030 -t UTF8 |cut -d\> -f3|sed 's/<\/font//'|sed 's/ //'|tr -d '\<' > ~/.weather/_Wuhan.weather
- w3m -dump_source "http://card.people.com.cn/forecast/inland24.jsp?aboard=0&interval=48"|sed -n '393,398p'|iconv -f GB18030 -t UTF8 |cut -d\> -f3|sed 's/<\/font//'|sed 's/ //'|tr -d '\<' >> ~/.weather/_Wuhan.weather
- dayweather24=`sed -n '1p' ~/.weather/_Wuhan.weather`
- daywind24=`sed -n '2p' ~/.weather/_Wuhan.weather`
- daytemp24=`sed -n '3p' ~/.weather/_Wuhan.weather|sed 's/[^0-9]//'`
- nightweather24=`sed -n '4p' ~/.weather/_Wuhan.weather`
- nightwind24=`sed -n '5p' ~/.weather/_Wuhan.weather`
- nighttemp24=`sed -n '6p' ~/.weather/_Wuhan.weather|sed 's/[^0-9]//'`
- dayweather48=`sed -n '7p' ~/.weather/_Wuhan.weather`
- daywind48=`sed -n '8p' ~/.weather/_Wuhan.weather`
- daytemp48=`sed -n '9p' ~/.weather/_Wuhan.weather|sed 's/[^0-9]//'`
- nightweather48=`sed -n '10p' ~/.weather/_Wuhan.weather`
- nightwind48=`sed -n '11p' ~/.weather/_Wuhan.weather`
- nighttemp48=`sed -n '12p' ~/.weather/_Wuhan.weather|sed 's/[^0-9]//'`
- if [ $daytemp24 -lt $nighttemp24 ]
- then
- echo "武汉地区未来24小时天气情况" > ~/.weather/Wuhan.weather
- echo "晚间天气 $dayweather24 风速:$daywind24 最高温度:$daytemp24 ℃" >> ~/.weather/ Wuhan.weather
- echo "白天天气 $nightweather24 风速:$nightwind24 最低温度:$nighttemp24 ℃" >> ~/.weather/Wuhan.weather
- echo "武汉地区未来48小时天气情况" >> ~/.weather/Wuhan.weather
- echo "晚间天气 $dayweather48 风速:$daywind48 最高温度:$daytemp48 ℃" >> ~/.weather/Wuhan.weather
- echo "白天天气 $nightweather48 风速:$nightwind48 最低温度:$nighttemp48 ℃" >> ~/.weather/Wuhan.weather
- else
- echo "武汉地区未来24小时天气情况" > ~/.weather/Wuhan.weather
- echo "白天天气 $dayweather24 风速:$daywind24 最高温度:$daytemp24 ℃" >> ~/.weather/Wuhan.weather
- echo "晚间天气 $nightweather24 风速:$nightwind24 最低温度:$nighttemp24 ℃" >> ~/.weather/Wuhan.weather
- echo "武汉地区未来48小时天气情况" >> ~/.weather/Wuhan.weather
- echo "白天天气 $dayweather48 风速:$daywind48 最高温度:$daytemp48 ℃" >> ~/.weather/Wuhan.weather
- echo "晚间天气 $nightweather48 风速:$nightwind48 最低温度:$nighttemp48 ℃" >> ~/.weather/Wuhan.weather
- fi
复制代码
在conky中运行,就有天气预报了。
花招4 新闻
经常上新浪,觉得里面的新闻时效性很强,甚至有滚动新闻,一分钟刷一次,这个是不是也可以当下来贴在conky上?(初学,这个脚本有些混乱,性能也很差,如果有高手告诉我怎么弄就太感谢了;另外,不用这个方法也可以,不是有著名的RSS么?这里只是好玩,不要鄙视我)
第一步,得把新浪的滚动新闻列表下载下来,我使用一个命令:- lynx -source http://news.sina.com.cn/news1000/index.shtml|grep \<li\>|iconv -f GB18030 -t UTF8|cut -c18-|sed 's/ target=_blank>/@/'|sed 's/<.*\>//' > ~/.sina_new/news.sina
复制代码 放到.sina_new/news.sina中,格式是“地址@标题”,便于下一步获得新闻内容。
第二步,每次取出最顶端的一条新闻,通过地址把它下载下来,然后析取其中文字部分。由于我的shell太菜,搞了很久也没有搞出能去掉网页上那么多乱七八糟的标签和代码,只好使用了一个卑鄙的办法,使用w3m [html url] >> file 搞到文本。然后大致的修剪了一下文本,只能保证大部分网页完整,多几个奇怪的符号我就不管了。
newtext.sh- mv ~/.sina_new/news.sina ~/.sina_new/news.old
- sed '1d' ~/.sina_new/news.old > ~/.sina_new/news.sina
- rm ~/.sina_new/news.old
- url=`sed -n '1p' ~/.sina_new/news.sina|cut -d@ -f1`
- echo $url
- w3m $url > ~/.sina_new/source.new
- startline=`cat ~/.sina_new/source.new -n|grep '*'|sed -n '1p'|cut -f1`
- endline=`cat ~/.sina_new/source.new -n|grep '发表评论'|sed -n '1p'|cut -f1|tr -d ' '`
- if [ $startline ]
- then
- startline=1
- fi
- #if [ $endline ]
- #then
- # endline=50
- #fi
- echo startline=$startline
- echo endline=$endline
- echo " echo -n Sina News: > ~/.sina_new/current.new" > ~/.sina_new/temp.sh
- echo "sed -n '1p' ~/.sina_new/news.sina|cut -d@ -f2 >> ~/.sina_new/current.new" >> ~/.sina_new/temp.sh
- echo -n "sed -n '" >> ~/.sina_new/temp.sh
- echo -n $startline >> ~/.sina_new/temp.sh
- echo -n "," >> ~/.sina_new/temp.sh
- echo -n $endline >> ~/.sina_new/temp.sh
- echo "p' ~/.sina_new/source.new |sed '1d'|sed '/[adfshow]/d'|sed '1d'|sed '2,3d'|sed '/^$/d'|sed '/发表/d'|sed '1d'>> ~/.sina_new/current.new" >> ~/.sina_new/temp.sh
- chmod 755 ~/.sina_new/temp.sh
- ~/.sina_new/temp.sh
复制代码
这里我有不懂的地方,就是算出起始行和终止行放到变量里,如何直接使用sed或者grep去掉其余的行?这个脚本我用了一半代码生成一个新脚本temp.sh,使用temp.sh创建新闻文本current.new。显然这个方法不好,请那位帮我?
我把两个脚本绑定到我的两个键上:- #sina news:
- Key KP_Add A N Exec exec lynx -source http://news.sina.com.cn/news1000/index.shtml|grep \<li\>|iconv -f GB18030 -t UTF8|cut -c18-|sed 's/ target=_blank>/@/'|sed 's/<.*\>//' > ~/.sina_new/news.sina
- Key KP_Enter A N Exec exec ~/.sina_new/newtext.sh
复制代码
这样按一下小键盘上的加号键就自动下载最新新闻列表,按一下小键盘的回车就查看条新闻。
由于conky版面有限,加上新闻的字不能太小,我只好把邮件检查放弃了(反正邮箱也没怎么用过),这是我的.conkyrc- background yes
- use_xft yes
- xftfont VeraSansYuanTi:size=10
- xftalpha 0.8
- update_interval 2.0
- total_run_times 0
- own_window no
- double_buffer yes
- minimum_size 280 10
- draw_shades yes
- draw_outline no
- draw_borders no
- stippled_borders 8
- border_margin 4
- border_width 1
- default_color white
- default_shade_color black
- default_outline_color white
- alignment top_left
- gap_x 24
- gap_y 24
- no_buffers yes
- uppercase no
- cpu_avg_samples 2
- net_avg_samples 2
- override_utf8_locale yes
- use_spacer yes
- TEXT
- ${color gray}登录时间: ${color }$uptime
- ${color gray}核心:${color } $kernel
- ${color gray}CPU:${color } $cpu% 温度:${acpitemp}`C
- ${color gray}系统负载: ${color }$loadavg
- ${color gray}进程数: ${color }$processes 活跃进程数: ${color }$running_processes
- ${color gray}CPU占用:
- ${color lightgrey} ${top name 2}${top_mem cpu 2}
- ${color lightgrey} ${top name 3}${top_mem cpu 3}
- ${color gray}内 存: ${membar 3,100} ${color }
- $memperc% $mem/$memmax
- ${color gray}交换空间: ${swapbar 3,100}${color }
- $swapperc% $swap/$swapmax
- ${color gray}Root : ${fs_bar 3,100 /}${color }
- ${fs_used /}/${fs_size /}
- ${color gray}Media : ${fs_bar 3,100 /media}${color }
- ${fs_used /media}/${fs_size /media}
- ${color gray}网络状况:
- ${color}上传速度: ${color }${upspeed eth0} k/s 上传总量:${totalup eth0}
- ${color}下载速度: ${color }${downspeed eth0}k/s${color} 下载总量:${totaldown eth0}
- ${color}${exec cat ~/.weather/Wuhan.weather}
- ${color}${exec ~/.xmms/.xmms.sh}
复制代码
搞定。
55555,对不起我下面的签名阿,又玩了一夜。困死了。 |
|