2 # dash_places_menu.sh - a shell (hopefully dash!) places openbox pipe menu
3 # Copyright (C) 2010 John Crawley
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.
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.
16 # <menu id="places" label="Places" execute="/path/to/dash_places_menu.sh ~" />
17 # to your .config/openbox/menu.xml
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.
23 # path to your "recent files" script, if you want to incorporate it:
24 recent_script="$HOME"/scripts/recently_opened_menu.sh
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
33 # function to open files with default open command, or alternative command for certain files
34 # - add other conditions to choice
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
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 .Xresources .zshrc .fonts.conf .gtkrc-2.0.mine .profile .xsession-errors'
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.
49 #######################################################################
52 # if "--open" option is sent as $1, open file ($2) instead of generating menu
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
60 output='<openbox_pipe_menu>
62 if [ -x "$recent_script" ]
64 output="$output"'<separator label="Recently opened..." />
65 <menu execute="'"$recent_script"'" id="recent" label="files" />
68 echo "$0 : cannot find executable script $recent_script" >&2
71 output='<openbox_pipe_menu>
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; }
79 case "$path" in # only escape if string needs it
80 *\&*|*\<*|*\>*|*\"*|*\'*) pathe=$(sed "s/\&/\&/g;s/</\</g;s/>/\>/g;s/\"/\"/g;s/'/\'/g;") <<XXX
88 *\&apos\;*) pathe_apos=$(sed 's/\'/\'\"\'\"\'/g;')<<XXX
92 *) pathe_apos=$pathe;;
95 output="$output"'<separator label="'$pathe'" />
96 <item label="Explorer ici...">
97 <action name="Execute">
99 ''"$open_folder_cmd"'' ''"$pathe_apos"''
106 unset extra_entries directories_menu files_menu
107 [ "$path" = "$HOME"/ ] && extra_entries="$shown_dotfiles"
108 for i in "$path"* $extra_entries
110 [ -e "$i" ] || continue # only output code if file exists
113 *\&*|*\<*|*\>*|*\"*|*\'*) shortnamee=$(sed "s/\&/\&/g;s/</\</g;s/>/\>/g;s/\"/\"/g;s/'/\'/g;") <<XXX
117 *) shortnamee=$shortname;;
120 *\&apos\;*) shortnamee_apos=$(sed 's/\'/\'\"\'\"\'/g;')<<XXX
124 *) shortnamee_apos=$shortnamee;;
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="''"$0"'' ''"${pathe_apos}${shortnamee_apos}"''" />'; continue; }
131 files_menu="$files_menu"'
132 <item label="'"$shortnamee"'">
133 <action name="Execute">
135 ''"$0"'' --open ''"${pathe_apos}${shortnamee_apos}"''
141 [ -n "$directories_menu" ] && {
142 # NOTE2 comment out next 2 lines if you don't want "Directories" label
143 output="${output}"'<separator label="Dossiers" />
145 output="${output}${directories_menu}"'
147 [ -n "$files_menu" ] && {
148 # NOTE3 comment out next 2 lines if you don't want "Files" label
149 output="${output}"'<separator label="Fichiers" />
151 output="${output}${files_menu}"'
153 output="${output}"'</openbox_pipe_menu>
155 printf '%s' "$output"