diff --git a/cli/src/main/package/setup b/cli/src/main/package/setup index f22c797c4..d7fa8828c 100755 --- a/cli/src/main/package/setup +++ b/cli/src/main/package/setup @@ -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