Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

source bash config from existing bash config to make rolling back changes easier, use posix-compliant echo #89

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
#!/bin/sh -e

# Make sure that echo is posix compliant
echo() {
if [ ! "$BASH_VERSION" = "" ]; then
/usr/bin/env echo -e "$@"
else
/usr/bin/env echo "$@"
fi
}

RC='\033[0m'
RED='\033[31m'
YELLOW='\033[33m'
Expand Down Expand Up @@ -248,25 +257,23 @@ create_fastfetch_config() {
linkConfig() {
## Get the correct user home directory.
USER_HOME=$(getent passwd "${SUDO_USER:-$USER}" | cut -d: -f6)
## Check if a bashrc file is already there.
OLD_BASHRC="$USER_HOME/.bashrc"
if [ -e "$OLD_BASHRC" ]; then
echo "${YELLOW}Moving old bash config file to $USER_HOME/.bashrc.bak${RC}"
if ! mv "$OLD_BASHRC" "$USER_HOME/.bashrc.bak"; then
echo "${RED}Can't move the old bash config file!${RC}"
exit 1
fi
## Make sure a bashrc file is already there.
CURRENT_BASHRC="$USER_HOME/.bashrc"
if [ ! -e "$CURRENT_BASHRC" ]; then
echo "${YELLOW}$CURRENT_BASHRC doesn't exist, creating it${RC}"
touch "$CURRENT_BASHRC"
fi

echo "${YELLOW}Linking new bash config file...${RC}"
ln -svf "$GITPATH/.bashrc" "$USER_HOME/.bashrc" || {
echo "${RED}Failed to create symbolic link for .bashrc${RC}"
exit 1
}
ln -svf "$GITPATH/starship.toml" "$USER_HOME/.config/starship.toml" || {
echo "${RED}Failed to create symbolic link for starship.toml${RC}"
exit 1
}
if grep -q ". $GITPATH/.bashrc" < "$CURRENT_BASHRC" ; then
echo "Bash config is already being sourced${RC}"
else
echo "Appending to current bash config"
cat >> "$CURRENT_BASHRC" << EOF

## ChrisTitusTech's bash config
. $GITPATH/.bashrc
EOF
fi
}

checkEnv
Expand Down