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 19th Nov 05:09 (modification of post by johnraff view diff)
View followups from johnraff and aung taejjon | 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.  
  7. # Command to open folders at "Browse here..." - any file manager
  8. open_folder_cmd=thunar
  9. # Default command to open files with - others might be xdg-open, gnome-open, pcmanfm...
  10. default_open_cmd=exo-open  # exo-open comes with thunar
  11. # Text editor of choice
  12. text_editor=gedit
  13.  
  14. # function to open files with default open command, or alternative command for certain files
  15. # - add other conditions to choice
  16. open_file() {
  17.         [ -x "$1" ] && exec "$text_editor" "$1"     # comment out this line if you don't want to edit executables instead of executing
  18.         #[ -x "$1" ] && exec "terminator -e" "$1"     # uncomment this and comment out previous line to run executables in terminal instead of editing
  19.         [ "${1##*.}" = desktop ] && exec "$text_editor" "$1"     # comment out this line if you don't want to edit .desktop files instead of executing
  20.         exec "$default_open_cmd" "$1"     # use default open command if above conditions not satisfied
  21. }
  22.  
  23. # extra dotfiles to display in HOME folder (dotfiles are hidden by default)
  24. # edit the list (space separated) or comment this line out, to taste:
  25. shown_dotfiles='.config .local .Xdefaults .bash_aliases .bashrc .fonts.conf .gtkrc-2.0.mine .profile .xsession-errors'
  26.  
  27. # By default, this script will display directories separately, before files.
  28. # To change this behaviour, see lines 85-87, 100-102 and 106-108.
  29.  
  30. #######################################################################
  31.  
  32. # if "--open" argument is sent as $1, open file ($2) instead of generating menu
  33. [ "$1" = '--open' ] && {
  34. open_file "$2"
  35. exit    # in case exec command fails
  36. }
  37.  
  38. path="${1:-$HOME}"  # default starting place is ~, otherwise $1
  39. path="$( echo "${path}"/ | tr -s '/' )"    # ensure one final slash
  40. [ -d "$path" ] || { echo "$path is not a directory" >&2; exit 1; }
  41.  
  42. # escape xml special characters
  43. escape() {
  44. case "$1" in    # only escape if string needs it
  45. *\&*|*\<*|*\>*|*\"*|*\'*) sed "s/\&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g;s/\"/\&quot;/g;s/'/\&apos;/g;" <<XXX
  46. $1
  47. XXX
  48. ;;
  49. *) printf '%s' "$1";;
  50. esac
  51. }
  52.  
  53. # escape &apos; (originally ') with surrounding '""' for command line
  54. escapos() {
  55. case "$1" in
  56. *\&apos\;*) sed 's/\&apos;/\&apos;\&quot;\&apos;\&quot;\&apos;/g;'<<XXX
  57. $1
  58. XXX
  59. ;;
  60. *) printf '%s' "$1";;
  61. esac
  62. }
  63.  
  64. pathe="$( escape "$path" )"
  65. output='<openbox_pipe_menu>
  66. <separator label="'$pathe'" />
  67. <item label="Browse here...">
  68.         <action name="Execute">
  69.                 <execute>
  70.                  '$open_folder_cmd' "'$(escapos "$pathe" )'"
  71.                 </execute>
  72.         </action>
  73. </item>
  74. <separator />
  75. '
  76.  
  77. unset extra_entries directories_menu files_menu
  78. [ "$path" = "$HOME"/ ] && extra_entries="$shown_dotfiles"
  79. for i in "$path"* $extra_entries
  80. do
  81.     [ -e "$i" ] || continue    # only output code if file exists
  82.         shortname="$(escape "${i##*/}")"
  83.         ie="${pathe}${shortname}"
  84.         [ -d "$i" ] && {
  85. # (note the one single quote at the end) If you want directories and files listed together     
  86. # change next line (directories_menu=$directories_menu') to read:       files_menu=$files_menu'
  87.         directories_menu="$directories_menu"'
  88. <menu id="'"$ie"'" label="'"$shortname"'" execute="&apos;'"$0"'&apos; &apos;'"$(escapos "$ie")"'&apos;" />'; continue; }
  89.         files_menu="$files_menu"'
  90. <item label="'"$shortname"'">
  91.     <action name="Execute">
  92.         <execute>
  93.         &apos;'"$0"'&apos; --open &apos;'"$(escapos "$ie")"'&apos;
  94.         </execute>
  95.     </action>
  96. </item>'
  97. done
  98.  
  99. [ -n "$directories_menu" ] && {
  100. # comment out next 2 lines if you don't want "Directories" label
  101. output="${output}"'<separator label="Directories" />
  102. '
  103. output="${output}${directories_menu}"'
  104. '; }
  105. [ -n "$files_menu" ] && {
  106. # comment out next 2 lines if you don't want "Files" label
  107. output="${output}"'<separator label="Files" />
  108. '
  109. output="${output}${files_menu}"'
  110. '; }
  111. output="${output}"'</openbox_pipe_menu>
  112. '
  113. printf '%s' "$output"
  114. 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