skip if shellrc files do not exist.

pull/115/head
Muhammad Atif Ali 2 years ago
parent 1cfefb8d50
commit 22ecc7903d

@ -92,19 +92,21 @@ fi
# Configure the JFrog CLI completion # Configure the JFrog CLI completion
echo "📦 Configuring 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}') 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 jf completion $SHELLNAME --install
## Add the completion script to the user's shell profile # Add the completion script to the user's shell profile
if [ "$SHELLNAME" == "bash" ]; then if [ "$SHELLNAME" == "bash" ] && [ -f ~/.bashrc ]; then
if ! grep -q "# jf CLI shell completion" ~/.bashrc; then if ! grep -q "# jf CLI shell completion" ~/.bashrc; then
echo "" >> ~/.bashrc echo "" >> ~/.bashrc
echo "# BEGIN: jf CLI shell completion (added by coder module jfrog-oauth)" >> ~/.bashrc echo "# BEGIN: jf CLI shell completion (added by coder module jfrog-oauth)" >> ~/.bashrc
echo 'source "$HOME/.jfrog/jfrog_bash_completion"' >> ~/.bashrc echo 'source "$HOME/.jfrog/jfrog_bash_completion"' >> ~/.bashrc
echo "# END: jf CLI shell completion" >> ~/.bashrc echo "# END: jf CLI shell completion" >> ~/.bashrc
else
echo "🥳 ~/.bashrc already contains jf CLI shell completion configuration, skipping."
fi fi
elif [ "$SHELLNAME" == "zsh" ]; then elif [ "$SHELLNAME" == "zsh" ] && [ -f ~/.zshrc ]; then
if ! grep -q "# jf CLI shell completion" ~/.zshrc; then if ! grep -q "# jf CLI shell completion" ~/.zshrc; then
echo "" >> ~/.zshrc echo "" >> ~/.zshrc
echo "# BEGIN: jf CLI shell completion (added by coder module jfrog-oauth)" >> ~/.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 "compinit" >> ~/.zshrc
echo 'source "$HOME/.jfrog/jfrog_zsh_completion"' >> ~/.zshrc echo 'source "$HOME/.jfrog/jfrog_zsh_completion"' >> ~/.zshrc
echo "# END: jf CLI shell completion" >> ~/.zshrc echo "# END: jf CLI shell completion" >> ~/.zshrc
else
echo "🥳 ~/.zshrc already contains jf CLI shell completion configuration, skipping."
fi fi
else
echo "🤔 ~/.bashrc or ~/.zshrc does not exist, skipping jf CLI shell completion configuration."
fi fi

@ -92,19 +92,21 @@ fi
# Configure the JFrog CLI completion # Configure the JFrog CLI completion
echo "📦 Configuring 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}') 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 jf completion $SHELLNAME --install
## Add the completion script to the user's shell profile # Add the completion script to the user's shell profile
if [ "$SHELLNAME" == "bash" ]; then if [ "$SHELLNAME" == "bash" ] && [ -f ~/.bashrc ]; then
if ! grep -q "# jf CLI shell completion" ~/.bashrc; then if ! grep -q "# jf CLI shell completion" ~/.bashrc; then
echo "" >> ~/.bashrc echo "" >> ~/.bashrc
echo "# BEGIN: jf CLI shell completion (added by coder module jfrog-token)" >> ~/.bashrc echo "# BEGIN: jf CLI shell completion (added by coder module jfrog-token)" >> ~/.bashrc
echo 'source "$HOME/.jfrog/jfrog_bash_completion"' >> ~/.bashrc echo 'source "$HOME/.jfrog/jfrog_bash_completion"' >> ~/.bashrc
echo "# END: jf CLI shell completion" >> ~/.bashrc echo "# END: jf CLI shell completion" >> ~/.bashrc
else
echo "🥳 ~/.bashrc already contains jf CLI shell completion configuration, skipping."
fi fi
elif [ "$SHELLNAME" == "zsh" ]; then elif [ "$SHELLNAME" == "zsh" ] && [ -f ~/.zshrc ]; then
if ! grep -q "# jf CLI shell completion" ~/.zshrc; then if ! grep -q "# jf CLI shell completion" ~/.zshrc; then
echo "" >> ~/.zshrc echo "" >> ~/.zshrc
echo "# BEGIN: jf CLI shell completion (added by coder module jfrog-token)" >> ~/.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 "compinit" >> ~/.zshrc
echo 'source "$HOME/.jfrog/jfrog_zsh_completion"' >> ~/.zshrc echo 'source "$HOME/.jfrog/jfrog_zsh_completion"' >> ~/.zshrc
echo "# END: jf CLI shell completion" >> ~/.zshrc echo "# END: jf CLI shell completion" >> ~/.zshrc
else
echo "🥳 ~/.zshrc already contains jf CLI shell completion configuration, skipping."
fi fi
else
echo "🤔 ~/.bashrc or ~/.zshrc does not exist, skipping jf CLI shell completion configuration."
fi fi

Loading…
Cancel
Save