2018-01-20 20:20:25 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2018-09-25 02:38:30 +00:00
|
|
|
_burrow() {
|
2018-01-20 20:20:25 +00:00
|
|
|
local cur
|
|
|
|
cur=${COMP_WORDS[COMP_CWORD]}
|
2018-09-25 01:35:36 +00:00
|
|
|
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
|
2018-09-25 01:53:15 +00:00
|
|
|
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
|
2018-09-25 01:35:36 +00:00
|
|
|
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||" )
|
2018-09-25 01:53:15 +00:00
|
|
|
local suggestions=( $( compgen -W "$gophermaps $directories" -- "$cur" ) )
|
|
|
|
if [ "${#suggestions[@]}" == "1" ]; then
|
|
|
|
local resp=$(echo ${suggestions[0]/%\ */})
|
|
|
|
COMPREPLY=("$resp")
|
|
|
|
else
|
|
|
|
COMPREPLY=("${suggestions[@]}")
|
|
|
|
fi
|
2018-09-25 01:35:36 +00:00
|
|
|
else
|
|
|
|
local helplist
|
|
|
|
helplist=$(burrow shortlist)
|
|
|
|
COMPREPLY=( $( compgen -W "$helplist" -- "$cur" ) )
|
|
|
|
fi
|
2018-01-20 20:02:34 +00:00
|
|
|
}
|
2018-03-03 23:24:05 +00:00
|
|
|
|
|
|
|
# Detect if current shell is ZSH, and if so, load this file in bash
|
|
|
|
# compatibility mode.
|
|
|
|
if [ -n "$ZSH_VERSION" ]; then
|
2018-09-25 01:35:36 +00:00
|
|
|
autoload bashcompinit
|
|
|
|
bashcompinit
|
2018-03-03 23:24:05 +00:00
|
|
|
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
|
2018-09-25 01:35:36 +00:00
|
|
|
complete -o default -o nospace -F _burrow burrow.exe
|
2018-03-03 23:24:05 +00:00
|
|
|
fi
|