CrunchBang Linux Pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

CrunchBang Linux Pastebin

Posted by johnraff on Tue 19th Jun 06:02 (modification of post by johnraff view diff)
diff | download | new post

  1. #!/bin/sh
  2. #    dash_places_menu.sh - a shell (hopefully dash!) places openbox pipe menu
  3. #    Copy#!/bin/sh
  4. #    dash_places_menu.sh - a shell (hopefully dash!) places openbox pipe menu
  5. #    Copyright (C) 2010  John Crawley
  6. #
  7. #    This program is free software: you can redistribute it and/or modify
  8. #    it under the terms of the GNU General Public License as published by
  9. #    the Free Software Foundation, either version 3 of the License, or
  10. #    (at your option) any later version.
  11. #
  12. #    This program is distributed in the hope that it will be useful,
  13. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. #    GNU General Public License for more details.
  16. #    version 2012/06/19
  17.  
  18. # Usage: add
  19. # <menu id="places" label="Places" execute="/path/to/dash_places_menu.sh ~/" />
  20. # to your .config/openbox/menu.xml
  21.  
  22. # or, if you want the "recent files" menu incorporated at the top, use:
  23. # <menu id="places" label="Places" execute="/path/to/dash_places_menu.sh --recent ~/" />
  24. # make sure you have recently_opened_menu.sh somewhere, and enter its path below.
  25.  
  26. # path to your "recent files" script, if you want to incorporate it:
  27. recent_script="$HOME"/scripts/recently_opened_menu.sh
  28.  
  29. # Command to open folders at "Browse here..." - any file manager
  30. open_folder_cmd=thunar
  31. # Default command to open files with - others might be xdg-open, gnome-open, pcmanfm...
  32. default_open_cmd=exo-open  # exo-open comes with thunar
  33. # Text editor of choice
  34. text_editor=geany
  35.  
  36. # function to open files with default open command, or alternative command for certain files
  37. # - add other conditions to choice
  38. open_file() {
  39.         [ -x "$1" ] && exec "$text_editor" "$1"     # comment out this line if you don't want to edit executables instead of executing
  40.         #[ -x "$1" ] && exec "terminator -e" "$1"     # uncomment this and comment out previous line to run executables in terminal instead of editing
  41.         [ "${1##*.}" = desktop ] && exec "$text_editor" "$1"     # comment out this line if you don't want to edit .desktop files instead of executing
  42.         exec "$default_open_cmd" "$1"     # use default open command if above conditions not satisfied
  43. }
  44.  
  45. # extra dotfiles to display in HOME folder (dotfiles are hidden by default)
  46. # edit the list (space separated, surrounded by single quotes) or comment this line out, to taste:
  47. shown_dotfiles='.config .local .Xdefaults .bash_aliases .bashrc .fonts.conf .gtkrc-2.0.mine .profile .xsession-errors'
  48.  
  49. # By default, this script will display directories separately, before files.
  50. # To change this behaviour, see NOTE1, NOTE2 and NOTE3 below, near end of page.
  51.  
  52. #######################################################################
  53.  
  54. case $1 in
  55. # if "--open" option is sent as $1, open file ($2) instead of generating menu
  56. --open)
  57.     open_file "$2"
  58.     echo "$0 : failed to open $2" >&2
  59.     exit;;    # in case exec command fails
  60. # if "--recent" option is sent, incorporate "recent files" menu
  61. --recent)
  62.     shift
  63.     output='<openbox_pipe_menu>
  64. '
  65.     if [ -x "$recent_script" ]
  66.     then
  67.         output="$output"'<separator label="Recently opened..." />
  68. <menu execute="'"$recent_script"'" id="recent" label="files" />
  69. '
  70.     else
  71.         echo "$0 : cannot find executable script $recent_script" >&2
  72.     fi;;
  73. *)
  74.     output='<openbox_pipe_menu>
  75. ';;
  76. esac
  77.  
  78. path="${1:-$HOME}"  # default starting place is ~, otherwise $1
  79. path="$( echo "${path}"/ | tr -s '/' )"    # ensure one final slash
  80. [ -d "$path" ] || { echo "$0 : $path is not a directory" >&2; exit 1; }
  81.  
  82. case "$path" in    # only escape if string needs it
  83. *\&*|*\<*|*\>*|*\"*|*\'*) pathe=$(sed "s/\&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g;s/\"/\&quot;/g;s/'/\&apos;/g;") <<XXX
  84. $path
  85. XXX
  86. ;;
  87. *)pathe=$path;;
  88. esac
  89.  
  90. case "$pathe" in
  91. *\&apos\;*) pathe_apos=$(sed 's/\&apos;/\&apos;\&quot;\&apos;\&quot;\&apos;/g;')<<XXX
  92. $pathe
  93. XXX
  94. ;;
  95. *) pathe_apos=$pathe;;
  96. esac
  97.  
  98. output="$output"'<separator label="'$pathe'" />
  99. <item label="Browse here...">
  100.         <action name="Execute">
  101.                 <command>
  102.                  &apos;'"$open_folder_cmd"'&apos; &apos;'"$pathe_apos"'&apos;
  103.                 </command>
  104.         </action>
  105. </item>
  106. <separator />
  107. '
  108.  
  109. unset extra_entries directories_menu files_menu
  110. [ "$path" = "$HOME"/ ] && extra_entries="$shown_dotfiles"
  111. for i in "$path"* $extra_entries
  112. do
  113.     [ -e "$i" ] || continue    # only output code if file exists
  114.     shortname="${i##*/}"
  115.         case $shortname in
  116.         *\&*|*\<*|*\>*|*\"*|*\'*) shortnamee=$(sed "s/\&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g;s/\"/\&quot;/g;s/'/\&apos;/g;") <<XXX
  117. $shortname
  118. XXX
  119.     ;;
  120.     *) shortnamee=$shortname;;
  121.     esac
  122.     case $shortnamee in
  123.     *\&apos\;*) shortnamee_apos=$(sed 's/\&apos;/\&apos;\&quot;\&apos;\&quot;\&apos;/g;')<<XXX
  124. $shortnamee
  125. XXX
  126.     ;;
  127.     *) shortnamee_apos=$shortnamee;;
  128.     esac
  129.     case $shortnamee in
  130.     *_*) shortnamee_label=$(sed 's/_/__/g;')<<XXX
  131. $shortnamee
  132. XXX
  133.     ;;
  134.     *) shortnamee_label=$shortnamee;;
  135.     esac
  136.         [ -d "$i" ] && {
  137. # NOTE1 If you want directories and files listed together
  138. # change next line (directories_menu="$directories_menu"') to read:     files_menu="$files_menu"' (note the one single quote at the end)
  139.         directories_menu="$directories_menu"'
  140. <menu id="'"${pathe_apos}${shortnamee_apos}"'" label="'"$shortnamee_label"'" execute="&apos;'"$0"'&apos; &apos;'"${pathe_apos}${shortnamee_apos}"'&apos;" />'; continue; }
  141.         files_menu="$files_menu"'
  142. <item label="'"$shortnamee_label"'">
  143.     <action name="Execute">
  144.         <command>
  145.         &apos;'"$0"'&apos; --open &apos;'"${pathe_apos}${shortnamee_apos}"'&apos;
  146.         </command>
  147.     </action>
  148. </item>'
  149. done
  150.  
  151. [ -n "$directories_menu" ] && {
  152. # NOTE2 comment out next 2 lines if you don't want "Directories" label
  153. #output="${output}"'<separator label="Directories" />
  154. #'
  155. output="${output}${directories_menu}"'
  156. '; }
  157. [ -n "$files_menu" ] && {
  158. # NOTE3 comment out next 2 lines if you don't want "Files" label
  159. #output="${output}"'<separator label="Files" />
  160. #'
  161. output="${output}${files_menu}"'
  162. '; }
  163. output="${output}"'</openbox_pipe_menu>
  164. '
  165. printf '%s' "$output"
  166. exit
  167.  
  168. right (C) 2010  John Crawley
  169. #
  170. #    This program is free software: you can redistribute it and/or modify
  171. #    it under the terms of the GNU General Public License as published by
  172. #    the Free Software Foundation, either version 3 of the License, or
  173. #    (at your option) any later version.
  174. #
  175. #    This program is distributed in the hope that it will be useful,
  176. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  177. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  178. #    GNU General Public License for more details.
  179. #    Version 2012/02/17
  180.  
  181. # Usage: add
  182. # <menu id="places" label="Places" execute="/path/to/dash_places_menu.sh ~/" />
  183. # to your .config/openbox/menu.xml
  184.  
  185. # or, if you want the "recent files" menu incorporated at the top, use:
  186. # <menu id="places" label="Places" execute="/path/to/dash_places_menu.sh --recent ~" />
  187. # make sure you have recently_opened_menu.sh somewhere, and enter its path below.
  188.  
  189. # path to your "recent files" script, if you want to incorporate it:
  190. recent_script="$HOME"/scripts/recently_opened_menu.sh
  191.  
  192. # Command to open folders at "Browse here..." - any file manager
  193. open_folder_cmd=thunar
  194. # Default command to open files with - others might be xdg-open, gnome-open, pcmanfm...
  195. default_open_cmd=exo-open  # exo-open comes with thunar
  196. # Text editor of choice
  197. text_editor=geany
  198.  
  199. # function to open files with default open command, or alternative command for certain files
  200. # - add other conditions to choice
  201. open_file() {
  202.         [ -x "$1" ] && exec "$text_editor" "$1"     # comment out this line if you don't want to edit executables instead of executing
  203.         #[ -x "$1" ] && exec "terminator -e" "$1"     # uncomment this and comment out previous line to run executables in terminal instead of editing
  204.         [ "${1##*.}" = desktop ] && exec "$text_editor" "$1"     # comment out this line if you don't want to edit .desktop files instead of executing
  205.         exec "$default_open_cmd" "$1"     # use default open command if above conditions not satisfied
  206. }
  207.  
  208. # extra dotfiles to display in HOME folder (dotfiles are hidden by default)
  209. # edit the list (space separated, surrounded by single quotes) or comment this line out, to taste:
  210. shown_dotfiles='.config .local .Xdefaults .bash_aliases .bashrc .fonts.conf .gtkrc-2.0.mine .profile .xsession-errors'
  211.  
  212. # By default, this script will display directories separately, before files.
  213. # To change this behaviour, see NOTE1, NOTE2 and NOTE3 below, near end of page.
  214.  
  215. #######################################################################
  216.  
  217. case $1 in
  218. # if "--open" option is sent as $1, open file ($2) instead of generating menu
  219. --open)
  220.     open_file "$2"
  221.     echo "$0 : failed to open $2" >&2
  222.     exit;;    # in case exec command fails
  223. # if "--recent" option is sent, incorporate "recent files" menu
  224. --recent)
  225.     shift
  226.     output='<openbox_pipe_menu>
  227. '
  228.     if [ -x "$recent_script" ]
  229.     then
  230.         output="$output"'<separator label="Recently opened..." />
  231. <menu execute="'"$recent_script"'" id="recent" label="files" />
  232. '
  233.     else
  234.         echo "$0 : cannot find executable script $recent_script" >&2
  235.     fi;;
  236. *)
  237.     output='<openbox_pipe_menu>
  238. ';;
  239. esac
  240.  
  241. path="${1:-$HOME}"  # default starting place is ~, otherwise $1
  242. path="$( echo "${path}"/ | tr -s '/' )"    # ensure one final slash
  243. [ -d "$path" ] || { echo "$0 : $path is not a directory" >&2; exit 1; }
  244.  
  245. case "$path" in    # only escape if string needs it
  246. *\&*|*\<*|*\>*|*\"*|*\'*) pathe=$(sed "s/\&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g;s/\"/\&quot;/g;s/'/\&apos;/g;") <<XXX
  247. $path
  248. XXX
  249. ;;
  250. *)pathe=$path;;
  251. esac
  252.  
  253. case "$pathe" in
  254. *\&apos\;*) pathe_apos=$(sed 's/\&apos;/\&apos;\&quot;\&apos;\&quot;\&apos;/g;')<<XXX
  255. $pathe
  256. XXX
  257. ;;
  258. *) pathe_apos=$pathe;;
  259. esac
  260.  
  261. output="$output"'<separator label="'$pathe'" />
  262. <item label="Browse here...">
  263.         <action name="Execute">
  264.                 <command>
  265.                  &apos;'"$open_folder_cmd"'&apos; &apos;'"$pathe_apos"'&apos;
  266.                 </command>
  267.         </action>
  268. </item>
  269. <separator />
  270. '
  271.  
  272. unset extra_entries directories_menu files_menu
  273. [ "$path" = "$HOME"/ ] && extra_entries="$shown_dotfiles"
  274. for i in "$path"* $extra_entries
  275. do
  276.     [ -e "$i" ] || continue    # only output code if file exists
  277.     shortname="${i##*/}"
  278.         case $shortname in
  279.         *\&*|*\<*|*\>*|*\"*|*\'*) shortnamee=$(sed "s/\&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g;s/\"/\&quot;/g;s/'/\&apos;/g;") <<XXX
  280. $shortname
  281. XXX
  282.     ;;
  283.     *) shortnamee=$shortname;;
  284.     esac
  285.     case $shortnamee in
  286.     *\&apos\;*) shortnamee_apos=$(sed 's/\&apos;/\&apos;\&quot;\&apos;\&quot;\&apos;/g;')<<XXX
  287. $shortnamee
  288. XXX
  289.     ;;
  290.     *) shortnamee_apos=$shortnamee;;
  291.     esac
  292.         [ -d "$i" ] && {
  293. # NOTE1 If you want directories and files listed together       
  294. # change next line (directories_menu="$directories_menu"') to read:     files_menu="$files_menu"' (note the one single quote at the end)
  295.         directories_menu="$directories_menu"'
  296. <menu id="'"${pathe_apos}${shortnamee_apos}"'" label="'"$shortnamee"'" execute="&apos;'"$0"'&apos; &apos;'"${pathe_apos}${shortnamee_apos}"'&apos;" />'; continue; }
  297.         files_menu="$files_menu"'
  298. <item label="'"$shortnamee"'">
  299.     <action name="Execute">
  300.         <command>
  301.         &apos;'"$0"'&apos; --open &apos;'"${pathe_apos}${shortnamee_apos}"'&apos;
  302.         </command>
  303.     </action>
  304. </item>'
  305. done
  306.  
  307. [ -n "$directories_menu" ] && {
  308. # NOTE2 comment out next 2 lines if you don't want "Directories" label
  309. output="${output}"'<separator label="Directories" />
  310. '
  311. output="${output}${directories_menu}"'
  312. '; }
  313. [ -n "$files_menu" ] && {
  314. # NOTE3 comment out next 2 lines if you don't want "Files" label
  315. output="${output}"'<separator label="Files" />
  316. '
  317. output="${output}${files_menu}"'
  318. '; }
  319. output="${output}"'</openbox_pipe_menu>
  320. '
  321. printf '%s' "$output"
  322. exit

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me