| | | |
| 1 | 1 | | #!/bin/sh |
| 2 | 2 | | # shell (hopefully dash!) places menu for openbox |
| 3 | 3 | | # Usage: add |
| 4 | 4 | | # <menu id="places" label="Places" execute="/path/to/dash_places_menu.sh ~" /> |
| 5 | 5 | | # to your .config/openbox/menu.xml (you don't need a final slash after the ~) |
| 6 | 6 | | # or, if you want the "recent files" menu incorporated at the top, use: |
| 7 | 7 | | # <menu id="places" label="Places" execute="/path/to/dash_places_menu.sh --recent ~" /> |
| 8 | 8 | | # make sure you have recently_opened_menu.sh somewhere, and enter its path below. |
| 10 | 10 | | # path to your "recent files" script, if you want to incorporate it: |
| 11 | 11 | | recent_script="$HOME"/scripts/recently_opened_menu.sh |
| 13 | 13 | | # Command to open folders at "Browse here..." - any file manager |
| 14 | 14 | | open_folder_cmd=thunar |
| 15 | 15 | | # Default command to open files with - others might be xdg-open, gnome-open, pcmanfm... |
| 16 | 16 | | default_open_cmd=exo-open # exo-open comes with thunar |
| 17 | 17 | | # Text editor of choice |
| 18 | 18 | | text_editor=gedit |
| 20 | 20 | | # function to open files with default open command, or alternative command for certain files |
| 21 | 21 | | # - add other conditions to choice |
| 22 | 22 | | open_file() { |
| 23 | 23 | | [ -x "$1" ] && exec "$text_editor" "$1" # comment out this line if you don't want to edit executables instead of executing |
| 24 | 24 | | #[ -x "$1" ] && exec "terminator -e" "$1" # uncomment this and comment out previous line to run executables in terminal instead of editing |
| 25 | 25 | | [ "${1##*.}" = desktop ] && exec "$text_editor" "$1" # comment out this line if you don't want to edit .desktop files instead of executing |
| 26 | 26 | | exec "$default_open_cmd" "$1" # use default open command if above conditions not satisfied |
| 27 | 27 | | } |
| 29 | 29 | | # extra dotfiles to display in HOME folder (dotfiles are hidden by default) |
| 30 | 30 | | # edit the list (space separated, surrounded by single quotes) or comment this line out, to taste: |
| 31 | 31 | | shown_dotfiles='.config .local .Xdefaults .bash_aliases .bashrc .fonts.conf .gtkrc-2.0.mine .profile .xsession-errors' |
| 33 | 33 | | # By default, this script will display directories separately, before files. |
| 34 | 34 | | # To change this behaviour, see NOTE1, NOTE2 and NOTE3 below. |
| 36 | 36 | | ####################################################################### |
| 38 | + | case $1 in |
| 38 | 39 | | # if "--open" option is sent as $1, open file ($2) instead of generating menu |
| 39 | | - | [ "$1" = '--open' ] && { |
| 40 | + | --open) |
| 40 | 41 | | open_file "$2" |
| 41 | 42 | | echo "$0 : failed to open $2" >&2 |
| 42 | | - | exit # in case exec command fails |
| 43 | + | exit;; # in case exec command fails |
| 43 | | - | } |
| 45 | | - | output='<openbox_pipe_menu> |
| 46 | | - | ' |
| 47 | 44 | | # if "--recent" option is sent, incorporate "recent files" menu |
| 48 | | - | [ "$1" = '--recent' ] && { |
| 45 | + | --recent) |
| 49 | 46 | | shift |
| 47 | + | output='<openbox_pipe_menu> |
| 48 | + | ' |
| 50 | 49 | | if [ -x "$recent_script" ] |
| 51 | 50 | | then |
| 52 | | - | output="$output"'<separator label="Recent Files" /> |
| 51 | + | output="$output"'<separator label="Recently opened..." /> |
| 53 | | - | <menu execute="'"$recent_script"'" id="recent" label="Recent Files" /> |
| 52 | + | <menu execute="'"$recent_script"'" id="recent" label="Files" /> |
| 54 | 53 | | ' |
| 55 | 54 | | else |
| 56 | 55 | | echo "$0 : cannot find executable script $recent_script" >&2 |
| 57 | | - | fi |
| 56 | + | fi;; |
| 58 | | - | } |
| 57 | + | *) |
| 58 | + | output='<openbox_pipe_menu> |
| 59 | + | ';; |
| 60 | + | esac |
| 60 | 62 | | path="${1:-$HOME}" # default starting place is ~, otherwise $1 |
| 61 | 63 | | path="$( echo "${path}"/ | tr -s '/' )" # ensure one final slash |
| 62 | 64 | | [ -d "$path" ] || { echo "$0 : $path is not a directory" >&2; exit 1; } |
| 64 | | - | # escape xml special characters |
| 66 | + | case "$path" in # only escape if string needs it |
| 65 | | - | escape() { |
| 67 | + | *\&*|*\<*|*\>*|*\"*|*\'*) pathe=$(sed "s/\&/\&/g;s/</\</g;s/>/\>/g;s/\"/\"/g;s/'/\'/g;") <<XXX |
| 66 | | - | case "$1" in # only escape if string needs it |
| 68 | + | $path |
| 67 | | - | *\&*|*\<*|*\>*|*\"*|*\'*) sed "s/\&/\&/g;s/</\</g;s/>/\>/g;s/\"/\"/g;s/'/\'/g;" <<XXX |
| 68 | | - | $1 |
| 69 | 69 | | XXX |
| 70 | 70 | | ;; |
| 71 | | - | *) printf '%s' "$1";; |
| 71 | + | *)pathe=$path;; |
| 72 | 72 | | esac |
| 73 | | - | } |
| 75 | | - | # escape ' (originally ') with surrounding '""' for command line |
| 74 | + | case "$pathe" in |
| 76 | | - | escapos() { |
| 75 | + | *\&apos\;*) pathe_apos=$(sed 's/\'/\'\"\'\"\'/g;')<<XXX |
| 77 | | - | case "$1" in |
| 76 | + | $pathe |
| 78 | | - | *\&apos\;*) sed 's/\'/\'\"\'\"\'/g;'<<XXX |
| 79 | | - | $1 |
| 80 | 77 | | XXX |
| 81 | 78 | | ;; |
| 82 | | - | *) printf '%s' "$1";; |
| 79 | + | *) pathe_apos=$pathe;; |
| 83 | 80 | | esac |
| 84 | | - | } |
| 86 | | - | pathe="$( escape "$path" )" |
| 82 | + | output="$output"'<separator label="'$pathe'" /> |