From be2193602a7fcdd15f57c896ace79b61d444e4b0 Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Sun, 10 Jan 2021 19:23:26 +0530 Subject: [PATCH] formatted gem completion --- completion/available/gem.completion.bash | 63 +++++++++++------------- 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/completion/available/gem.completion.bash b/completion/available/gem.completion.bash index 2d098529..321198dc 100644 --- a/completion/available/gem.completion.bash +++ b/completion/available/gem.completion.bash @@ -1,41 +1,34 @@ #!/usr/bin/env bash # Completion for gem -_installcomp() { - if [ -z "$REMOTE_GEMS" ] - then - REMOTE_GEMS=( $(gem list --remote --no-versions | tr '\n' ' ') ) - fi - local cur=${COMP_WORDS[COMP_CWORD]} - COMPREPLY=( $(compgen -W "${REMOTE_GEMS[*]}" -- $cur) ) +__gem_completions() { + local cur=${COMP_WORDS[COMP_CWORD]} + local prev=${COMP_WORDS[COMP_CWORD-1]} + case $prev in + install) + # list the remote gems and add to completion + if [ -z "$REMOTE_GEMS" ] + then + REMOTE_GEMS=( $(gem list --remote --no-versions | sed 's/\*\*\* REMOTE GEMS \*\*\*//' | tr '\n' ' ') ) + fi + + local cur=${COMP_WORDS[COMP_CWORD]} + COMPREPLY=( $(compgen -W "${REMOTE_GEMS[*]}" -- $cur) ) + ;; + uninstall) + # list all local installed gems and add to completion + if [ -z "$LOCAL_GEMS" ] + then + LOCAL_GEMS=( $(gem list --no-versions | sed 's/\*\*\* LOCAL GEMS \*\*\*//' | tr '\n' ' ') ) + fi + + local cur=${COMP_WORDS[COMP_CWORD]} + COMPREPLY=( $(compgen -W "${LOCAL_GEMS[*]}" -- $cur) ) + ;; + esac + local commands=(build cert check cleanup contents dependency environment fetch generate_index help install list lock outdated owner pristine push query rdoc search server sources specification stale uninstall unpack update which) + COMPREPLY=( $(compgen -W "${commands[*]}" -- $cur) ) } -_uninstallcomp() { - if [ -z "$LOCAL_GEMS" ] - then - LOCAL_GEMS=( $(gem list --no-versions | sed 's/\*\*\* LOCAL GEMS \*\*\*//' | tr '\n' ' ') ) - fi - - local cur=${COMP_WORDS[COMP_CWORD]} - COMPREPLY=( $(compgen -W "${LOCAL_GEMS[*]}" -- $cur) ) -} - -_gem() { - local cur=${COMP_WORDS[COMP_CWORD]} - local prev=${COMP_WORDS[COMP_CWORD-1]} - case $prev in - install) - _installcomp - return 0 - ;; - uninstall) - _uninstallcomp - return 0 - ;; - esac - local commands=(build cert check cleanup contents dependency environment fetch generate_index help install list lock outdated owner pristine push query rdoc search server sources specification stale uninstall unpack update which) - COMPREPLY=( $(compgen -W "${commands[*]}" -- $cur) ) -} - -complete -F _gem gem +complete -F __gem_completions gem