Skip to content

Instantly share code, notes, and snippets.

@masutaka
Created October 28, 2018 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masutaka/1f17b9895f1c4e358b56e609a95dd74e to your computer and use it in GitHub Desktop.
Save masutaka/1f17b9895f1c4e358b56e609a95dd74e to your computer and use it in GitHub Desktop.
Heroku CLI autocomplete research
# /Users/masutaka/Library/Caches/heroku/autocomplete/zsh_setup
expand-or-complete-with-dots() {
echo -n "..."
zle expand-or-complete
zle redisplay
}
zle -N expand-or-complete-with-dots
bindkey "^I" expand-or-complete-with-dots
HEROKU_AC_ANALYTICS_DIR=/Users/masutaka/Library/Caches/heroku/autocomplete/completion_analytics;
HEROKU_AC_COMMANDS_PATH=/Users/masutaka/Library/Caches/heroku/autocomplete/commands;
HEROKU_AC_ZSH_SETTERS_PATH=${HEROKU_AC_COMMANDS_PATH}_setters && test -f $HEROKU_AC_ZSH_SETTERS_PATH && source $HEROKU_AC_ZSH_SETTERS_PATH;
fpath=(
/usr/local/Cellar/heroku/7.18.3/libexec/node_modules/@heroku-cli/plugin-autocomplete/autocomplete/zsh
$fpath
);
autoload -Uz compinit;
compinit;
# /usr/local/Cellar/heroku/7.18.3/libexec/node_modules/@heroku-cli/plugin-autocomplete/autocomplete/zsh/_heroku
#compdef heroku
_heroku () {
# exit if vars are not set
: "${HEROKU_AC_ANALYTICS_DIR?}"
: "${HEROKU_AC_COMMANDS_PATH?}"
local -a _flags=()
local _command_id=${words[2]}
local _cur=${words[CURRENT]}
mkdir -p "$HEROKU_AC_ANALYTICS_DIR"
## all commands
_complete_commands () {
touch "$HEROKU_AC_ANALYTICS_DIR"/command
local -a _all_commands_list
if type _set_all_commands_list >/dev/null 2>&1; then
_set_all_commands_list
_describe -t all-commands "all commands" _all_commands_list
return
fi
# fallback to grep'ing cmds from cache
compadd $(grep -oe '^[a-zA-Z0-9:_-]\+' $HEROKU_AC_COMMANDS_PATH)
}
## end all commands
_compadd_args () {
compadd $(echo $([[ -n $REPORTTIME ]] && REPORTTIME=100; heroku autocomplete:options "${words}"))
}
_compadd_flag_options () {
touch "$HEROKU_AC_ANALYTICS_DIR"/value
_compadd_args
}
if [ $CURRENT -gt 2 ]; then
if [[ "$_cur" == -* ]]; then
touch "$HEROKU_AC_ANALYTICS_DIR"/flag
local _flag_completion_func="_set_${_command_id//:/_}_flags"
declare -f $_flag_completion_func >/dev/null && $_flag_completion_func
else
if type _compadd_args >/dev/null 2>&1; then
_compadd_args
fi
fi
fi
_arguments '1: :_complete_commands' \
$_flags
}
_heroku
# /usr/local/share/zsh/site-functions/_heroku
#compdef heroku
### Keep in sync with zsh shim
HEROKU_AC_ANALYTICS_DIR=$HOME/Library/Caches/heroku/autocomplete/completion_analytics;
HEROKU_AC_COMMANDS_PATH=$HOME/Library/Caches/heroku/autocomplete/commands;
HEROKU_AC_ZSH_SETTERS_PATH=${HEROKU_AC_COMMANDS_PATH}_setters && test -f $HEROKU_AC_ZSH_SETTERS_PATH && source $HEROKU_AC_ZSH_SETTERS_PATH;
### Keep in sync with autocomplete/zsh/_heroku
_heroku () {
# exit if vars are not set
: "${HEROKU_AC_ANALYTICS_DIR?}"
: "${HEROKU_AC_COMMANDS_PATH?}"
local -a _flags=()
local _command_id=${words[2]}
local _cur=${words[CURRENT]}
mkdir -p "$HEROKU_AC_ANALYTICS_DIR"
## all commands
_complete_commands () {
touch "$HEROKU_AC_ANALYTICS_DIR"/command
local -a _all_commands_list
if type _set_all_commands_list >/dev/null 2>&1; then
_set_all_commands_list
_describe -t all-commands "all commands" _all_commands_list
return
fi
# fallback to grep'ing cmds from cache
compadd $(grep -oe '^[a-zA-Z0-9:_-]\+' $HEROKU_AC_COMMANDS_PATH)
}
## end all commands
_compadd_args () {
compadd $(echo $([[ -n $REPORTTIME ]] && REPORTTIME=100; heroku autocomplete:options "${words}"))
}
_compadd_flag_options () {
touch "$HEROKU_AC_ANALYTICS_DIR"/value
_compadd_args
}
if [ $CURRENT -gt 2 ]; then
if [[ "$_cur" == -* ]]; then
touch "$HEROKU_AC_ANALYTICS_DIR"/flag
local _flag_completion_func="_set_${_command_id//:/_}_flags"
declare -f $_flag_completion_func >/dev/null && $_flag_completion_func
else
if type _compadd_args >/dev/null 2>&1; then
_compadd_args
fi
fi
fi
_arguments '1: :_complete_commands' \
$_flags
}
_heroku
@masutaka
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment