Commit eb5eb73f authored by Ingo Meyer's avatar Ingo Meyer

Added an autocomplete function for zsh

parent 94f8123f
PREFIX=/usr/local
default:
@echo "Please run \`make install\` explicitly to install \`config_update.sh\`."
@echo "Please run \`make install\` explicitly to install \`config-update\`."
@echo "You can override \`PREFIX\` to specify an installation prefix:"
@echo
@echo " make PREFIX=/opt/config_update install"
......@@ -9,7 +9,7 @@ default:
@echo "which install to \`/opt/config_update/bin/\`."
install:
cp "config_update.sh" "$(PREFIX)/bin/"
cp "config-update" "$(PREFIX)/bin/"
.PRECIOUS: %.o
.PHONY: default install
#compdef config-update
function _config-update {
local configs_dir configs_location_file optinal arguments location locations config_name config_names local_branch
local local_branches ref
configs_dir="${CONFIG_UPDATE_ROOT_DIR}/configs"
configs_location_file="${configs_dir}/.config_locations"
if (( CURRENT == 2 )); then
if [[ "${words[2]}" =~ ^-.* ]]; then
optional_arguments=(
{-h,--help}'[show help message]'
--version'[print version string]'
)
_arguments $optional_arguments
else
config_names=()
if [[ -f "${configs_location_file}" ]]; then
locations=( "${(f)$(<${configs_location_file})}" )
for location in "${locations[@]}"; do
config_name="$(echo "${location}" | cut -d: -f1)"
config_names+=( "${config_name}" )
done
fi
_arguments '*:config files:($config_names)'
fi
elif (( CURRENT == 3)); then
local_branches=()
if pushd "${configs_dir}" >/dev/null 2>&1; then
for ref in $(git for-each-ref --format='%(refname)' refs/heads/); do
[[ "${ref}" != "refs/heads/HEAD" ]] || continue
local_branch="$(echo "${ref}" | awk -F'/' '{ print $NF }')" && \
local_branches+=( "${local_branch}" )
done
popd >/dev/null 2>&1
fi
_arguments '*:branches:($local_branches)'
fi
return
}
_config-update "@"
# vim: ft=zsh:tw=120
alias config-update="${0:h}/config_update.sh"
export CONFIG_UPDATE_ROOT_DIR="${0:h}"
fpath+="${CONFIG_UPDATE_ROOT_DIR}/completion"
alias config-update="${CONFIG_UPDATE_ROOT_DIR}/config-update"
# vim: ft=zsh:tw=120
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment