burrow/burrow.d

54 lines
1.7 KiB
D
Raw Normal View History

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]}
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
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
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
complete -o default -o nospace -F _burrow burrow.exe
2018-03-03 23:24:05 +00:00
fi