From c6d681767298dc445753661e7af79ddbb9b2381a Mon Sep 17 00:00:00 2001 From: "Oliver G. Mueller" Date: Sun, 19 Apr 2020 22:16:20 +0200 Subject: [PATCH] resolved #51 Adding auto-completion to ineo - added bash autocompletion support for linux and mac, if completion folder are found -- on macos auto completion is expected to use /usr/local/etc/bash_completion.d -- on linux auto completion is expected to use /etc/bash_completion.d/ --- ineo | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 85 insertions(+), 6 deletions(-) diff --git a/ineo b/ineo index 4eb0ca0..3312a27 100755 --- a/ineo +++ b/ineo @@ -85,13 +85,19 @@ else readonly NF="" # No Format fi -# Underline -UNDERLINE='\033[4m' -ITALIC='\033[3m' -BOLD='\033[1m' +# ============================================================================== +# BASH AUTO COMPLETION +# ============================================================================== -# No Format -NF='\033[0m' +function ineo_autocompletion { + if [ "${#COMP_WORDS[@]}" -eq "2" ]; then + COMPREPLY=($(compgen -W "create set-port versions instances start stop restart status shell console delete-db + destroy install update uninstall help" "${COMP_WORDS[1]}")) + else + COMPREPLY=$(compgen -W "$(ineo instances|egrep '> instance'|sed "s/> instance '\(.*\)'/ \1/g"|sed "s/\s*//g")" + "${COMP_WORDS[-1]}") + fi +} # ============================================================================== # SET INSTANCES FUNCTION @@ -402,6 +408,71 @@ EOF systemctl enable ineo fi + # Check if ineo bash autocomplete can be installed + local completion + if [[ -d "/etc/bash_completion.d/" ]]; then + completion="/etc/bash_completion.d/" + elif [[ -d "/usr/local/etc/bash_completion.d" ]]; then + completion="/usr/local/etc/bash_completion.d" + fi + + if [[ -n "${completion}" && -w "${completion}" ]]; then + cat >"${completion}/ineo" <