Skip to content

Commit

Permalink
improve setup script (avoid redundancies for bash/zsh) (#718)
Browse files Browse the repository at this point in the history
  • Loading branch information
hohwille authored Oct 29, 2024
1 parent 6579538 commit 071e732
Showing 1 changed file with 32 additions and 39 deletions.
71 changes: 32 additions & 39 deletions cli/src/main/package/setup
Original file line number Diff line number Diff line change
@@ -1,46 +1,39 @@
#!/bin/bash

cd "$(dirname "${BASH_SOURCE:-$0}")" || exit 255
echo "Setting up your IDEasy in ${PWD}"

AUTOCOMPLETION="source ${PWD}/completion"

if ! grep -q "${AUTOCOMPLETION}" ~/.bashrc; then
echo -e "${AUTOCOMPLETION}" >> ~/.bashrc
fi
if ! grep -q "alias ide=" ~/.bashrc; then
echo -e "alias ide=\"source ${PWD}/bin/ide\"" >> ~/.bashrc
echo -e "ide" >> ~/.bashrc
fi

if [ "${OSTYPE}" != "cygwin" ] && [ "${OSTYPE}" != "msys" ]; then
if ! grep -q "IDE_ROOT" ~/.bashrc
then
echo -e 'export IDE_ROOT="$(pwd)"' >> ~/.bashrc
fi

if ! grep -q "IDE_ROOT" ~/.zshrc
then
echo -e 'export IDE_ROOT="$(pwd)"' >> ~/.zshrc
function doSetupInConfigFile() {
local cfg=$1
if [ ! -f "${cfg}" ]; then
echo "${cfg} not found - skipping."
return
fi
fi


if [ -f ~/.zshrc ]; then
if ! grep -q "compinit" ~/.zshrc
then
echo -e 'autoload -Uz compinit\ncompinit' >> ~/.zshrc
if [ "${cfg}" = "~/.zshrc" ]; then
if ! grep -q "compinit" "${cfg}"; then
echo -e 'autoload -Uz compinit\ncompinit' >> "${cfg}"
fi
if ! grep -q "bashcompinit" "${cfg}"; then
echo -e 'autoload bashcompinit\nbashcompinit' >> "${cfg}"
fi
fi
if ! grep -q "bashcompinit" ~/.zshrc
then
echo -e 'autoload bashcompinit\nbashcompinit' >> ~/.zshrc
echo "Configuring IDEasy in ${cfg}."
if ! grep -q "${AUTOCOMPLETION}" "${cfg}"; then
echo -e "${AUTOCOMPLETION}" >> "${cfg}"
fi
if ! grep -q "${AUTOCOMPLETION}" ~/.zshrc
then
echo -e "${AUTOCOMPLETION}" >> ~/.zshrc
if ! grep -q "alias ide=" "${cfg}"; then
echo -e "alias ide=\"source ${PWD}/bin/ide\"" >> "${cfg}"
echo -e "ide" >> "${cfg}"
fi
if ! grep -q "alias ide=" ~/.zshrc; then
echo -e "alias ide=\"source ${PWD}/bin/ide\"" >> ~/.zshrc
echo -e "ide" >> ~/.zshrc
if [ "${OSTYPE}" != "cygwin" ] && [ "${OSTYPE}" != "msys" ]; then
if ! grep -q "IDE_ROOT" "${cfg}"
then
echo -e 'export IDE_ROOT="${PWD}"' >> "${cfg}"
fi
fi
fi
}

cd "$(dirname "${BASH_SOURCE:-$0}")" || exit 255
echo "Setting up your IDEasy in ${PWD}"

AUTOCOMPLETION="source ${PWD}/completion"

doSetupInConfigFile ~/.bashrc
doSetupInConfigFile ~/.zshrc

0 comments on commit 071e732

Please sign in to comment.