tools/install: create "~/.bash_profile" if it doesn't exist

This commit is contained in:
Koichi Murase 2023-02-05 01:38:52 +09:00
parent 60332ed8fb
commit f6597af711
3 changed files with 35 additions and 4 deletions

@ -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

@ -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

@ -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