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:11 (modification of post by johnraff view diff)
View followups from johnraff | diff | download | new post

  1. #!/bin/sh
  2. #    dash_places_menu.sh - a shell (hopefully dash!) places openbox pipe menu
  3. #    Copyright (C) 2010  John Crawley
  4. #
  5. #    This program is free software: you can redistribute it and/or modify
  6. #    it under the terms of the GNU General Public License as published by
  7. #    the Free Software Foundation, either version 3 of the License, or
  8. #    (at your option) any later version.
  9. #
  10. #    This program is distributed in the hope that it will be useful,
  11. #    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. #    GNU General Public License for more details.
  14. #    version 2012/06/19
  15.  
  16. # Usage: add
  17. # <menu id="places" label="Places" execute="/path/to/dash_places_menu.sh ~/" />
  18. # to your .config/openbox/menu.xml
  19.  
  20. # or, if you want the "recent files" menu incorporated at the top, use:
  21. # <menu id="places" label="Places" execute="/path/to/dash_places_menu.sh --recent ~/" />
  22. # make sure you have recently_opened_menu.sh somewhere, and enter its path below.
  23.  
  24. # path to your "recent files" script, if you want to incorporate it:
  25. recent_script="$HOME"/scripts/recently_opened_menu.sh
  26.  
  27. # Command to open folders at "Browse here..." - any file manager
  28. open_folder_cmd=thunar
  29. # Default command to open files with - others might be xdg-open, gnome-open, pcmanfm...
  30. default_open_cmd=exo-open  # exo-open comes with thunar
  31. # Text editor of choice
  32. text_editor=geany
  33.  
  34. # function to open files with default open command, or alternative command for certain files
  35. # - add other conditions to choice
  36. open_file() {
  37.         [ -x "$1" ] && exec "$text_editor" "$1"     # comment out this line if you don't want to edit executables instead of executing
  38.         #[ -x "$1" ] && exec "terminator -e" "$1"     # uncomment this and comment out previous line to run executables in terminal instead of editing
  39.         [ "${1##*.}" = desktop ] && exec "$text_editor" "$1"     # comment out this line if you don't want to edit .desktop files instead of executing
  40.         exec "$default_open_cmd" "$1"     # use default open command if above conditions not satisfied
  41. }
  42.  
  43. # extra dotfiles to display in HOME folder (dotfiles are hidden by default)
  44. # edit the list (space separated, surrounded by single quotes) or comment this line out, to taste:
  45. shown_dotfiles='.config .local .Xdefaults .bash_aliases .bashrc .fonts.conf .gtkrc-2.0.mine .profile .xsession-errors'
  46.  
  47. # By default, this script will display directories separately, before files.
  48. # To change this behaviour, see NOTE1, NOTE2 and NOTE3 below, near end of page.
  49.  
  50. #######################################################################
  51.  
  52. case $1 in
  53. # if "--open" option is sent as $1, open file ($2) instead of generating menu
  54. --open)
  55.     open_file "$2"
  56.     echo "$0 : failed to open $2" >&2
  57.     exit;;    # in case exec command fails
  58. # if "--recent" option is sent, incorporate "recent files" menu
  59. --recent)
  60.     shift
  61.     output='<openbox_pipe_menu>
  62. '
  63.     if [ -x "$recent_script" ]
  64.     then
  65.         output="$output"'<separator label="Recently opened..." />
  66. <menu execute="'"$recent_script"'" id="recent" label="files" />
  67. '
  68.     else
  69.         echo "$0 : cannot find executable script $recent_script" >&2
  70.     fi;;
  71. *)
  72.     output='<openbox_pipe_menu>
  73. ';;
  74. esac
  75.  
  76. path="${1:-$HOME}"  # default starting place is ~, otherwise $1
  77. path="$( echo "${path}"/ | tr -s '/' )"    # ensure one final slash
  78. [ -d "$path" ] || { echo "$0 : $path is not a directory" >&2; exit 1; }
  79.  
  80. case "$path" in    # only escape if string needs it
  81. *\&*|*\<*|*\>*|*\"*|*\'*) pathe=$(sed "s/\&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g;s/\"/\&quot;/g;s/'/\&apos;/g;") <<XXX
  82. $path
  83. XXX
  84. ;;
  85. *)pathe=$path;;
  86. esac
  87.  
  88. case "$pathe" in
  89. *\&apos\;*) pathe_apos=$(sed 's/\&apos;/\&apos;\&quot;\&apos;\&quot;\&apos;/g;')<<XXX
  90. $pathe
  91. XXX
  92. ;;
  93. *) pathe_apos=$pathe;;
  94. esac
  95.  
  96. output="$output"'<separator label="'$pathe'" />
  97. <item label="Browse here...">
  98.         <action name="Execute">
  99.                 <command>
  100.                  &apos;'"$open_folder_cmd"'&apos; &apos;'"$pathe_apos"'&apos;
  101.                 </command>
  102.         </action>
  103. </item>
  104. <separator />
  105. '
  106.  
  107. unset extra_entries directories_menu files_menu
  108. [ "$path" = "$HOME"/ ] && extra_entries="$shown_dotfiles"
  109. for i in "$path"* $extra_entries
  110. do
  111.     [ -e "$i" ] || continue    # only output code if file exists
  112.     shortname="${i##*/}"
  113.         case $shortname in
  114.         *\&*|*\<*|*\>*|*\"*|*\'*) shortnamee=$(sed "s/\&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g;s/\"/\&quot;/g;s/'/\&apos;/g;") <<XXX
  115. $shortname
  116. XXX
  117.     ;;
  118.     *) shortnamee=$shortname;;
  119.     esac
  120.     case $shortnamee in
  121.     *\&apos\;*) shortnamee_apos=$(sed 's/\&apos;/\&apos;\&quot;\&apos;\&quot;\&apos;/g;')<<XXX
  122. $shortnamee
  123. XXX
  124.     ;;
  125.     *) shortnamee_apos=$shortnamee;;
  126.     esac
  127.     case $shortnamee in
  128.     *_*) shortnamee_label=$(sed 's/_/__/g;')<<XXX
  129. $shortnamee
  130. XXX
  131.     ;;
  132.     *) shortnamee_label=$shortnamee;;
  133.     esac
  134.         [ -d "$i" ] && {
  135. # NOTE1 If you want directories and files listed together
  136. # change next line (directories_menu="$directories_menu"') to read:     files_menu="$files_menu"' (note the one single quote at the end)
  137.         directories_menu="$directories_menu"'
  138. <menu id="'"${pathe_apos}${shortnamee_apos}"'" label="'"$shortnamee_label"'" execute="&apos;'"$0"'&apos; &apos;'"${pathe_apos}${shortnamee_apos}"'&apos;" />'; continue; }
  139.         files_menu="$files_menu"'
  140. <item label="'"$shortnamee_label"'">
  141.     <action name="Execute">
  142.         <command>
  143.         &apos;'"$0"'&apos; --open &apos;'"${pathe_apos}${shortnamee_apos}"'&apos;
  144.         </command>
  145.     </action>
  146. </item>'
  147. done
  148.  
  149. [ -n "$directories_menu" ] && {
  150. # NOTE2 comment out next 2 lines if you don't want "Directories" label
  151. output="${output}"'<separator label="Directories" />
  152. '
  153. output="${output}${directories_menu}"'
  154. '; }
  155. [ -n "$files_menu" ] && {
  156. # NOTE3 comment out next 2 lines if you don't want "Files" label
  157. output="${output}"'<separator label="Files" />
  158. '
  159. output="${output}${files_menu}"'
  160. '; }
  161. output="${output}"'</openbox_pipe_menu>
  162. '
  163. printf '%s' "$output"
  164. 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