-
Notifications
You must be signed in to change notification settings - Fork 10
/
burrow.d
53 lines (49 loc) · 1.69 KB
/
burrow.d
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
#!/usr/bin/env bash
_burrow() {
local cur
cur=${COMP_WORDS[COMP_CWORD]}
if [ "${COMP_WORDS[1]}" == "gophermap" ]; then
local gopher_dir
local gophermaps
local directories
gopher_dir=$(burrow gopherdir)
search_dir=${gopher_dir}
if [ -n "${COMP_WORDS[2]}" ]; then
partial_search_dir="${gopher_dir}${COMP_WORDS[2]}"
if [ -d "$partial_search_dir" ]; then
search_dir="$partial_search_dir"
else
partial_search_dir=$(dirname "$partial_search_dir")
if [ -d "$partial_search_dir" ]; then
search_dir="$partial_search_dir"
fi
fi
fi
gophermaps=$(find "$search_dir" -mindepth 1 -maxdepth 1 -type f -name "gophermap" -print | sed "s|$gopher_dir||" | sed "s|gophermap$||" )
directories=$(find "$search_dir" -mindepth 1 -maxdepth 1 -type d -print | sed "s|$gopher_dir||" )
local suggestions=( $( compgen -W "$gophermaps $directories" -- "$cur" ) )
if [ "${#suggestions[@]}" == "1" ]; then
local resp=$(echo ${suggestions[0]/%\ */})
COMPREPLY=("$resp")
else
COMPREPLY=("${suggestions[@]}")
fi
else
local helplist
helplist=$(burrow shortlist)
COMPREPLY=( $( compgen -W "$helplist" -- "$cur" ) )
fi
}
# Detect if current shell is ZSH, and if so, load this file in bash
# compatibility mode.
if [ -n "$ZSH_VERSION" ]; then
autoload bashcompinit
bashcompinit
fi
complete -o default -o nospace -F _burrow burrow
# The following are necessary only for Cygwin, and only are needed
# when the user has tab-completed the executable name and consequently
# included the '.exe' suffix.
if [ Cygwin = "$(uname -o 2>/dev/null)" ]; then
complete -o default -o nospace -F _burrow burrow.exe
fi