dots2/.antidote/functions/__antidote_bundle_dir

46 lines
1.6 KiB
Bash

#!/bin/zsh
### Get the name of the bundle dir.
#function __antidote_bundle_dir {
emulate -L zsh; setopt local_options $_adote_funcopts
# If the bundle is a repo/URL, then by default we use the legacy antibody format:
# `$ANTIDOTE_HOME/https-COLON--SLASH--SLASH-github.com-SLASH-zsh-users-SLASH-zsh-autosuggestions`
# With `zstyle ':antidote:bundle' use-friendly-names on`, we can simplify to
# `$ANTIDOTE_HOME/zsh-users/zsh-autosuggestions`
# If the bundle is a file, use its parent directory.
# Otherwise, just assume the bundle is a directory.
local MATCH MBEGIN MEND; local -a match mbegin mend # appease 'warn_create_global'
local bundle="$1"
local bundle_type="$(__antidote_bundle_type $bundle)"
# handle repo bundle paths
if [[ "$bundle_type" == (repo|url|sshurl) ]] && [[ ! -e "$bundle_path" ]]; then
if zstyle -t ':antidote:bundle' use-friendly-names; then
# user/repo format
# ex: $ANTIDOTE_HOME/zsh-users/zsh-autosuggestions
bundle=${bundle%.git}
bundle=${bundle:gs/\:/\/}
local parts=( ${(ps./.)bundle} )
if [[ $#parts -gt 1 ]]; then
print $(antidote-home)/${parts[-2]}/${parts[-1]}
else
print $(antidote-home)/$bundle
fi
else
# sanitize URL for safe use as a dir name
# ex: $ANTIDOTE_HOME/https-COLON--SLASH--SLASH-github.com-SLASH-zsh-users-SLASH-zsh-autosuggestions
local url=$(__antidote_tourl $bundle)
url=${url%.git}
url=${url:gs/\@/-AT-}
url=${url:gs/\:/-COLON-}
url=${url:gs/\//-SLASH-}
print $(antidote-home)/$url
fi
elif [[ -f "$bundle" ]]; then
print ${bundle:A:h}
else
print ${bundle}
fi
#}