|
root / base / hammerhead-desktop / hh-places-pipemenu
hh-places-pipemenu Plain Text 59 lines 1.9 KB
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/sh
# hh-places-pipemenu - Openbox "Places" pipe menu (GTK-free)
#
# Pattern adapted from CrunchBang++'s cbpp-places-pipemenu
# (github.com/CBPP/cbpp-pipemenus, Copyright (C) 2010 John Crawley,
# ported to #!++ by Ben Young) - same idea (walk a directory, XML-escape
# names, emit an <openbox_pipe_menu>) but rewritten small/flat for our
# stack: no thunar/exo-open/geany, no recursive submenus. Every entry
# opens in xfe; a matching terminal entry opens st in that directory.
#
# Usage: <menu id="places-menu" label="Places" execute="hh-places-pipemenu"/>
# in menu.xml. Invoked with no arguments; always lists $HOME's immediate
# subdirectories (dotdirs skipped).
#
# NB: the shell, not bash - keep this POSIX sh / dash-fast per upstream.

files="xfe"

xml_escape() {
    # $1 -> escaped on stdout
    printf '%s' "$1" | sed \
        -e 's/&/\&amp;/g' \
        -e 's/</\&lt;/g' \
        -e 's/>/\&gt;/g' \
        -e 's/"/\&quot;/g'
}

home="${HOME:-/root}"

printf '<openbox_pipe_menu>\n'

printf '  <item label="~ Home">\n'
printf '    <action name="Execute"><command>%s %s</command></action>\n' "$files" "$(xml_escape "$home")"
printf '  </item>\n'
printf '  <item label="Terminal Here">\n'
printf '    <action name="Execute"><command>st -d %s</command></action>\n' "$(xml_escape "$home")"
printf '  </item>\n'
printf '  <separator/>\n'

# Immediate subdirectories of $HOME, skipping dotdirs, alphabetical.
for d in "$home"/*/; do
    [ -d "$d" ] || continue
    d="${d%/}"
    base="${d##*/}"
    case "$base" in
        .*) continue ;;
    esac
    label="$(xml_escape "$base")"
    path="$(xml_escape "$d")"
    printf '  <item label="%s">\n' "$label"
    printf '    <action name="Execute"><command>%s %s</command></action>\n' "$files" "$path"
    printf '  </item>\n'
    printf '  <item label="Terminal: %s">\n' "$label"
    printf '    <action name="Execute"><command>st -d %s</command></action>\n' "$path"
    printf '  </item>\n'
done

printf '</openbox_pipe_menu>\n'