menumanager 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. #!/bin/bash
  2. # 131222 01micko, script to manage what .desktop files show in menu
  3. # must be run as root
  4. [ "$UID" = 0 ]|| exec sudo -A ${0} ${@}
  5. CWM=`cat /etc/windowmanager`
  6. JWM_MENU_HEIGHT=
  7. if [ "$CWM" = "jwm" ];then
  8. MENHEIGHT=16
  9. [ -f $HOME/.jwm/menuheights ] && . $HOME/.jwm/menuheights
  10. MENU=`grep "RootMenu label" /etc/xdg/templates/_root_.jwmrc|grep MENHEIGHT`
  11. [ "$MENU" ] && JWM_MENU_HEIGHT='
  12. <vbox space-expand="false" space-fill="false">
  13. <frame '$(gettext "Menu Heights")'>
  14. <hbox space-fill="true" space-expand="true">
  15. <text space-expand="false" space-fill="false"><label>" "</label></text>
  16. <text wrap="false" xalign="0" space-expand="true" space-fill="true"><label>'$(gettext "You can adjust the heights of the menus in pixels :")' </label></text>
  17. <spinbutton range-min="16" range-max="48" range-step="8" editable="false" space-expand="false" space-fill="false">
  18. <variable>NEWMENHEIGHT</variable>
  19. <default>'$MENHEIGHT'</default>
  20. <sensitive>true</sensitive>
  21. </spinbutton>
  22. </hbox>
  23. </frame>
  24. </vbox>'
  25. fi
  26. tmp=${RANDOM}
  27. export TMP0=/tmp/${tmp}0
  28. export TMP1=/tmp/${tmp}1
  29. export TMP2=/tmp/${tmp}2
  30. export DIR=/usr/share/applications
  31. # potential shown list(s)
  32. grep -E "^Icon=" ${DIR}/* | awk -F: '{print $1}' > $TMP0
  33. # enabled list
  34. echo -n '' > $TMP1
  35. while read fline
  36. do
  37. grep -q -E "^NoDisplay=" $fline
  38. case $? in
  39. 0)FALSE=`grep -E "^NoDisplay=" $fline | grep "false"`
  40. [ "$FALSE" ] && echo ${fline##*/} >> $TMP1
  41. ;;
  42. *)echo ${fline##*/} >> $TMP1
  43. ;;
  44. esac
  45. done < $TMP0
  46. # disabled list
  47. echo -n '' > $TMP2
  48. while read tline
  49. do
  50. grep -q -E "^NoDisplay=true" $tline
  51. [ "$?" -eq 0 ] && echo ${tline##*/} >> $TMP2
  52. done < $TMP0
  53. #loop used for multiple selections when holding ctrl when clicking
  54. # move to disabled
  55. move_right() {
  56. if [ "$YLIST" != "" ];then
  57. for Y in $YLIST
  58. do
  59. grep -q $Y $TMP2
  60. if [ $? != 0 ];then
  61. /usr/lib/gtkdialog/box_splash -timeout 1 -bg red -close box -text "$(gettext 'Removing') ${Y} $(gettext 'from menu.')"
  62. echo $Y >> $TMP2
  63. sed -i "/$Y/d" $TMP1
  64. fi
  65. done
  66. else
  67. /usr/lib/gtkdialog/box_splash -timeout 2 -close never -text "$(gettext 'Nothing selected in left pane')" &
  68. fi
  69. return
  70. }
  71. export -f move_right
  72. # move to enabled
  73. move_left() {
  74. if [ "$NLIST" != "" ];then
  75. for N in $NLIST
  76. do
  77. grep -q $N $TMP1
  78. if [ $? != 0 ];then
  79. /usr/lib/gtkdialog/box_splash -timeout 1 -bg green -close box -text "$(gettext 'Enabling') ${N} $(gettext 'at startup.')"
  80. echo $N >> $TMP1
  81. sed -i "/$N/d" $TMP2
  82. fi
  83. done
  84. else
  85. /usr/lib/gtkdialog/box_splash -timeout 2 -close never -text "$(gettext 'Nothing selected in right pane')" &
  86. fi
  87. return
  88. }
  89. export -f move_left
  90. export menuManager='
  91. <window title="'$(gettext "Menu Manager")'" icon-name="gtk-properties">
  92. <vbox space-fill="true" space-expand="true">
  93. '"`/usr/lib/gtkdialog/xml_info fixed menu.svg 60 "$(gettext "This application controls what apps are set to show in the menu on your system.")"`"'
  94. <vbox space-fill="true" space-expand="true">
  95. <frame '$(gettext "Currently Menu Items")'>
  96. <vbox border-width="10" space-expand="false" space-fill="false">
  97. <text wrap="false" xalign="0" use-markup="true" space-expand="false" space-fill="false"><label>"'$(gettext "<b>Remove</b> an app from the menu by highlighting in the left pane and pressing <b>−</b>.")'"</label></text>
  98. <text wrap="false" xalign="0" use-markup="true" space-expand="false" space-fill="false"><label>"'$(gettext "<b>Add</b> an app to the menu by highlighting in the right pane and pressing <b>+</b>.")'"</label></text>
  99. </vbox>
  100. <hbox height-request="146" space-fill="true" space-expand="true">
  101. <hbox space-fill="true" space-expand="true">
  102. <tree selection-mode="3">
  103. <variable>YLIST</variable>
  104. <label>'$(gettext "Enabled Menu Items")'</label>
  105. <input>cat '"$TMP1"'</input>
  106. </tree>
  107. </hbox>
  108. <vbox homogeneous="true" space-fill="false" space-expand="false">
  109. <vbox space-fill="false" space-expand="false">
  110. <button border-width="3">
  111. '"`/usr/lib/gtkdialog/xml_button-icon remove`"'
  112. <action>move_right</action>
  113. <action>refresh:YLIST</action>
  114. <action>refresh:NLIST</action>
  115. </button>
  116. <button border-width="3">
  117. '"`/usr/lib/gtkdialog/xml_button-icon add`"'
  118. <action>move_left</action>
  119. <action>refresh:YLIST</action>
  120. <action>refresh:NLIST</action>
  121. </button>
  122. </vbox>
  123. </vbox>
  124. <tree selection-mode="3">
  125. <variable>NLIST</variable>
  126. <label>'$(gettext "Disabled Menu Items")'</label>
  127. <input>cat '"$TMP2"'</input>
  128. </tree>
  129. </hbox>
  130. </frame>
  131. </vbox>
  132. '$JWM_MENU_HEIGHT'
  133. <hbox space-expand="false" space-fill="false">
  134. <button space-expand="false" space-fill="false">
  135. <label>'$(gettext "Cancel")'</label>
  136. '"`/usr/lib/gtkdialog/xml_button-icon cancel`"'
  137. <action>exit:Cancel</action>
  138. </button>
  139. <button space-expand="false" space-fill="false">
  140. <label>'$(gettext "Ok")'</label>
  141. '"`/usr/lib/gtkdialog/xml_button-icon ok`"'
  142. <action>exit:OK</action>
  143. </button>
  144. '"`/usr/lib/gtkdialog/xml_scalegrip`"'
  145. </hbox>
  146. </vbox>
  147. </window>'
  148. . /usr/lib/gtkdialog/xml_info gtk #build bg_pixmap for gtk-theme
  149. eval $(gtkdialog -p menuManager)
  150. case $EXIT in
  151. OK)
  152. # add to enabled
  153. while read line1; do
  154. [ -f ${DIR}/${line1} ] && \
  155. sed -i "s%NoDisplay=true%NoDisplay=false%" ${DIR}/${line1}
  156. done < $TMP1
  157. # add to disabled
  158. while read line2; do
  159. [ -f ${DIR}/${line2} ] && \
  160. grep -q "^NoDisplay=" ${DIR}/${line2}
  161. if [ "$?" -eq 0 ];then
  162. sed -i "s%NoDisplay=false%NoDisplay=true%" ${DIR}/${line2}
  163. else
  164. echo "NoDisplay=true" >> ${DIR}/${line2}
  165. fi
  166. done < $TMP2
  167. # menu heights
  168. if [ "$NEWMENHEIGHT" != "$MENHEIGHT" ];then
  169. if [ "$NEWMENHEIGHT" = 16 ];then
  170. [ -f $HOME/.jwm/menuheights ] && rm $HOME/.jwm/menuheights
  171. else
  172. echo "MENHEIGHT=$NEWMENHEIGHT" > $HOME/.jwm/menuheights
  173. fi
  174. fi
  175. # fix menu
  176. /usr/lib/gtkdialog/box_splash -close never -text "$(gettext 'Please wait...')" &
  177. pid=$!
  178. fixmenus
  179. ps -A | grep -q "jwm" && (jwm -reload || jwm -restart)
  180. kill -9 $pid
  181. rm $TMP0; rm $TMP1; rm $TMP2
  182. sleep 1;;
  183. *)rm $TMP0; rm $TMP1; rm $TMP2;;
  184. esac