These are modified scripts from the Fluxbox extension, which will generate menu / submenu entries with icons for the 'Applications' menu (if defined via .desktop files), and for the 'OnDemand' menu (if loaded and defined via .desktop files).
I know, icons can look pretty bad in fluxbox but it still makes it way easier to quickly find an app in the menu without using your brain a lot.
I'm not sure if the scripts will be executed directly from /usr/local/bin/ so the extension might better be rebuild (for personal use).
fluxbox_makemenu
#!/bin/sh
# (c) Robert Shingledecker 2009, 2010
# Typically called from /usr/bin/desktop.sh
# makemenu APPNAME
. /etc/init.d/tc-functions
. /usr/local/bin/fluxbox_menu_common
[ -z "$1" ] && exit 1
WM_MENU=/usr/local/tce.fluxbox
OUTFILE=/tmp/menu.tmp
> "$OUTFILE"
# Check for freedesktop item
FREEDESK="/usr/local/share/applications"
if [ -e "$FREEDESK"/"$1".desktop ]; then
if [ -e "$FREEDESK"/"$1"~1.desktop ]; then
#echo "[submenu]("$1")" > "$OUTFILE"
echo -n "[submenu]("$1")" > "$OUTFILE"
writeSubMenu "$FREEDESK"/"$1".desktop >> "$OUTFILE"
for F in $(ls "$FREEDESK"/* | grep -E "$1"'(~[1-9][1-9]*)*'.desktop); do
writeMenuItem "$F" >> "$OUTFILE"
done
echo "[end]" >> "$OUTFILE"
else
writeMenuItem "$FREEDESK"/"$1".desktop >> "$OUTFILE"
fi
merge "$OUTFILE" "$WM_MENU" "[end] TCE" > /tmp/newmenu
sudo mv /tmp/newmenu "$WM_MENU"
fi
fluxbox_menu_common
#!/bin/sh
# (c) Robert Shingledecker 2010
# Called from startx to setup initial fluxbox system, tce, & ondemand menus.
writeMenuItem() {
busybox awk '
BEGIN {
FS = "="
}
{
if ( $1 == "Name") {
name = $2
#gsub(/ /, "", name)
} else if ( $1 == "Exec" ) {
exec = $2
test = match(exec,"%")
if ( test ) exec = substr(exec,0,test-1)
} else if ( $1 == "Terminal" ) {
terminal = $2
} else if ( $1 == "X-FullPathIcon" ) {
icon = $2
}
}
END {
if ( terminal == "true" ) {
print "[exec]("name"){aterm +tr +sb -T \""name"\" -e " exec"}<"icon">"
} else {
print "[exec]("name"){"exec"}<"icon">"
}
} ' "$1"
}
writeSubMenu() {
subname="${1##*/}"
busybox awk -v subname="${subname/.desktop/}" '
BEGIN {
FS = "="
}
{
if ( $1 == "GenericName" ) {
generic = $2
} else if ( $1 == "X-FullPathIcon" ) {
icon = $2
}
}
END {
if ( icon == "" ) {
#if ( system( "[ -e " /usr/local/share/pixmaps/"subname".png " ] " ) == "0" ) {
# if ( generic == "" ) {
# print "</usr/local/share/pixmaps/"subname".png>"
# } else {
# print "{"generic"}</usr/local/share/pixmaps/"subname".png>"
# }
#} else {
if ( generic == "" ) {
print " "
} else {
print "{"generic"}"
}
#}
} else {
if ( generic == "" ) {
#print "[submenu]("subname")<"icon">"
print "<"icon">"
} else {
#print "[submenu]("subname"){"generic"}<"icon">"
print "{"generic"}<"icon">"
}
}
} ' "$1"
}
fluxbox_ondemand
#!/bin/sh
. /etc/init.d/tc-functions
ONDEMAND=/home/"$USER"/.fluxbox/ondemand
TCEDIR=/etc/sysconfig/tcedir
process(){
if [ ! -s "$ONDEMAND" ]; then
echo "[submenu](OnDemand){ tce-dir:/ondemand/. }" > "$ONDEMAND"
echo " [submenu]( ){ on-demand menu }" >> "$ONDEMAND"
echo " [nop](* = installed)" >> "$ONDEMAND"
echo " [exec](Rebuild menu){fluxbox_ondemand}" >> "$ONDEMAND"
echo " [end] on-demand" >> "$ONDEMAND"
echo "[end] OnDemand" >> "$ONDEMAND"
sync
fi
TMP="/tmp/fluxbox.$$" && TMP2="/tmp/fluxbox2.$$"
#echo "[exec](${1}){$TCEDIR/ondemand/${1}}" >> "$TMP"
if [ -e /usr/local/tce.installed/${1} ]; then
if [ -e "/usr/local/share/applications/${1}.desktop" ]; then
busybox awk -v name="${1}" -v exec="$TCEDIR/ondemand/${1}" '
BEGIN {
FS = "="
}
{
if ( $1 == "X-FullPathIcon" ) {
icon = $2
}
}
END {
if ( icon == "" ) {
print "[exec](* "name"){"exec"}"
} else {
print "[exec](* "name"){"exec"}<"icon">"
}
} ' "/usr/local/share/applications/${1}.desktop" >> "$TMP"
else
echo "[exec](* ${1}){$TCEDIR/ondemand/${1}}" >> "$TMP"
fi
#elif [ -e "/home/"$USER"/.local/share/pixmaps/${1}.png" ]; then
# echo "[exec]( ${1}){$TCEDIR/ondemand/${1}}</home/"$USER"/.local/share/pixmaps/${1}.png>" >> "$TMP"
#elif [ -e "/home/"$USER"/.local/share/icons/${1}.png" ]; then
# echo "[exec]( ${1}){$TCEDIR/ondemand/${1}}</home/"$USER"/.local/share/icons/${1}.png>" >> "$TMP"
#elif [ -e "$TCEDIR/ondemand/${1}.img" ]; then
# echo "[exec]( ${1}){$TCEDIR/ondemand/${1}}<$TCEDIR/ondemand/${1}.img>" >> "$TMP"
#elif [ -e "/usr/local/share/pixmaps/${1}.png" ]; then
# echo "[exec]( ${1}){$TCEDIR/ondemand/${1}}</usr/local/share/pixmaps/${1}.png>" >> "$TMP"
else
echo "[exec]( ${1}){$TCEDIR/ondemand/${1}}" >> "$TMP"
fi
#merge "$TMP" "$ONDEMAND" "[end] OnDemand" > "$TMP2"
merge "$TMP" "$ONDEMAND" " [submenu]( ){ on-demand menu }" > "$TMP2"
mv "$TMP2" "$ONDEMAND"
rm "$TMP"
}
if [ -n "$1" ]; then
if [ ! -d "$TCEDIR/ondemand/${1}" ]; then
process "$1"
fi
else
> /home/"$USER"/.fluxbox/ondemand
[ -d "$TCEDIR"/ondemand ] && for O in `ls "$TCEDIR"/ondemand| grep -v ".img$"`; do fluxbox_ondemand ${O}; done
fi
Works for me.
However, I didn't test it in every possible scenario so don't hesitate to complain. q:
Will do the same for Openbox later.
--
Why are spaces removed from names in menus?
gsub(/ /, "", name)