diff --git a/README.md b/README.md index f8d8a36..c5b0eef 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,15 @@ bash -c "$(wget https://raw.githubusercontent.com/ohmybash/oh-my-bash/master/too ``` This replaces `~/.bashrc` with the version provided by Oh My Bash. The original `.bashrc` is backed up with the name `~/.bashrc.omb-TIMESTAMP`. +If `~/.bash_profile` does not exist, this also creates a new file `~/.bash_profile` with the default contents. + +⚠️ If `~/.bash_profile` already existed before Oh My Bash is installed, please make sure that`~/.bash_profile` contains the line `source ~/.bashrc` or `. ~/.bashrc`. +If not, please add the following three lines in `~/.bash_profile`: +```bash +if [[ -f ~/.bashrc ]]; then + source ~/.bashrc +fi +``` ## Using Oh My Bash diff --git a/templates/bash_profile.osh-template b/templates/bash_profile.osh-template new file mode 100644 index 0000000..7872597 --- /dev/null +++ b/templates/bash_profile.osh-template @@ -0,0 +1,11 @@ +# .bash_profile -*- mode: sh -*- + +# Load login settings and environment variables +if [[ -f ~/.profile ]]; then + source ~/.profile +fi + +# Load interactive settings +if [[ -f ~/.bashrc ]]; then + source ~/.bashrc +fi diff --git a/tools/install.sh b/tools/install.sh index c117e48..54a6ae1 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -134,12 +134,23 @@ _omb_install_user_bashrc() { _omb_install_run mv ~/.bashrc "$bashrc_backup" fi - printf "${BLUE}Using the Oh My Bash template file and adding it to ~/.bashrc${NORMAL}\n" - _omb_install_run cp "$OSH"/templates/bashrc.osh-template ~/.bashrc + printf "${BLUE}Copying the Oh-My-Bash template file to ~/.bashrc${NORMAL}\n" sed "/^export OSH=/ c\\ export OSH='${OSH//\'/\'\\\'\'}' - " ~/.bashrc >| ~/.bashrc.omb-temp - _omb_install_run mv -f ~/.bashrc.omb-temp ~/.bashrc + " "$OSH"/templates/bashrc.osh-template >| ~/.bashrc.omb-temp && + _omb_install_run mv -f ~/.bashrc.omb-temp ~/.bashrc + + # If no file is found at ~/.bash_profile, we create it with the default + # content. + if [[ ! -e ~/.bash_profile ]]; then + if [[ -h ~/.bash_profile ]]; then + _omb_install_run rm -f ~/.bash_profile + fi + _omb_install_run mv -f "$OSH"/templates/bash_profile.osh-template ~/.bash_profile + else + command grep -qE '(source|\.)[[:space:]].*/\.bashrc' ~/.bash_profile 2>/dev/null || + printf '%s\n' "${GREEN}Please make sure that ~/.bash_profile contains \"source ~/.bashrc\"${NORMAL}" + fi set +e _omb_install_banner