From 22ecc7903d2982b612a9647723f79d511bf68ab8 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Fri, 5 Jan 2024 17:32:57 +0300 Subject: [PATCH] skip if shellrc files do not exist. --- jfrog-oauth/run.sh | 16 +++++++++++----- jfrog-token/run.sh | 16 +++++++++++----- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/jfrog-oauth/run.sh b/jfrog-oauth/run.sh index 939c86e..c0fa589 100644 --- a/jfrog-oauth/run.sh +++ b/jfrog-oauth/run.sh @@ -92,19 +92,21 @@ fi # Configure the JFrog CLI completion echo "📦 Configuring JFrog CLI completion..." -## Get the user's shell +# Get the user's shell SHELLNAME=$(grep "^$USER" /etc/passwd | awk -F':' '{print $7}' | awk -F'/' '{print $NF}') -## Generate the completion script +# Generate the completion script jf completion $SHELLNAME --install -## Add the completion script to the user's shell profile -if [ "$SHELLNAME" == "bash" ]; then +# Add the completion script to the user's shell profile +if [ "$SHELLNAME" == "bash" ] && [ -f ~/.bashrc ]; then if ! grep -q "# jf CLI shell completion" ~/.bashrc; then echo "" >> ~/.bashrc echo "# BEGIN: jf CLI shell completion (added by coder module jfrog-oauth)" >> ~/.bashrc echo 'source "$HOME/.jfrog/jfrog_bash_completion"' >> ~/.bashrc echo "# END: jf CLI shell completion" >> ~/.bashrc + else + echo "🥳 ~/.bashrc already contains jf CLI shell completion configuration, skipping." fi -elif [ "$SHELLNAME" == "zsh" ]; then +elif [ "$SHELLNAME" == "zsh" ] && [ -f ~/.zshrc ]; then if ! grep -q "# jf CLI shell completion" ~/.zshrc; then echo "" >> ~/.zshrc echo "# BEGIN: jf CLI shell completion (added by coder module jfrog-oauth)" >> ~/.zshrc @@ -112,5 +114,9 @@ elif [ "$SHELLNAME" == "zsh" ]; then echo "compinit" >> ~/.zshrc echo 'source "$HOME/.jfrog/jfrog_zsh_completion"' >> ~/.zshrc echo "# END: jf CLI shell completion" >> ~/.zshrc + else + echo "🥳 ~/.zshrc already contains jf CLI shell completion configuration, skipping." fi +else + echo "🤔 ~/.bashrc or ~/.zshrc does not exist, skipping jf CLI shell completion configuration." fi diff --git a/jfrog-token/run.sh b/jfrog-token/run.sh index 55f4800..629a65d 100644 --- a/jfrog-token/run.sh +++ b/jfrog-token/run.sh @@ -92,19 +92,21 @@ fi # Configure the JFrog CLI completion echo "📦 Configuring JFrog CLI completion..." -## Get the user's shell +# Get the user's shell SHELLNAME=$(grep "^$USER" /etc/passwd | awk -F':' '{print $7}' | awk -F'/' '{print $NF}') -## Generate the completion script +# Generate the completion script jf completion $SHELLNAME --install -## Add the completion script to the user's shell profile -if [ "$SHELLNAME" == "bash" ]; then +# Add the completion script to the user's shell profile +if [ "$SHELLNAME" == "bash" ] && [ -f ~/.bashrc ]; then if ! grep -q "# jf CLI shell completion" ~/.bashrc; then echo "" >> ~/.bashrc echo "# BEGIN: jf CLI shell completion (added by coder module jfrog-token)" >> ~/.bashrc echo 'source "$HOME/.jfrog/jfrog_bash_completion"' >> ~/.bashrc echo "# END: jf CLI shell completion" >> ~/.bashrc + else + echo "🥳 ~/.bashrc already contains jf CLI shell completion configuration, skipping." fi -elif [ "$SHELLNAME" == "zsh" ]; then +elif [ "$SHELLNAME" == "zsh" ] && [ -f ~/.zshrc ]; then if ! grep -q "# jf CLI shell completion" ~/.zshrc; then echo "" >> ~/.zshrc echo "# BEGIN: jf CLI shell completion (added by coder module jfrog-token)" >> ~/.zshrc @@ -112,5 +114,9 @@ elif [ "$SHELLNAME" == "zsh" ]; then echo "compinit" >> ~/.zshrc echo 'source "$HOME/.jfrog/jfrog_zsh_completion"' >> ~/.zshrc echo "# END: jf CLI shell completion" >> ~/.zshrc + else + echo "🥳 ~/.zshrc already contains jf CLI shell completion configuration, skipping." fi +else + echo "🤔 ~/.bashrc or ~/.zshrc does not exist, skipping jf CLI shell completion configuration." fi