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