首页 > Script > 自动生成fvwm菜单的脚本

自动生成fvwm菜单的脚本

[总点击:866次]
2009年1月21日

RT
自动创建缩略图需要convert(安装imagemagick包即可)
看看效果图,还不错哦,会自动根据你的图标主题生成小图标(不过category的图标得自己准备就是了):

发件人 xiooli

这个是根据/usr/share/applications里面的desktop文件来创建的。如果你新安装了程序,再运行一下就可以了,不要的项目直接注释掉,下回更新的时候不会覆盖。
代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/bash
#Name: 		Fvwm menu auto creator (FMAC)
#Author:	xiooli <xioooli[at]yahoo.com.cn,http://joolix.com>
#Licence:	GPLv3
#Version:	09.01.20
 
Menufile=~/.fvwm/configs/menu_content
Categories=(Network AudioVideo Graphics Office Games Utility Settings System Development Unknow)
Categorieszh=(网络 影音 图像 办公 游戏 附件 设置 系统 开发 未知)
Lang="$(locale|awk -F"." '/LANG=/{gsub("LANG=","",$1);print $1}')"
Fvwmiconspath="`echo ~/.fvwm/icons`"
[ -d "$Fvwmiconspath" ] || mkdir -p "$Fvwmiconspath"
Iconspath=""`echo ~/.icons`" "/usr/share/icons""
#Iconthemedir="Gnome" #在此可以定义使用的图标主题(路径/名称均可,不填就从 ~/.gtkrc-2.0去找) 
Iconthemedir="${Iconthemedir:-$(awk -F"=" '/gtk-icon-theme-name=/{gsub("\"","",$2);print $2}' "`echo ~/.gtkrc-2.0`")}"
[ -d "$Iconthemedir" ] || for i in $Iconspath;do
	[ -d "$i/$Iconthemedir" ] && Iconthemedir="$i/$Iconthemedir" && break
done
 
RESIZE () {
 
	convert -resize 24x24 "$1" "$2"
}
 
ADD_TO_MENU () {
 
	#$1 catnum; $2 iconpath; $3 name; $4 execmd
	local menutip cataicon
	[ -f $Menufile ] ||cat << EOF >$Menufile
#此文件里面是菜单的具体内容,菜单的样式在./menu_style中定义。
DestroyMenu recreate MenuFvwmRoot
AddToMenu MenuFvwmRoot "FVWM 菜单"	Title Top
#MenuCate
EOF
	if [ "`grep -w "Menu${Categories[$1]}" "$Menufile"`" ];then
		menutip="+ \\\"%$2%$3\\\"	Exec exec $4\n#Menu${Categories[$1]}"
		[ "`grep -w "$4" "$Menufile"`" ] || \
		eval "sed -i \"s/^#Menu${Categories[$1]}/${menutip//\//\\/}/\" \"$Menufile\""
	else
		menutip="+ \\\"%$Fvwmiconspath/categrories/${Categories[$1]}.png%${Categorieszh[$1]}\\\"	Popup Menu${Categories[$1]}\n#MenuCate"
		eval "sed -i \"s/^#MenuCate/${menutip//\//\\/}/\" \"$Menufile\""
		echo -e "\nDestroyMenu Menu${Categories[$1]}\nAddToMenu Menu${Categories[$1]}\n#Menu${Categories[$1]}" >> "$Menufile"
		menutip="+ \\\"%$2%$3\\\"	Exec exec $4\n#Menu${Categories[$1]}"
		eval "sed -i \"s/^#Menu${Categories[$1]}/${menutip//\//\\/}/\" \"$Menufile\""
	fi
}
 
GET_INFO () { # $1 gives the desktop file name
 
	local j name type execmd icon iconpath cattmp catnum
	name="`grep -i "^name\[$Lang\]" $1|sed "s/^.*=//"`"
	[ "$name" ] || name="`grep -i "^name=" $1|sed "s/^.*=//"`"
	execmd="`grep -i "^exec=" $1|sed "s/^.*=//;s/%.//g"`"
	cattmp="`grep -i "Categories=" $1|sed "s/^.*=//"`"
	for j in `seq 0 "$((${#Categories[@]}-1))"`;do
		[ "${cattmp//${Categories[$j]}/}" != "$cattmp" ] && catnum="$j" && break
	done
	catnum="${catnum:-$((${#Categories[@]}-1))}"
	icon="`grep -i "^icon=" $1|sed "s/^.*=//"`"
	if [ -f "$icon" ];then
		iconpath="$icon"
		[ ! -f "$Fvwmiconspath/$icon" -a "$iconpath" ] && RESIZE "$iconpath" "$Fvwmiconspath/"`basename "$icon"`""
	else
		[ "${icon/%.png/}" = "$icon" ] && icon="${icon}.png"
		iconpath="`find "$Iconthemedir" -type f -name "$icon" -print|sort|tail -n1`"
		[ "$iconpath" ] || iconpath="`find "$Iconthemedir" -type f -name "*$icon" -print|sort|tail -n1`"
		[ ! -f "$Fvwmiconspath/$icon" -a "$iconpath" ] && RESIZE "$iconpath" "$Fvwmiconspath/$icon"
		iconpath="${iconpath:-"$Fvwmiconspath/noicon.png"}"
	fi
	ADD_TO_MENU "$catnum" "$Fvwmiconspath/`basename "$icon"`" "$name" "$execmd"
}
 
for k in /usr/share/applications/*.desktop;do
	GET_INFO "$k"
done

Script , ,

  1. 2009年1月31日09:27 | #1

    Lovely. Great site.

本文的评论功能被关闭了.