goto() {
# don't cd if the arg is actually a subcommand (e.g. `goto list`)
if dirmap commands | grep -qx -- "$1"; then
dirmap "$@"
return
fi
local output
output=$(dirmap "$1")
if [ $? -eq 0 ]; then
cd "$output"
else
echo "$output"
fi
}
_goto() {
local mapkeys=$(dirmap list -k)
_arguments -C "1: :(--help $mapkeys)"
}
compdef _goto goto
_dirmap() {
local mapkeys=$(dirmap list -k)
_arguments -C "1: :(--help $mapkeys)"
}
compdef _dirmap dirmap