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

Difference between
modified post 1713 by johnraff on Tue 19th Jun 06:11 and
original post 1506 by johnraff on Fri 17th Feb 13:15
Show old version | new version | both versions

    
11
#!/bin/sh
22
#    dash_places_menu.sh - a shell (hopefully dash!) places openbox pipe menu
33
#    Copyright (C) 2010  John Crawley
44
#
55
#    This program is free software: you can redistribute it and/or modify
66
#    it under the terms of the GNU General Public License as published by
77
#    the Free Software Foundation, either version 3 of the License, or
88
#    (at your option) any later version.
99
#
1010
#    This program is distributed in the hope that it will be useful,
1111
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
1212
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1313
#    GNU General Public License for more details.
14-
#    Version 2012/02/17
14+
#    version 2012/06/19
1616
# Usage: add
1717
# <menu id="places" label="Places" execute="/path/to/dash_places_menu.sh ~/" />
1818
# to your .config/openbox/menu.xml
2020
# 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 ~/" />
2222
# make sure you have recently_opened_menu.sh somewhere, and enter its path below.
2424
# path to your "recent files" script, if you want to incorporate it:
2525
recent_script="$HOME"/scripts/recently_opened_menu.sh
2727
# Command to open folders at "Browse here..." - any file manager
2828
open_folder_cmd=thunar
2929
# Default command to open files with - others might be xdg-open, gnome-open, pcmanfm...
3030
default_open_cmd=exo-open  # exo-open comes with thunar
3131
# Text editor of choice
3232
text_editor=geany
3434
# function to open files with default open command, or alternative command for certain files
3535
# - add other conditions to choice
3636
open_file() {
3737
	[ -x "$1" ] && exec "$text_editor" "$1"     # comment out this line if you don't want to edit executables instead of executing
3838
	#[ -x "$1" ] && exec "terminator -e" "$1"     # uncomment this and comment out previous line to run executables in terminal instead of editing
3939
	[ "${1##*.}" = desktop ] && exec "$text_editor" "$1"     # comment out this line if you don't want to edit .desktop files instead of executing
4040
	exec "$default_open_cmd" "$1"     # use default open command if above conditions not satisfied
4141
}
4343
# extra dotfiles to display in HOME folder (dotfiles are hidden by default)
4444
# edit the list (space separated, surrounded by single quotes) or comment this line out, to taste:
4545
shown_dotfiles='.config .local .Xdefaults .bash_aliases .bashrc .fonts.conf .gtkrc-2.0.mine .profile .xsession-errors'
4747
# By default, this script will display directories separately, before files.
4848
# To change this behaviour, see NOTE1, NOTE2 and NOTE3 below, near end of page.
5050
#######################################################################
5252
case $1 in
5353
# if "--open" option is sent as $1, open file ($2) instead of generating menu
5454
--open)
5555
    open_file "$2"
5656
    echo "$0 : failed to open $2" >&2
5757
    exit;;    # in case exec command fails
5858
# if "--recent" option is sent, incorporate "recent files" menu
5959
--recent)
6060
    shift
6161
    output='<openbox_pipe_menu>
6262
'
6363
    if [ -x "$recent_script" ]
6464
    then
6565
        output="$output"'<separator label="Recently opened..." />
6666
<menu execute="'"$recent_script"'" id="recent" label="files" />
6767
'
6868
    else
6969
        echo "$0 : cannot find executable script $recent_script" >&2
7070
    fi;;
7171
*)
7272
    output='<openbox_pipe_menu>
7373
';;
7474
esac
7676
path="${1:-$HOME}"  # default starting place is ~, otherwise $1
7777
path="$( echo "${path}"/ | tr -s '/' )"    # ensure one final slash
7878
[ -d "$path" ] || { echo "$0 : $path is not a directory" >&2; exit 1; }
8080
case "$path" in    # only escape if string needs it
8181
*\&*|*\<*|*\>*|*\"*|*\'*) pathe=$(sed "s/\&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g;s/\"/\&quot;/g;s/'/\&apos;/g;") <<XXX
8282
$path
8383
XXX
8484
;;
8585
*)pathe=$path;;
8686
esac
8888
case "$pathe" in
8989
*\&apos\;*) pathe_apos=$(sed 's/\&apos;/\&apos;\&quot;\&apos;\&quot;\&apos;/g;')<<XXX
9090
$pathe
9191
XXX
9292
;;
9393
*) pathe_apos=$pathe;;
9494
esac
9696
output="$output"'<separator label="'$pathe'" />
9797
<item label="Browse here...">
9898
	<action name="Execute">
9999
		<command>
100100
		 &apos;'"$open_folder_cmd"'&apos; &apos;'"$pathe_apos"'&apos;
101101
		</command>
102102
	</action>
103103
</item>
104104
<separator />
105105
'
107107
unset extra_entries directories_menu files_menu
108108
[ "$path" = "$HOME"/ ] && extra_entries="$shown_dotfiles"
109109
for i in "$path"* $extra_entries
110110
do
111111
    [ -e "$i" ] || continue    # only output code if file exists
112112
    shortname="${i##*/}"
113113
	case $shortname in
114114
	*\&*|*\<*|*\>*|*\"*|*\'*) shortnamee=$(sed "s/\&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g;s/\"/\&quot;/g;s/'/\&apos;/g;") <<XXX
115115
$shortname
116116
XXX
117117
    ;;
118118
    *) shortnamee=$shortname;;
119119
    esac
120120
    case $shortnamee in
121121
    *\&apos\;*) shortnamee_apos=$(sed 's/\&apos;/\&apos;\&quot;\&apos;\&quot;\&apos;/g;')<<XXX
122122
$shortnamee
123123
XXX
124124
    ;;
125125
    *) shortnamee_apos=$shortnamee;;
126126
    esac
127+
    case $shortnamee in
128+
    *_*) shortnamee_label=$(sed 's/_/__/g;')<<XXX
129+
$shortnamee
130+
XXX
131+
    ;;
132+
    *) shortnamee_label=$shortnamee;;
133+
    esac
127134
	[ -d "$i" ] && {
128135
# NOTE1 If you want directories and files listed together
129136
# change next line (directories_menu="$directories_menu"') to read:	files_menu="$files_menu"' (note the one single quote at the end)
130137
	directories_menu="$directories_menu"'
131-
<menu id="'"${pathe_apos}${shortnamee_apos}"'" label="'"$shortnamee"'" execute="&apos;'"$0"'&apos; &apos;'"${pathe_apos}${shortnamee_apos}"'&apos;" />'; continue; }
138+
<menu id="'"${pathe_apos}${shortnamee_apos}"'" label="'"$shortnamee_label"'" execute="&apos;'"$0"'&apos; &apos;'"${pathe_apos}${shortnamee_apos}"'&apos;" />'; continue; }
132139
	files_menu="$files_menu"'
133-
<item label="'"$shortnamee"'">
140+
<item label="'"$shortnamee_label"'">
134141
    <action name="Execute">
135142
        <command>
136143
        &apos;'"$0"'&apos; --open &apos;'"${pathe_apos}${shortnamee_apos}"'&apos;
137144
        </command>
138145
    </action>
139146
</item>'
140147
done
142149
[ -n "$directories_menu" ] && {
143150
# NOTE2 comment out next 2 lines if you don't want "Directories" label
144151
output="${output}"'<separator label="Directories" />
145152
'
146153
output="${output}${directories_menu}"'
147154
'; }
148155
[ -n "$files_menu" ] && {
149156
# NOTE3 comment out next 2 lines if you don't want "Files" label
150157
output="${output}"'<separator label="Files" />
151158
'
152159
output="${output}${files_menu}"'
153160
'; }
154161
output="${output}"'</openbox_pipe_menu>
155162
'
156163
printf '%s' "$output"
157164
exit

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me