Skip to content

Instantly share code, notes, and snippets.

@DylanLukes
Last active November 5, 2023 19:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DylanLukes/bab760b8855a0aef258ecfee84e05c63 to your computer and use it in GitHub Desktop.
Save DylanLukes/bab760b8855a0aef258ecfee84e05c63 to your computer and use it in GitHub Desktop.
Cosmo ZSH Plugin
cosmo() {
declare cosmo_path=${COSMO_PATH:-/opt/cosmos/bin:/opt/cosmo/bin}
declare ape_bin
# If no arguments were provided, abort.
if [[ $# -eq 0 ]]; then
echo "usage: cosmo <command> [<args>]"
return 1
fi
# Search for the binary in the given paths.
for dir in "${(@s/:/)cosmo_path}"; do
if [[ -x "${dir}/$1" ]]; then
ape_bin="${dir}/$1"
break
fi
done
# If no binary was found, abort.
if [[ -z "${ape_bin}" ]]; then
printf "$1 not found in %s\n" "${cosmo_path}"
return 1
fi
"${ape_bin}" "${@:2}"
}
_cosmo_completion() {
declare cosmo_path=${COSMO_PATH:-/opt/cosmos/bin:/opt/cosmo/bin}
declare word="$1"
declare -a completions=()
# Add all of the available files in each directory,
for dir in "${(@s/:/)cosmo_path}"; do
if [[ -d "${dir}" ]]; then
completions+=("${dir}"/*(:t))
fi
done
compadd -a completions
}
# Register the _cosmo_completion function for the cosmo command
compdef _cosmo_completion cosmo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment