Last active
November 5, 2023 19:54
-
-
Save DylanLukes/bab760b8855a0aef258ecfee84e05c63 to your computer and use it in GitHub Desktop.
Cosmo ZSH Plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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