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 Fri 5th Oct 06:38 (modification of post by johnraff view diff)
diff | download | new post

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