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