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 Mon 22nd Nov 16:10 (modification of post by johnraff view diff)
View followups from johnraff | diff | download | new post

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