diff --git a/config/profile b/config/profile index 53abbd1..ad49953 100644 --- a/config/profile +++ b/config/profile @@ -14,9 +14,9 @@ dependencies=( ) # Load dotfiles directory into DOTFILES_DIR -# Dotfiles directory should be in environment or ~/.dotfiles-dir -if [ -f "$HOME/.dotfiles-dir" ]; then - source "$HOME/.dotfiles-dir" +# Dotfiles directory should be in environment or ~/.dotfiles-config +if [ -f "$HOME/.dotfiles-config" ]; then + source "$HOME/.dotfiles-config" fi # PATHs diff --git a/config/systemd/update-wallpapers.service b/config/systemd/update-wallpapers.service index b15298c..b372dab 100644 --- a/config/systemd/update-wallpapers.service +++ b/config/systemd/update-wallpapers.service @@ -6,7 +6,7 @@ Type=simple User=brad Environment=DISPLAY=:0 ExecStartPre=/bin/sleep 3 -# TODO: The file might not be here if ~/.dotfiles-dir set to somewhere else +# TODO: The file might not be here if ~/.dotfiles-config set to somewhere else ExecStart=/home/brad/dotfiles/bin/start-wallpaper.sh [Install] diff --git a/config/zshrc b/config/zshrc index eef064a..5c5b2b9 100755 --- a/config/zshrc +++ b/config/zshrc @@ -149,8 +149,8 @@ if [ -n "$NO_GIT_CHECK" ] && [ ! "$NO_GIT_CHECK" -eq 1 ]; then elif [[ $dotfiles_version = 4 ]]; then echo "Dotfiles repository at $DOTFILES_DIR has diverged from origin" elif [[ $dotfiles_version = 5 ]]; then - echo "Dotfiles repository not set in $HOME/.dotfiles-dir" - echo "Please run ./install.sh in dotfiles repository and exit to create ~/.dotfiles-dir" + echo "Dotfiles repository not set in $HOME/.dotfiles-config" + echo "Please run ./install.sh in dotfiles repository and exit to create ~/.dotfiles-config" echo "The following will not work until this is set:" echo " - oh-my-zsh will not be started" echo " - gruvbox color palette will not be loaded" diff --git a/dotfiles-local.sh b/dotfiles-local.sh index a1671e1..b328512 100755 --- a/dotfiles-local.sh +++ b/dotfiles-local.sh @@ -5,11 +5,11 @@ source "$HOME/.profile" if [ -f "$HOME/.profile.local" ]; then source "$HOME/.profile.local" fi -if [ -f "$HOME/.dotfiles-dir" ]; then - source "$HOME/.dotfiles-dir" +if [ -f "$HOME/.dotfiles-config" ]; then + source "$HOME/.dotfiles-config" else - echo "Dotfiles repository not set in $HOME/.dotfiles-dir" - echo "Please run ./install.sh in dotfiles repository and exit to create ~/.dotfiles-dir" + echo "Dotfiles repository not set in $HOME/.dotfiles-config" + echo "Please run ./install.sh in dotfiles repository and exit to create ~/.dotfiles-config" exit 1 fi if [ -z "$DOTFILES_LOCAL_REPOSITORY" ]; then diff --git a/functions.sh b/functions.sh index 8b3e845..24bc305 100644 --- a/functions.sh +++ b/functions.sh @@ -24,3 +24,21 @@ function user_service_enabled { return "$return_" } + +function update_dotfiles_config { + if [ "$#" != 2 ]; then + echo "Usage: update_dotfiles_config ENV_VARIABLE VALUE" + exit 1 + fi + local var="$1" + local val="$2" + + if [ ! -f "$HOME/.dotfiles-config" ]; then + touch "$HOME/.dotfiles-config" + fi + if [ $(cat "$HOME/.dotfiles-config" | grep -Eq "^export $1=.*$") ]; then + sed -i "s/$1=.*$/$1=$2/" "$HOME/.dotfiles-config" + else + echo "export $1=$2" >> "$HOME/.dotfiles-config" + fi +} diff --git a/install.sh b/install.sh index 6a5724a..dc5c4d9 100755 --- a/install.sh +++ b/install.sh @@ -70,20 +70,26 @@ # Then go into iTerm2 settings and set Source Code Pro for Powerline as the font dir="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" # dotfiles repository directory -# TODO: Migrate this to an environment variable in .profile.local -if [ ! -f "$HOME/.dotfiles-dir" ]; then +source "$DOTFILES_DIR"/functions.sh +if [ -f "$HOME/.dotfiles-dir" ]; then + # Migrate legacy config + echo "Migrating .dotfiles-dir to .dotfiles-config" + mv "$HOME/.dotfiles-dir" "$HOME/.dotfiles-config" +fi +if [ ! -f "$HOME/.dotfiles-config" ]; then if [ ! -f "$dir/install.sh" ] || [ ! -f "$dir/dotfiles-local.sh" ]; then echo "Please run this script initially from within the dotfiles directory" exit 1 fi - echo "Writing 'export DOTFILES_DIR=$dir' to $HOME/.dotfiles-dir" - echo "export DOTFILES_DIR=$dir" > "$HOME/.dotfiles-dir" + echo "Writing 'export DOTFILES_DIR=$dir' to $HOME/.dotfiles-config" + update_dotfiles_config "DOTFILES_DIR" "$dir" + # echo "export DOTFILES_DIR=$dir" > "$HOME/.dotfiles-config" echo "" else - echo "Loading existing $HOME/.dotfiles-dir" + echo "Loading existing $HOME/.dotfiles-config" echo "" fi -source "$HOME/.dotfiles-dir" +source "$HOME/.dotfiles-config" unset dir config_dir="$DOTFILES_DIR"/config packages_dir="$DOTFILES_DIR"/packages @@ -93,7 +99,6 @@ pacman_args="--noconfirm --needed" restart_needed=0 interactive=0 -source "$DOTFILES_DIR"/functions.sh if [ ! -L $DOTFILES_DIR/bin/dotfiles-install ]; then echo "Adding this script to PATH. 'dotfiles-install' to run in the future" ln -s "$DOTFILES_DIR/install.sh" "$DOTFILES_DIR/bin/dotfiles-install"