potiuk commented on a change in pull request #9685:
URL: https://github.com/apache/airflow/pull/9685#discussion_r450098358



##########
File path: breeze
##########
@@ -228,62 +228,80 @@ function initialize_virtualenv() {
 # Sets up autocomplete for Breeze for both - bash and zsh
 function setup_autocomplete() {
     echo "Installing bash/zsh completion for local user"
-    echo "Note that completion for zsh is just limited to flags - without 
their values"
     echo
-    echo
-    set +e
-    grep ".bash_completion.d" "${HOME}/.bashrc" >/dev/null 2>&1
-    RES=$?
-    set -e
-    if [[ "${RES}" == "0" ]]; then
-        echo >&2
-        echo >&2 "ERROR:  Bash completion already setup before."
-        echo >&2
-        exit 1
-    fi
     "${AIRFLOW_SOURCES}/confirm" "This will create ~/.bash_completion.d/ 
directory and modify ~/.*rc files"
     echo
     echo
     mkdir -pv ~/.bash_completion.d
     ln -sf "${AIRFLOW_SOURCES}/breeze-complete" "${HOME}/.bash_completion.d/"
-    touch ~/.bashrc
-    cat >>~/.bashrc <<"EOF"
+    echo
+    echo "Breeze Bash completion is linked to: 
${AIRFLOW_SOURCES}/breeze-complete now."
+    echo
+    local BREEZE_COMMENT="Added by Airflow Breeze autocomplete setup"
+    if ! grep "${BREEZE_COMMENT}" "${HOME}/.bashrc" >/dev/null 2>&1; then
+        touch ~/.bashrc
+        # shellcheck disable=SC2129
+        echo "# START: ${BREEZE_COMMENT}" >>~/.bashrc
+        cat <<"EOF" >>~/.bashrc
 for BCFILE in ~/.bash_completion.d/* ; do
     . ${BCFILE}
 done
 EOF
-    cat >>~/.zshrc <<"EOF"
+        echo "# END: ${BREEZE_COMMENT}" >>~/.bashrc
+        echo
+        echo "The ${HOME}/.bashrc has been modified"
+        echo
+    else
+        echo
+        echo "The ${HOME}/.bashrc was already modified before. Not changing 
it."
+        echo
+    fi
+    if ! grep "${BREEZE_COMMENT}" "${HOME}/.zshrc" >/dev/null 2>&1; then
+        # shellcheck disable=SC2129
+        echo "# START: ${BREEZE_COMMENT}" >>~/.zshrc
+        cat <<"EOF" >>~/.zshrc
 autoload compinit && compinit
 autoload bashcompinit && bashcompinit
 source ~/.bash_completion.d/breeze-complete
 EOF
+        echo "# END: ${BREEZE_COMMENT}" >>~/.zshrc
+        echo
+        echo "The ${HOME}/.zshrc has been modified"
+        echo

Review comment:
       I am using bash completion script to keep both bash and zsh. 
Unfortunately it's a little bit involved to have bash completion scripts to 
work for zsh. It's also a little bit different than when installing a binary 
for a tool as we are using dynamically changing sources and dynamically 
changing completions. 
   
   In our case the "breeze-complete" evolves continuously and new options are 
being added in the sources. That's why I created  .bash_completion.d and have 
symbolic link to the breeze-complete so that you do not have to reinstall it 
every time new options are added. 
   
   That's why rather than `echo "source <(xyz completion zsh)" >> ~/.zshrc` I 
do "./breeze setup-autocomplete' which does all of that (it's more than just 
appending entries to .zshrc). Also I actually display warning and ask for 
confirmation before it happens:
   
   "${AIRFLOW_SOURCES}/confirm" "This will create ~/.bash_completion.d/ 
directory and modify ~/.*rc files"
   
   
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to