Merge pull request #3175 from dokku/2095-bash-completion
Implement bash-completion for commands
This commit is contained in:
11 files changed
+80
-12
No files matched your search
@@ -0,0 +1,39 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
_dokku_complete_goals_fetch() {
|
||||||
|
dokku --quiet help --all | awk '/^ /{ print $1 }' | sort > "/var/cache/dokku-completion"
|
||||||
|
}
|
||||||
|
|
||||||
|
_dokku_complete_verify() {
|
||||||
|
declare desc="shows bash completion"
|
||||||
|
declare COMMAND="$1"
|
||||||
|
local COMMANDS=""
|
||||||
|
|
||||||
|
if [[ ! -f "/var/cache/dokku-completion" ]] || [[ -s "/var/cache/dokku-completion" ]]; then
|
||||||
|
_dokku_complete_goals_fetch
|
||||||
|
fi
|
||||||
|
|
||||||
|
_dokku_complete_goals=$(cat "/var/cache/dokku-completion")
|
||||||
|
|
||||||
|
while read -r fn; do
|
||||||
|
if [[ -z "$COMMAND" ]] || [[ "$fn" == $COMMAND* ]]; then
|
||||||
|
COMMANDS="${COMMANDS};${fn}"
|
||||||
|
fi
|
||||||
|
done <<< "$_dokku_complete_goals"
|
||||||
|
|
||||||
|
echo "${COMMANDS#";"}"
|
||||||
|
}
|
||||||
|
|
||||||
|
have dokku &&
|
||||||
|
_dokku_complete() {
|
||||||
|
local cur prev
|
||||||
|
_get_comp_words_by_ref -n : cur
|
||||||
|
opts=$(_dokku_complete_verify "${cur}")
|
||||||
|
COMPREPLY=($(IFS=";" compgen -W "$opts" -- "$cur"))
|
||||||
|
__ltrim_colon_completions "$cur"
|
||||||
|
} &&
|
||||||
|
complete -F _dokku_complete dokku
|
||||||
|
|
||||||
|
if [[ ! -f "/var/cache/dokku-completion" ]] || [[ -s "/var/cache/dokku-completion" ]]; then
|
||||||
|
have dokku && export -f _dokku_complete_goals_fetch && nohup bash -c _dokku_complete_goals_fetch >/dev/null 2>&1 &
|
||||||
|
fi
|
||||||
@@ -117,6 +117,7 @@ deb-dokku:
|
|||||||
mkdir -p /tmp/tmp /tmp/build
|
mkdir -p /tmp/tmp /tmp/build
|
||||||
|
|
||||||
cp -r debian /tmp/build/DEBIAN
|
cp -r debian /tmp/build/DEBIAN
|
||||||
|
mkdir -p /tmp/build/etc/bash_completion.d
|
||||||
mkdir -p /tmp/build/usr/bin
|
mkdir -p /tmp/build/usr/bin
|
||||||
mkdir -p /tmp/build/usr/share/doc/dokku
|
mkdir -p /tmp/build/usr/share/doc/dokku
|
||||||
mkdir -p /tmp/build/usr/share/dokku/contrib
|
mkdir -p /tmp/build/usr/share/dokku/contrib
|
||||||
@@ -126,6 +127,7 @@ deb-dokku:
|
|||||||
|
|
||||||
cp dokku /tmp/build/usr/bin
|
cp dokku /tmp/build/usr/bin
|
||||||
cp LICENSE /tmp/build/usr/share/doc/dokku/copyright
|
cp LICENSE /tmp/build/usr/share/doc/dokku/copyright
|
||||||
|
cp contrib/bash-completion /tmp/build/etc/bash_completion.d/dokku
|
||||||
find . -name ".DS_Store" -depth -exec rm {} \;
|
find . -name ".DS_Store" -depth -exec rm {} \;
|
||||||
$(MAKE) go-build
|
$(MAKE) go-build
|
||||||
cp common.mk /tmp/build/var/lib/dokku/core-plugins/common.mk
|
cp common.mk /tmp/build/var/lib/dokku/core-plugins/common.mk
|
||||||
|
|||||||
@@ -191,20 +191,20 @@ case "$1" in
|
|||||||
done
|
done
|
||||||
|
|
||||||
# New lines are blank echos for readability
|
# New lines are blank echos for readability
|
||||||
echo "Usage: dokku [--quiet|--trace|--rm-container|--rm|--force] COMMAND <app> [command-specific-options]"
|
dokku_log_quiet "Usage: dokku [--quiet|--trace|--rm-container|--rm|--force] COMMAND <app> [command-specific-options]"
|
||||||
echo ""
|
dokku_log_quiet ""
|
||||||
echo "Primary help options, type \"dokku COMMAND:help\" for more details, or dokku help --all to see all commands."
|
dokku_log_quiet "Primary help options, type \"dokku COMMAND:help\" for more details, or dokku help --all to see all commands."
|
||||||
echo ""
|
dokku_log_quiet ""
|
||||||
echo "Commands:"
|
dokku_log_quiet "Commands:"
|
||||||
echo ""
|
dokku_log_quiet ""
|
||||||
|
|
||||||
if [[ "$2" == "--all" ]] ; then
|
if [[ "$2" == "--all" ]] ; then
|
||||||
for core_plugin_command in $CORE_PLUGIN_COMMANDS; do
|
for core_plugin_command in $CORE_PLUGIN_COMMANDS; do
|
||||||
$core_plugin_command help
|
$core_plugin_command help
|
||||||
done | sort | column -c2 -t -s,
|
done | sort | column -c2 -t -s,
|
||||||
echo ""
|
dokku_log_quiet ""
|
||||||
echo "Community plugin commands:"
|
dokku_log_quiet "Community plugin commands:"
|
||||||
echo ""
|
dokku_log_quiet ""
|
||||||
for community_plugin_command in $COMMUNITY_PLUGIN_COMMANDS; do
|
for community_plugin_command in $COMMUNITY_PLUGIN_COMMANDS; do
|
||||||
$community_plugin_command help
|
$community_plugin_command help
|
||||||
done | sort | column -c2 -t -s,
|
done | sort | column -c2 -t -s,
|
||||||
@@ -214,9 +214,9 @@ case "$1" in
|
|||||||
# When done, sort, sed cuts arugments out of strings and colum make it pretty
|
# When done, sort, sed cuts arugments out of strings and colum make it pretty
|
||||||
done | sort | sed -e '/^.*:/d' -e 's/\s[\[\<\-\(].*,/,/' | column -c2 -t -s,
|
done | sort | sed -e '/^.*:/d' -e 's/\s[\[\<\-\(].*,/,/' | column -c2 -t -s,
|
||||||
if [[ -n "$COMMUNITY_PLUGIN_COMMANDS" ]]; then
|
if [[ -n "$COMMUNITY_PLUGIN_COMMANDS" ]]; then
|
||||||
echo ""
|
dokku_log_quiet ""
|
||||||
echo "Community plugin commands:"
|
dokku_log_quiet "Community plugin commands:"
|
||||||
echo ""
|
dokku_log_quiet ""
|
||||||
for community_plugin_command in $COMMUNITY_PLUGIN_COMMANDS; do
|
for community_plugin_command in $COMMUNITY_PLUGIN_COMMANDS; do
|
||||||
$community_plugin_command help
|
$community_plugin_command help
|
||||||
done | sort | column -c2 -t -s,
|
done | sort | column -c2 -t -s,
|
||||||
|
|||||||
@@ -16,6 +16,13 @@ dokku_apps() {
|
|||||||
[[ $INSTALLED_APPS ]] && echo "$INSTALLED_APPS"
|
[[ $INSTALLED_APPS ]] && echo "$INSTALLED_APPS"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dokku_log_quiet() {
|
||||||
|
declare desc="log quiet formatter"
|
||||||
|
if [[ -z "$DOKKU_QUIET_OUTPUT" ]]; then
|
||||||
|
echo "$*"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
dokku_log_info1() {
|
dokku_log_info1() {
|
||||||
declare desc="log info1 formatter"
|
declare desc="log info1 formatter"
|
||||||
echo "-----> $*"
|
echo "-----> $*"
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||||
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||||
|
|
||||||
plugin_list_cmd() {
|
plugin_list_cmd() {
|
||||||
declare desc="lists all plugins"
|
declare desc="lists all plugins"
|
||||||
@@ -8,3 +9,10 @@ plugin_list_cmd() {
|
|||||||
plugn version
|
plugn version
|
||||||
plugn list
|
plugn list
|
||||||
}
|
}
|
||||||
|
|
||||||
|
plugin_prime_bash_completion() {
|
||||||
|
declare desc="primes the bash-completion cache"
|
||||||
|
|
||||||
|
dokku_log_info1_quiet "Priming bash-completion cache"
|
||||||
|
dokku --quiet help --all | awk '/^ /{ print $1 }' | sort > "/var/cache/dokku-completion"
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||||
source "$PLUGIN_AVAILABLE_PATH/plugin/functions"
|
source "$PLUGIN_AVAILABLE_PATH/plugin/functions"
|
||||||
|
source "$PLUGIN_AVAILABLE_PATH/plugin/internal-functions"
|
||||||
|
|
||||||
plugin_disable_cmd() {
|
plugin_disable_cmd() {
|
||||||
declare desc="disables plugin via command line"
|
declare desc="disables plugin via command line"
|
||||||
@@ -9,6 +10,7 @@ plugin_disable_cmd() {
|
|||||||
[[ -z $2 ]] && dokku_log_fail "Please specify a plugin to disable"
|
[[ -z $2 ]] && dokku_log_fail "Please specify a plugin to disable"
|
||||||
local PLUGIN="$2"
|
local PLUGIN="$2"
|
||||||
disable_plugin "$PLUGIN"
|
disable_plugin "$PLUGIN"
|
||||||
|
plugin_prime_bash_completion
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin_disable_cmd "$@"
|
plugin_disable_cmd "$@"
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||||
source "$PLUGIN_AVAILABLE_PATH/plugin/functions"
|
source "$PLUGIN_AVAILABLE_PATH/plugin/functions"
|
||||||
|
source "$PLUGIN_AVAILABLE_PATH/plugin/internal-functions"
|
||||||
|
|
||||||
plugin_enable_cmd() {
|
plugin_enable_cmd() {
|
||||||
declare desc="enables plugin via command line"
|
declare desc="enables plugin via command line"
|
||||||
@@ -9,6 +10,7 @@ plugin_enable_cmd() {
|
|||||||
[[ -z $2 ]] && dokku_log_fail "Please specify a plugin to enable"
|
[[ -z $2 ]] && dokku_log_fail "Please specify a plugin to enable"
|
||||||
local PLUGIN="$2"
|
local PLUGIN="$2"
|
||||||
enable_plugin "$PLUGIN"
|
enable_plugin "$PLUGIN"
|
||||||
|
plugin_prime_bash_completion
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin_enable_cmd "$@"
|
plugin_enable_cmd "$@"
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||||
source "$PLUGIN_AVAILABLE_PATH/plugin/functions"
|
source "$PLUGIN_AVAILABLE_PATH/plugin/functions"
|
||||||
|
source "$PLUGIN_AVAILABLE_PATH/plugin/internal-functions"
|
||||||
|
|
||||||
plugin_install_cmd() {
|
plugin_install_cmd() {
|
||||||
declare desc="installs a plugin from URL and calls install plugin trigger via command line"
|
declare desc="installs a plugin from URL and calls install plugin trigger via command line"
|
||||||
@@ -20,6 +21,7 @@ plugin_install_cmd() {
|
|||||||
plugn trigger install
|
plugn trigger install
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
plugin_prime_bash_completion
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin_install_cmd "$@"
|
plugin_install_cmd "$@"
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||||
source "$PLUGIN_AVAILABLE_PATH/plugin/functions"
|
source "$PLUGIN_AVAILABLE_PATH/plugin/functions"
|
||||||
|
source "$PLUGIN_AVAILABLE_PATH/plugin/internal-functions"
|
||||||
|
|
||||||
plugin_uninstall_cmd() {
|
plugin_uninstall_cmd() {
|
||||||
declare desc="uninstalls plugin via command line"
|
declare desc="uninstalls plugin via command line"
|
||||||
@@ -9,6 +10,7 @@ plugin_uninstall_cmd() {
|
|||||||
[[ -z $2 ]] && dokku_log_fail "Please specify a plugin to enable"
|
[[ -z $2 ]] && dokku_log_fail "Please specify a plugin to enable"
|
||||||
local PLUGIN="$2"
|
local PLUGIN="$2"
|
||||||
uninstall_plugin "$PLUGIN"
|
uninstall_plugin "$PLUGIN"
|
||||||
|
plugin_prime_bash_completion
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin_uninstall_cmd "$@"
|
plugin_uninstall_cmd "$@"
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
|
||||||
|
source "$PLUGIN_AVAILABLE_PATH/plugin/internal-functions"
|
||||||
|
|
||||||
plugin_update_cmd() {
|
plugin_update_cmd() {
|
||||||
declare desc="updates plugin to optional committish and calls update plugin trigger via command line"
|
declare desc="updates plugin to optional committish and calls update plugin trigger via command line"
|
||||||
@@ -10,6 +11,7 @@ plugin_update_cmd() {
|
|||||||
plugn update "$PLUGIN" "$PLUGIN_COMMITTISH"
|
plugn update "$PLUGIN" "$PLUGIN_COMMITTISH"
|
||||||
fi
|
fi
|
||||||
plugn trigger update
|
plugn trigger update
|
||||||
|
plugin_prime_bash_completion
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin_update_cmd "$@"
|
plugin_update_cmd "$@"
|
||||||
@@ -51,6 +51,7 @@ rpm-dokku:
|
|||||||
rm -rf /tmp/tmp /tmp/build dokku_*_$(RPM_ARCHITECTURE).rpm
|
rm -rf /tmp/tmp /tmp/build dokku_*_$(RPM_ARCHITECTURE).rpm
|
||||||
mkdir -p /tmp/tmp /tmp/build
|
mkdir -p /tmp/tmp /tmp/build
|
||||||
|
|
||||||
|
mkdir -p /tmp/build/etc/bash_completion.d
|
||||||
mkdir -p /tmp/build/usr/bin
|
mkdir -p /tmp/build/usr/bin
|
||||||
mkdir -p /tmp/build/usr/share/doc/dokku
|
mkdir -p /tmp/build/usr/share/doc/dokku
|
||||||
mkdir -p /tmp/build/usr/share/dokku/contrib
|
mkdir -p /tmp/build/usr/share/dokku/contrib
|
||||||
@@ -60,6 +61,7 @@ rpm-dokku:
|
|||||||
|
|
||||||
cp dokku /tmp/build/usr/bin
|
cp dokku /tmp/build/usr/bin
|
||||||
cp LICENSE /tmp/build/usr/share/doc/dokku/copyright
|
cp LICENSE /tmp/build/usr/share/doc/dokku/copyright
|
||||||
|
cp contrib/bash-completion /tmp/build/etc/bash_completion.d/dokku
|
||||||
find . -name ".DS_Store" -depth -exec rm {} \;
|
find . -name ".DS_Store" -depth -exec rm {} \;
|
||||||
$(MAKE) go-build
|
$(MAKE) go-build
|
||||||
cp common.mk /tmp/build/var/lib/dokku/core-plugins/common.mk
|
cp common.mk /tmp/build/var/lib/dokku/core-plugins/common.mk
|
||||||
|
|||||||
Reference in new issue
Block a user