"Контекстное меню" пользователя.
Код: Выделить всё
#! /bin/bash
### Define menu actions ###
run () {
case "$1" in
TODO*) ~/bin/export-todo-in-one-string.sh;;
Подключить*) ~/bin/open-dir-GTK3.sh ;;
Редактировать*) emacsclient -c $0 ;;
Выделение_перевести) ~/tools/popup-translate.sh ;;
Подключить_USB) ~/bin/open-dir-GTK3.sh ;;
esac
}
c=0 # set event counter
### Get active window ###
win="$(xprop -id $(xprop -root -f _NET_ACTIVE_WINDOW 0x " \$0\\n" _NET_ACTIVE_WINDOW | awk "{print \$2}") | awk '/WM_CLASS/{print $4}')" # LOL!
### Define menu items ###
N='<item>Menu</item>'
I1='<item>TODO-лист</item>'
I2='<item>Выделение_записать</item>'
I3='<item>Подключить_USB</item>'
I4='<item>Выделение_перевести</item>'
I5=
I6=
I7=
I8=
I9=
I10='<item>Редактировать это меню >></item>'
### Build list menu items ###
# h - menu wihdow height
case "$win" in
\"Xfdesktop\") I0=$N$I1$I10
h=100;;
\"Midori\") I0=$N$I2$I4$I10
h=200;;
\"XTerm\") I0=$N$I4$I10
h=100;;
\"ROX-Filer\") I0=$N$I3$I10
h=100;;
*) I0=$N$I1$I10
h=100;;
esac
### Build menu UI & execute ###
echo '<window window_position="2" title="U-menu">
<vbox>
<tree>
<label>""</label>
'"$I0"'
<width>200</width>
<height>'$h'</height>
<variable>ITEM</variable>
<action signal="changed">echo $ITEM</action>
<action signal="focus-out-event">exit:EXIT</action>
</tree>
</vbox>
</window>' | gtkdialog -s | while read item
do
let c=$c+1
if ((c>1))
then run $item
fi
done
exit 0
Ну а вопрос- на чем/как это можно сделать адекватно?
UPD
Автоматический расчет высоты окна меню (вместо констант в "### Build list menu items ###") :
Код: Выделить всё
### Calculate window height ###
ni=$(echo $I0 | grep -o '<item>' | wc -w)
h=$((($ni-1)*23+50)) # customize!