From a9baa1f4688aad95b4b8eeea9f2e9ef51326df4e Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Tue, 2 Jan 2024 05:38:00 +0300 Subject: [PATCH] Add shell completion support for jf CLI --- jfrog-oauth/run.sh | 16 +++++++++++++--- jfrog-token/run.sh | 16 +++++++++++++--- 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index 85e8f61..e18b303 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -108,8 +108,18 @@ SHELLNAME=$(grep "^$USER" /etc/passwd | awk -F':' '{print $7}' | awk -F'/' '{pri ## Generate the completion script jf completion $SHELLNAME --install ## Add the completion script to the user's shell profile -if [ "$SHELLNAME" == "bash" ] || [ "$SHELLNAME" == "zsh" ]; then - if ! grep -q "source $HOME/.jfrog/jfrog_$${SHELLNAME}_completion" ~/.$${SHELLNAME}rc; then - echo "source $HOME/.jfrog/jfrog_$${SHELLNAME}_completion" >> ~/.$${SHELLNAME}rc +if [ "$SHELLNAME" == "bash" ]; then + if ! grep -q "# jf CLI shell completion" ~/.bashrc; then + echo "# jf CLI shell completion" >> ~/.bashrc + echo "source $HOME/.jfrog/jfrog_bash_completion" >> ~/.bashrc + echo "# end jf CLI shell completion" >> ~/.bashrc + fi +elif [ "$SHELLNAME" == "zsh" ]; then + if ! grep -q "# jf CLI shell completion" ~/.zshrc; then + echo "# jf CLI shell completion" >> ~/.zshrc + echo "autoload -Uz compinit" >> ~/.zshrc + echo "compinit" >> ~/.zshrc + echo "source $HOME/.jfrog/jfrog_zsh_completion" >> ~/.zshrc + echo "# end jf CLI shell completion" >> ~/.zshrc fi fi diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index 9dd71bf..bf9c436 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -108,8 +108,18 @@ SHELLNAME=$(grep "^$USER" /etc/passwd | awk -F':' '{print $7}' | awk -F'/' '{pri ## Generate the completion script jf completion $SHELLNAME --install ## Add the completion script to the user's shell profile -if [ "$SHELLNAME" == "bash" ] || [ "$SHELLNAME" == "zsh" ]; then - if ! grep -q "source $HOME/.jfrog/jfrog_$${SHELLNAME}_completion" ~/.$${SHELLNAME}rc; then - echo "source $HOME/.jfrog/jfrog_$${SHELLNAME}_completion" >> ~/.$${SHELLNAME}rc +if [ "$SHELLNAME" == "bash" ]; then + if ! grep -q "# jf CLI shell completion" ~/.bashrc; then + echo "# jf CLI shell completion" >> ~/.bashrc + echo "source $HOME/.jfrog/jfrog_bash_completion" >> ~/.bashrc + echo "# end jf CLI shell completion" >> ~/.bashrc + fi +elif [ "$SHELLNAME" == "zsh" ]; then + if ! grep -q "# jf CLI shell completion" ~/.zshrc; then + echo "# jf CLI shell completion" >> ~/.zshrc + echo "autoload -Uz compinit" >> ~/.zshrc + echo "compinit" >> ~/.zshrc + echo "source $HOME/.jfrog/jfrog_zsh_completion" >> ~/.zshrc + echo "# end jf CLI shell completion" >> ~/.zshrc fi fi