diff --git a/bin/oref0-log-shortcuts.sh b/bin/oref0-log-shortcuts.sh index 5de69ac94..57acb1f88 100755 --- a/bin/oref0-log-shortcuts.sh +++ b/bin/oref0-log-shortcuts.sh @@ -1,63 +1,24 @@ #!/usr/bin/env bash -# Because this script is meant to be "source"d, not just run normally, it -# doesn't include oref0-bash-common-functions.sh like most others do. +#Maintain a standard list of convenience aliases in the ~/.bash_profile file. -myopenaps=${OPENAPS_DIR:-"$HOME/myopenaps"} -self="${BASH_SOURCE[0]}" -function usage () -{ - cat <>"$PROFILE_PATH" - fi + remove_obsolete_aliases + + #if they exist, remove current aliases to avoid multiple identical aliases in .bash_profile file on a repeat setup + remove_current_aliases + + #add in the current aliases + add_current_aliases + # source default /etc/profile as well if ! grep -q /etc/skel/.profile "$PROFILE_PATH"; then echo "source /etc/skel/.profile" >> "$PROFILE_PATH" @@ -65,38 +26,34 @@ function add_aliases_to_profile () } # In versions prior to 0.7.0, we individually added a bunch of aliases to the -# user's .bash_profile; in 0.7.0, we instead make the .bash_profile source a -# file that includes those aliases. For upgrading purposes, we want to remove +# user's .bash_profile; For upgrading purposes, we want to remove # aliases that exactly match the ones that earlier versions added, but not # aliases that have been modified. + function remove_obsolete_aliases () { - local PROFILE_PATH="$1" - - # List of aliases that may have been added by previous versions of oref0. - # Some have multiple variants. OBSOLETE_ALIASES=$(cat <"$PROFILE_PATH".new$$ && + mv -f "$PROFILE_PATH".new$$ "$PROFILE_PATH" + done) +} + +function add_current_aliases () { + CURRENT_ALIASES1=$(cat <> "$PROFILE_PATH" +} -# Script was loaded with "source" (rather than regular execution)? -if [[ "${BASH_SOURCE[0]}" != "${0}" ]]; then - # Don't parse arguments, because the arguments in $@ belong to the parent - # script, not to us. - do_aliases -else - if [[ $# == 0 ]]; then - usage - exit 0 - fi - for i in "$@"; do - case "$i" in - --add-to-profile) - test -f "$HOME/.bash_profile" && add_aliases_to_profile "$HOME/.bash_profile" - ;; - --add-to-profile=*) - test -f "${i#*=}" && add_aliases_to_profile "${i#*=}" - ;; - *) - echo "Unrecognized argument: $i" - exit 1 - ;; - esac - done -fi +# Do it! + +update_aliases_in_profile + +exit 0 diff --git a/bin/oref0-setup.sh b/bin/oref0-setup.sh index 71d9d4921..b33f1fa85 100755 --- a/bin/oref0-setup.sh +++ b/bin/oref0-setup.sh @@ -1050,10 +1050,11 @@ if prompt_yn "" N; then cd $directory || die "Can't cd $directory" do_openaps_import $HOME/src/oref0/lib/oref0-setup/supermicrobolus.json - echo "Adding OpenAPS log shortcuts" # Make sure that .bash_profile exists first, then call script to add the log shortcuts touch "$HOME/.bash_profile" - oref0-log-shortcuts --add-to-profile="$HOME/.bash_profile" + + echo "Adding OpenAPS log shortcuts" + oref0-log-shortcuts # Append NIGHTSCOUT_HOST and API_SECRET to $HOME/.bash_profile so that openaps commands can be executed from the command line #echo Add NIGHTSCOUT_HOST and API_SECRET to $HOME/.bash_profile diff --git a/tests/bash-util-functions.test.sh b/tests/bash-util-functions.test.sh index 8c15018b9..ba5580ec2 100755 --- a/tests/bash-util-functions.test.sh +++ b/tests/bash-util-functions.test.sh @@ -189,32 +189,7 @@ EOT if [[ "$(source ./test_script_is_sourced.sh)" != "sourced" ]]; then fail_test "script_is_sourced on sourced script" fi - - # Test oref0-log-shortcuts - cat >test_bash_profile <