autocomplete is super smart for gophermap

This commit is contained in:
James Tomasino 2018-09-24 21:53:15 -04:00
parent 487574e053
commit 3fed90daef
3 changed files with 17 additions and 5 deletions

2
burrow
View File

@ -1,6 +1,6 @@
#!/bin/sh
version="v1.7.0"
version="v1.7.1"
configfiles="$HOME/.config/burrow/config $HOME/.config/burrow $HOME/.burrow"

View File

@ -1,4 +1,4 @@
.TH BURROW 1 "24 Sep 2018" "version 1.7.0"
.TH BURROW 1 "24 Sep 2018" "version 1.7.1"
.SH NAME
burrow \- a helper for building and managing a gopher hole
.SH SYNOPSIS

View File

@ -12,13 +12,25 @@ _burrow()
gopher_dir=$(burrow gopherdir)
search_dir=${gopher_dir}
if [ -n "${COMP_WORDS[2]}" ]; then
if [ -d "${gopher_dir}${COMP_WORDS[2]}" ]; then
search_dir="${gopher_dir}${COMP_WORDS[2]}"
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||" )
COMPREPLY=( $( compgen -W "$gophermaps $directories" -- "$cur" ) )
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)