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 1879 by johnraff on Fri 5th Oct 06:38 and
original post 1713 by johnraff on Tue 19th Jun 06:11
Show old version | new version | both versions

    
11
#!/bin/sh
2-
#    dash_places_menu.sh - a shell (hopefully dash!) places openbox pipe menu
2+
#    dash_places_menu.sh - a 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/06/19
14+
#    version 2012/09/27
16+
#    NB The shell, not bash, is invoked in the hope that
17+
#    dash will be used, as it is much faster.
1619
# Usage: add
1720
# <menu id="places" label="Places" execute="/path/to/dash_places_menu.sh ~/" />
1821
# to your .config/openbox/menu.xml
2023
# or, if you want the "recent files" menu incorporated at the top, use:
2124
# <menu id="places" label="Places" execute="/path/to/dash_places_menu.sh --recent ~/" />
2225
# make sure you have recently_opened_menu.sh somewhere, and enter its path below.
2427
# path to your "recent files" script, if you want to incorporate it:
2528
recent_script="$HOME"/scripts/recently_opened_menu.sh
2730
# Command to open folders at "Browse here..." - any file manager
2831
open_folder_cmd=thunar
2932
# Default command to open files with - others might be xdg-open, gnome-open, pcmanfm...
3033
default_open_cmd=exo-open  # exo-open comes with thunar
3134
# Text editor of choice
3235
text_editor=geany
3437
# function to open files with default open command, or alternative command for certain files
3538
# - add other conditions to choice
3639
open_file() {
3740
	[ -x "$1" ] && exec "$text_editor" "$1"     # comment out this line if you don't want to edit executables instead of executing
3841
	#[ -x "$1" ] && exec "terminator -e" "$1"     # uncomment this and comment out previous line to run executables in terminal instead of editing
3942
	[ "${1##*.}" = desktop ] && exec "$text_editor" "$1"     # comment out this line if you don't want to edit .desktop files instead of executing
4043
	exec "$default_open_cmd" "$1"     # use default open command if above conditions not satisfied
4144
}
4346
# extra dotfiles to display in HOME folder (dotfiles are hidden by default)
4447
# edit the list (space separated, surrounded by single quotes) or comment this line out, to taste:
4548
shown_dotfiles='.config .local .Xdefaults .bash_aliases .bashrc .fonts.conf .gtkrc-2.0.mine .profile .xsession-errors'
4750
# By default, this script will display directories separately, before files.
4851
# To change this behaviour, see NOTE1, NOTE2 and NOTE3 below, near end of page.
5053
#######################################################################
5255
case $1 in
5356
# if "--open" option is sent as $1, open file ($2) instead of generating menu
5457
--open)
5558
    open_file "$2"
5659
    echo "$0 : failed to open $2" >&2
5760
    exit;;    # in case exec command fails
5861
# if "--recent" option is sent, incorporate "recent files" menu
5962
--recent)
6063
    shift
6164
    output='<openbox_pipe_menu>
6265
'
6366
    if [ -x "$recent_script" ]
6467
    then
6568
        output="$output"'<separator label="Recently opened..." />
6669
<menu execute="'"$recent_script"'" id="recent" label="files" />
6770
'
6871
    else
6972
        echo "$0 : cannot find executable script $recent_script" >&2
7073
    fi;;
7174
*)
7275
    output='<openbox_pipe_menu>
7376
';;
7477
esac
7679
path="${1:-$HOME}"  # default starting place is ~, otherwise $1
7780
path="$( echo "${path}"/ | tr -s '/' )"    # ensure one final slash
7881
[ -d "$path" ] || { echo "$0 : $path is not a directory" >&2; exit 1; }
8083
case "$path" in    # only escape if string needs it
81-
*\&*|*\<*|*\>*|*\"*|*\'*) pathe=$(sed "s/\&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g;s/\"/\&quot;/g;s/'/\&apos;/g;") <<XXX
84+
*\&*|*\<*|*\>*|*\"*|*\'*) pathe=$(sed "s/\&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g;s/\"/\&quot;/g;s/'/\&apos;/g;" <<XXX
8285
$path
8386
XXX
87+
)
8488
;;
8589
*)pathe=$path;;
8690
esac
8892
case "$pathe" in
89-
*\&apos\;*) pathe_apos=$(sed 's/\&apos;/\&apos;\&quot;\&apos;\&quot;\&apos;/g;')<<XXX
93+
*\&apos\;*) pathe_apos=$(sed 's/\&apos;/\&apos;\&quot;\&apos;\&quot;\&apos;/g;'<<XXX
9094
$pathe
9195
XXX
96+
)
9297
;;
9398
*) pathe_apos=$pathe;;
9499
esac
96101
output="$output"'<separator label="'$pathe'" />
97102
<item label="Browse here...">
98103
	<action name="Execute">
99104
		<command>
100105
		 &apos;'"$open_folder_cmd"'&apos; &apos;'"$pathe_apos"'&apos;
101106
		</command>
102107
	</action>
103108
</item>
104109
<separator />
105110
'
107112
unset extra_entries directories_menu files_menu
108113
[ "$path" = "$HOME"/ ] && extra_entries="$shown_dotfiles"
109114
for i in "$path"* $extra_entries
110115
do
111116
    [ -e "$i" ] || continue    # only output code if file exists
112117
    shortname="${i##*/}"
113118
	case $shortname in
114-
	*\&*|*\<*|*\>*|*\"*|*\'*) shortnamee=$(sed "s/\&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g;s/\"/\&quot;/g;s/'/\&apos;/g;") <<XXX
119+
	*\&*|*\<*|*\>*|*\"*|*\'*) shortnamee=$(sed "s/\&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g;s/\"/\&quot;/g;s/'/\&apos;/g;" <<XXX
115120
$shortname
116121
XXX
122+
)
117123
    ;;
118124
    *) shortnamee=$shortname;;
119125
    esac
120126
    case $shortnamee in
121-
    *\&apos\;*) shortnamee_apos=$(sed 's/\&apos;/\&apos;\&quot;\&apos;\&quot;\&apos;/g;')<<XXX
127+
    *\&apos\;*) shortnamee_apos=$(sed 's/\&apos;/\&apos;\&quot;\&apos;\&quot;\&apos;/g;'<<XXX
122128
$shortnamee
123129
XXX
130+
)
124131
    ;;
125132
    *) shortnamee_apos=$shortnamee;;
126133
    esac
127134
    case $shortnamee in
128-
    *_*) shortnamee_label=$(sed 's/_/__/g;')<<XXX
135+
    *_*) shortnamee_label=$(sed 's/_/__/g;'<<XXX
129136
$shortnamee
130137
XXX
138+
)
131139
    ;;
132140
    *) shortnamee_label=$shortnamee;;
133141
    esac
134142
	[ -d "$i" ] && {
135143
# NOTE1 If you want directories and files listed together
136144
# change next line (directories_menu="$directories_menu"') to read:	files_menu="$files_menu"' (note the one single quote at the end)
137145
	directories_menu="$directories_menu"'
138146
<menu id="'"${pathe_apos}${shortnamee_apos}"'" label="'"$shortnamee_label"'" execute="&apos;'"$0"'&apos; &apos;'"${pathe_apos}${shortnamee_apos}"'&apos;" />'; continue; }
139147
	files_menu="$files_menu"'
140148
<item label="'"$shortnamee_label"'">
141149
    <action name="Execute">
142150
        <command>
143151
        &apos;'"$0"'&apos; --open &apos;'"${pathe_apos}${shortnamee_apos}"'&apos;
144152
        </command>
145153
    </action>
146154
</item>'
147155
done
149157
[ -n "$directories_menu" ] && {
150158
# NOTE2 comment out next 2 lines if you don't want "Directories" label
151-
output="${output}"'<separator label="Directories" />
159+
#output="${output}"'<separator label="Directories" />
152-
'
160+
#'
153161
output="${output}${directories_menu}"'
154162
'; }
155163
[ -n "$files_menu" ] && {
156164
# NOTE3 comment out next 2 lines if you don't want "Files" label
157-
output="${output}"'<separator label="Files" />
165+
#output="${output}"'<separator label="Files" />
166+
#'
167+
output="${output}${files_menu}"'
168+
'; }
169+
output="${output}"'</openbox_pipe_menu>
158-
'
159167
output="${output}${files_menu}"'
160168
'; }
161169
output="${output}"'</openbox_pipe_menu>
162170
'
163171
printf '%s' "$output"
164172
exit

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me