#! /bin/bash # kbbmenu.sh - make bb menu from KDE dir structure # quick 'n dirty (also quite slow) script to read KDE menu directory # and print a blackbox menu structure. redirect to some file which # can be typically [include] ed in the blackbox menu file # # takes one argument - the KDE menu directory. if no arguments are # given, defaults to $KDEDIR/share/applnk # # there has to be faster, more elegant, perfect solutions - but I did # this just for me in 10mts since I couldn't get kbbmc to work # # Babu - 99/03/16 # vsbabu@bellatlantic.net http://members.bellatlantic.net/~vsbabu # # known bugs - better make sure you give the right directory, else # you'll probably get null menu entries # - runs reasonably fast on a PIII 500Mhz and then on my 486. startdir=$KDEDIR/share/applnk/ [ $# -eq 1 ]&&startdir=$1 startlevel=`echo $startdir|awk -F'/' '{print NF;}'` #a small function to indent, before printing a row function indentnow() { myindent=`expr $currlevel \* 2` echo|awk '{printf("%'$myindent's"," ");}' } #fetch all the application links in the current directory #process these. recursively for subdirectories function processdir() { currsubmenu=`pwd|awk -F'/' '{print $NF;}'` currlevel=`pwd|awk -F'/' '{print NF;}'` if [ $currlevel -ge $startlevel ] then indentnow echo "[submenu] ($currsubmenu) {$currsubmenu}" currlevel=`expr $currlevel + 1` fi for MENUENTRY in * do # get the name (Name=) and the Executable(Exec=) if [ -s $MENUENTRY -a ! -d $MENUENTRY ] then NAME=`grep "^Name=" $MENUENTRY|cut -f2 -d'='` EXEC=`grep "^Exec=" $MENUENTRY|cut -f2 -d'='|\ sed 's/"//g'|sed "s/-caption//g"|sed "s/%/g"` #captions and KDE's % variables screw up in #bb (atleast mine) indentnow echo "[exec] (${NAME}) {${EXEC}}" elif [ -d $MENUENTRY ] then cd $MENUENTRY processdir cd .. fi done if [ $currlevel -ge $startlevel ] then currlevel=`expr $currlevel - 1` indentnow echo "[end]" fi } #### # MAIN - entry point ## cd $startdir && processdir