From 759cdd5a6dc6a55c1c090135b8090711600600c7 Mon Sep 17 00:00:00 2001 From: Gurkirat Singh Date: Sun, 10 Jan 2021 19:24:05 +0530 Subject: [PATCH 1/3] formatted github-cli completion --- completion/available/github-cli.completion.bash | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/completion/available/github-cli.completion.bash b/completion/available/github-cli.completion.bash index 7b7c9fa0..b392a865 100644 --- a/completion/available/github-cli.completion.bash +++ b/completion/available/github-cli.completion.bash @@ -3,8 +3,6 @@ cite "about-completion" about-completion "GitHub CLI completion" if _binary_exists gh; then - if _command_exists brew; then - _log_warning "You don't need github-cli completion enabled if you have system completion enabled" - fi - eval "$(gh completion --shell=bash)" + complete -p gh &> /dev/null || return + eval "$(gh completion --shell=bash)" fi From 2b66100c47a77a1294a525f5337734ebaf757e46 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Sat, 16 Jan 2021 22:57:04 +0200 Subject: [PATCH 2/3] helpers: Add _completion_exists helper --- lib/helpers.bash | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/helpers.bash b/lib/helpers.bash index 436fc59e..b89bad3d 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -37,6 +37,17 @@ function _binary_exists () type -P "$1" &> /dev/null || (_log_warning "$msg" && return 1) ; } +function _completion_exists () +{ + _about 'checks for existence of a completion' + _param '1: command to check' + _param '2: (optional) log message to include when completion is found' + _example '$ _completion_exists gh && echo exists' + _group 'lib' + local msg="${2:-Completion for '$1' already exists!}" + complete -p "$1" &> /dev/null && _log_warning "$msg" ; +} + function _make_reload_alias() { echo "source \${BASH_IT}/scripts/reloader.bash ${1} ${2}" } From adc77bb622871745536701be208f446af8a2c7cc Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Sat, 16 Jan 2021 22:57:30 +0200 Subject: [PATCH 3/3] completion: Lint github-cli completion and use completion_exists --- clean_files.txt | 1 + completion/available/github-cli.completion.bash | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/clean_files.txt b/clean_files.txt index b49952d1..ddafc469 100644 --- a/clean_files.txt +++ b/clean_files.txt @@ -64,6 +64,7 @@ completion/available/conda.completion.bash completion/available/consul.completion.bash completion/available/docker.completion.bash completion/available/gcloud.completion.bash +completion/available/github-cli.completion.bash completion/available/helm.completion.bash completion/available/knife.completion.bash completion/available/packer.completion.bash diff --git a/completion/available/github-cli.completion.bash b/completion/available/github-cli.completion.bash index b392a865..4a611394 100644 --- a/completion/available/github-cli.completion.bash +++ b/completion/available/github-cli.completion.bash @@ -1,8 +1,9 @@ -#!/usr/bin/env bash +# shellcheck shell=bash cite "about-completion" about-completion "GitHub CLI completion" if _binary_exists gh; then - complete -p gh &> /dev/null || return - eval "$(gh completion --shell=bash)" + # If gh already completed, stop + _completion_exists gh && return + eval "$(gh completion --shell=bash)" fi