Created
October 28, 2018 13:08
-
-
Save masutaka/1f17b9895f1c4e358b56e609a95dd74e to your computer and use it in GitHub Desktop.
Heroku CLI autocomplete research
This file contains hidden or 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
# /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; |
This file contains hidden or 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
# /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 |
This file contains hidden or 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
# /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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Referred by https://masutaka.net/chalow/2018-10-28-1.html