#!/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 ) 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: # 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/&/\&/g' \ -e 's//\>/g' \ -e 's/"/\"/g' } home="${HOME:-/root}" printf '\n' printf ' \n' printf ' %s %s\n' "$files" "$(xml_escape "$home")" printf ' \n' printf ' \n' printf ' st -d %s\n' "$(xml_escape "$home")" printf ' \n' printf ' \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 ' \n' "$label" printf ' %s %s\n' "$files" "$path" printf ' \n' printf ' \n' "$label" printf ' st -d %s\n' "$path" printf ' \n' done printf '\n'