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 835 by johnraff on Sat 20th Nov 16:38 and
original post 834 by johnraff on Fri 19th Nov 05:09
Show old version | new version | both versions

    
11
#!/bin/sh
22
# shell (hopefully dash!) places menu for openbox
33
# Usage: add
44
# <menu id="places" label="Places" execute="/path/to/dash_places_menu.sh ~" />
55
# to your .config/openbox/menu.xml (you don't need a final slash after the ~)
6+
# or, if you want the "recent files" menu incorporated at the top, use:
7+
# <menu id="places" label="Places" execute="/path/to/dash_places_menu.sh --recent ~" />
8+
# make sure you have recently_opened_menu.sh somewhere, and enter its path below.
10+
# path to your "recent files" script, if you want to incorporate it:
11+
recent_script="$HOME"/scripts/recently_opened_menu.sh
713
# Command to open folders at "Browse here..." - any file manager
814
open_folder_cmd=thunar
915
# Default command to open files with - others might be xdg-open, gnome-open, pcmanfm...
1016
default_open_cmd=exo-open  # exo-open comes with thunar
1117
# Text editor of choice
1218
text_editor=gedit
1420
# function to open files with default open command, or alternative command for certain files
1521
# - add other conditions to choice
1622
open_file() {
1723
	[ -x "$1" ] && exec "$text_editor" "$1"     # comment out this line if you don't want to edit executables instead of executing
1824
	#[ -x "$1" ] && exec "terminator -e" "$1"     # uncomment this and comment out previous line to run executables in terminal instead of editing
1925
	[ "${1##*.}" = desktop ] && exec "$text_editor" "$1"     # comment out this line if you don't want to edit .desktop files instead of executing
2026
	exec "$default_open_cmd" "$1"     # use default open command if above conditions not satisfied
2127
}
2329
# extra dotfiles to display in HOME folder (dotfiles are hidden by default)
24-
# edit the list (space separated) or comment this line out, to taste:
30+
# edit the list (space separated, surrounded by single quotes) or comment this line out, to taste:
2531
shown_dotfiles='.config .local .Xdefaults .bash_aliases .bashrc .fonts.conf .gtkrc-2.0.mine .profile .xsession-errors'
2733
# By default, this script will display directories separately, before files.
28-
# To change this behaviour, see lines 85-87, 100-102 and 106-108.
34+
# To change this behaviour, see NOTE1, NOTE2 and NOTE3 below.
3036
#######################################################################
32-
# if "--open" argument is sent as $1, open file ($2) instead of generating menu
38+
# if "--open" option is sent as $1, open file ($2) instead of generating menu
3339
[ "$1" = '--open' ] && {
3440
open_file "$2"
41+
echo "$0 : failed to open $2" >&2
3542
exit    # in case exec command fails
3643
}
38-
path="${1:-$HOME}"  # default starting place is ~, otherwise $1
45+
output='<openbox_pipe_menu>
39-
path="$( echo "${path}"/ | tr -s '/' )"    # ensure one final slash
46+
'
40-
[ -d "$path" ] || { echo "$path is not a directory" >&2; exit 1; }
47+
# if "--recent" option is sent, incorporate "recent files" menu
48+
[ "$1" = '--recent' ] && {
42-
# escape xml special characters
49+
shift
43-
escape() {
50+
if [ -x "$recent_script" ]
44-
case "$1" in    # only escape if string needs it
51+
then
45-
*\&*|*\<*|*\>*|*\"*|*\'*) sed "s/\&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g;s/\"/\&quot;/g;s/'/\&apos;/g;" <<XXX
52+
    output="$output"'<separator label="Recent Files" />
46-
$1
53+
<menu execute="'"$recent_script"'" id="recent" label="Recent Files" />
47-
XXX
54+
'
48-
;;
55+
else
49-
*) printf '%s' "$1";;
56+
    echo "$0 : cannot find executable script $recent_script" >&2
50-
esac
57+
fi
5158
}
53-
# escape &apos; (originally ') with surrounding '""' for command line
60+
path="${1:-$HOME}"  # default starting place is ~, otherwise $1
54-
escapos() {
61+
path="$( echo "${path}"/ | tr -s '/' )"    # ensure one final slash
55-
case "$1" in
62+
[ -d "$path" ] || { echo "$0 : $path is not a directory" >&2; exit 1; }
56-
*\&apos\;*) sed 's/\&apos;/\&apos;\&quot;\&apos;\&quot;\&apos;/g;'<<XXX
57-
$1
58-
XXX
59-
;;
60-
*) printf '%s' "$1";;
61-
esac
62-
}
64+
# escape xml special characters
65+
escape() {
66+
case "$1" in    # only escape if string needs it
67+
*\&*|*\<*|*\>*|*\"*|*\'*) sed "s/\&/\&amp;/g;s/</\&lt;/g;s/>/\&gt;/g;s/\"/\&quot;/g;s/'/\&apos;/g;" <<XXX
5768
$1
5869
XXX
5970
;;
6071
*) printf '%s' "$1";;
6172
esac
6273
}
64-
pathe="$( escape "$path" )"
75+
# escape &apos; (originally ') with surrounding '""' for command line
65-
output='<openbox_pipe_menu>
76+
escapos() {
66-
<separator label="'$pathe'" />
77+
case "$1" in
67-
<item label="Browse here...">
78+
*\&apos\;*) sed 's/\&apos;/\&apos;\&quot;\&apos;\&quot;\&apos;/g;'<<XXX
68-
	<action name="Execute">
79+
$1
69-
		<execute>
80+
XXX
70-
		 '$open_folder_cmd' "'$(escapos "$pathe" )'"
81+
;;
71-
		</execute>
82+
*) printf '%s' "$1";;
72-
	</action>
83+
esac
73-
</item>
84+
}
74-
<separator />
75-
'
77-
unset extra_entries directories_menu files_menu
86+
pathe="$( escape "$path" )"
78-
[ "$path" = "$HOME"/ ] && extra_entries="$shown_dotfiles"
79-
for i in "$path"* $extra_entries
88+
output="$output"'<separator label="'$pathe'" />
80-
do
89+
<item label="Browse here...">
81-
    [ -e "$i" ] || continue    # only output code if file exists
90+
	<action name="Execute">
82-
	shortname="$(escape "${i##*/}")"
91+
		<execute>
83-
	ie="${pathe}${shortname}"
92+
		 '$open_folder_cmd' "'$(escapos "$pathe" )'"
84-
	[ -d "$i" ] && {
93+
		</execute>
85-
# (note the one single quote at the end) If you want directories and files listed together
94+
	</action>
86-
# change next line (directories_menu=$directories_menu') to read:	files_menu=$files_menu'
95+
</item>
87-
	directories_menu="$directories_menu"'
96+
<separator />
88-
<menu id="'"$ie"'" label="'"$shortname"'" execute="&apos;'"$0"'&apos; &apos;'"$(escapos "$ie")"'&apos;" />'; continue; }
97+
'
89-
	files_menu="$files_menu"'
90-
<item label="'"$shortname"'">
91-
    <action name="Execute">
92-
        <execute>
93-
        &apos;'"$0"'&apos; --open &apos;'"$(escapos "$ie")"'&apos;
94-
        </execute>
95-
    </action>
96-
</item>'
97-
done
99-
[ -n "$directories_menu" ] && {
99+
unset extra_entries directories_menu files_menu
100-
# comment out next 2 lines if you don't want "Directories" label
100+
[ "$path" = "$HOME"/ ] && extra_entries="$shown_dotfiles"
101-
output="${output}"'<separator label="Directories" />
101+
for i in "$path"* $extra_entries
102-
'
102+
do
103-
output="${output}${directories_menu}"'
103+
    [ -e "$i" ] || continue    # only output code if file exists
104-
'; }
104+
	shortname="$(escape "${i##*/}")"
105-
[ -n "$files_menu" ] && {
105+
	ie="${pathe}${shortname}"
106-
# comment out next 2 lines if you don't want "Files" label
106+
	[ -d "$i" ] && {
107-
output="${output}"'<separator label="Files" />
107+
# NOTE1 If you want directories and files listed together
108-
'
108+
# change next line (directories_menu=$directories_menu') to read:	files_menu=$files_menu' (note the one single quote at the end)
109-
output="${output}${files_menu}"'
109+
	directories_menu="$directories_menu"'
110-
'; }
110+
<menu id="'"$ie"'" label="'"$shortname"'" execute="&apos;'"$0"'&apos; &apos;'"$(escapos "$ie")"'&apos;" />'; continue; }
111-
output="${output}"'</openbox_pipe_menu>
111+
	files_menu="$files_menu"'
112-
'
112+
<item label="'"$shortname"'">
113-
printf '%s' "$output"
113+
    <action name="Execute">
114-
exit
114+
        <execute>
115+
        &apos;'"$0"'&apos; --open &apos;'"$(escapos "$ie")"'&apos;
116+
        </execute>
117+
    </action>
118+
</item>'
119+
done
121+
[ -n "$directories_menu" ] && {
122+
# NOTE2 comment out next 2 lines if you don't want "Directories" label
123+
output="${output}"'<separator label="Directories" />
124+
'
125+
output="${output}${directories_menu}"'
126+
'; }
127+
[ -n "$files_menu" ] && {
128+
# NOTE3 comment out next 2 lines if you don't want "Files" label
129+
output="${output}"'<separator label="Files" />
130+
'
131+
output="${output}${files_menu}"'
132+
'; }
133+
output="${output}"'</openbox_pipe_menu>
134+
'
135+
printf '%s' "$output"
136+
exit

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me