From cea6f933541aa2273dab011a6d3bbaaa53ec4893 Mon Sep 17 00:00:00 2001 From: David Todd Date: Mon, 11 Jan 2021 22:20:28 -0600 Subject: [PATCH] Move the update scripts to root of repo Also rework the variables in the environment to use /bin/true and /bin/false instead of string representations of this. Might cause problems, haven't tested yet --- .environment | 14 +++++++------- .zshrc | 4 ++-- .../check_for_upgrade.sh => check_for_upgrade.sh | 15 +++++++-------- install.sh | 2 +- internal_bin/upgrade.sh => upgrade.sh | 0 5 files changed, 17 insertions(+), 18 deletions(-) rename internal_bin/check_for_upgrade.sh => check_for_upgrade.sh (84%) rename internal_bin/upgrade.sh => upgrade.sh (100%) diff --git a/.environment b/.environment index 6d29e4b..10c57b3 100644 --- a/.environment +++ b/.environment @@ -15,28 +15,28 @@ export PATH=${HOME}/bin:$PATH:/usr/lib/wine/bin:/sbin:/usr/sbin:/usr/local/bin # Give the path to the dotfiles export _DOTFILES="${HOME}/dotfiles" -# Allow automatic updates -export DISABLE_DOTFILES_AUTO_UPDATE="FALSE" +# Allow checking for automatic updates +export ENABLE_DOTFILES_AUTO_UPDATE=true # Set "true" to update without asking first -export DISABLE_DOTFILES_UPDATE_PROMPT="FALSE" +export DISABLE_DOTFILES_UPDATE_PROMPT=false # Update every 2 weeks (OMZ default) export UPDATE_DOTFILES_DAYS=13 # Whether or not to automatically connect to a TMUX session when opening the shell -export ENABLE_TMUXAC="FALSE" +export ENABLE_TMUXAC=false # If there is not an active tmux session, we probably want one # Otherwise, the shell will not open the session again (eg. opening tabs, new terminals) if $(tmux list-sessions >> /dev/null 2>&1); then - export TMUXATT="TRUE" + export TMUXATT=true else - export TMUXATT="FALSE" + export TMUXATT=false fi # Automatically attach tmux session "C0DE" -if [[ -z "$TMUX" && "$TMUXATT" != "TRUE" && "$ENABLE_TMUXAC" != "FALSE" ]]; then +if [[ -z "$TMUX" && "$TMUXATT" && "$ENABLE_TMUXAC" ]]; then tmux attach -t C0DE || tmux new -s C0DE fi diff --git a/.zshrc b/.zshrc index 6d49bb8..7259804 100644 --- a/.zshrc +++ b/.zshrc @@ -41,8 +41,8 @@ bindkey "^[s" insert-sudo # Check for updates... # Stolen and modified Oh-My-ZSH's update system -if [ "$DISABLE_DOTFILES_AUTO_UPDATE" != "true" ]; then - env ZSH=$ZSH _DOTFILES=$_DOTFILES DISABLE_UPDATE_PROMPT=$DISABLE_DOTFILES_UPDATE_PROMPT zsh -f $_DOTFILES/internal_bin/check_for_upgrade.sh +if [ "${ENABLE_DOTFILES_AUTO_UPDATE}" ]; then + env ZSH=$ZSH _DOTFILES=$_DOTFILES DISABLE_UPDATE_PROMPT=$DISABLE_DOTFILES_UPDATE_PROMPT zsh -f $_DOTFILES/check_for_upgrade.sh fi # Oh-My-ZSH Options below this line diff --git a/internal_bin/check_for_upgrade.sh b/check_for_upgrade.sh similarity index 84% rename from internal_bin/check_for_upgrade.sh rename to check_for_upgrade.sh index 5868ade..033e352 100755 --- a/internal_bin/check_for_upgrade.sh +++ b/check_for_upgrade.sh @@ -10,15 +10,14 @@ function _current_epoch() { echo $(( $EPOCHSECONDS / 60 / 60 / 24 )) } -function _update_dotfiles_update() { +function _touch_dotfiles_update() { echo "export LAST_EPOCH=$(_current_epoch)" > ${HOME}/.dotfiles-update echo "touched ~/.dotfiles-update" } function _upgrade_dotfiles() { - env _DOTFILES=$_DOTFILES sh $_DOTFILES/internal_bin/upgrade.sh - # update the zsh file - _update_dotfiles_update + env _DOTFILES=$_DOTFILES sh $_DOTFILES/upgrade.sh + _touch_dotfiles_update } # Configure this in shell/env @@ -49,12 +48,12 @@ if mkdir -p "$_DOTFILES/update.lock" 2>/dev/null; then if [[ -z "$LAST_EPOCH" ]]; then echo "Missing \$LAST_EPOCH" - _update_dotfiles_update && return 0; + _touch_dotfiles_update && return 0; fi epoch_diff=$(($(_current_epoch) - $LAST_EPOCH)) if [ $epoch_diff -gt $epoch_target ]; then - if [ "$DISABLE_UPDATE_PROMPT" = "true" ]; then + if [ "${DISABLE_UPDATE_PROMPT}" ]; then _upgrade_dotfiles else echo "[Dotfiles] Would you like to check for updates? [Y/n]: \c" @@ -62,14 +61,14 @@ if mkdir -p "$_DOTFILES/update.lock" 2>/dev/null; then if [[ "$line" == Y* ]] || [[ "$line" == y* ]] || [ -z "$line" ]; then _upgrade_dotfiles else - _update_dotfiles_update + _touch_dotfiles_update fi fi fi else echo "Missing ~/.dotfiles-update" # create the zsh file - _update_dotfiles_update + _touch_dotfiles_update fi rmdir $_DOTFILES/update.lock diff --git a/install.sh b/install.sh index 64cbf05..028cde3 100755 --- a/install.sh +++ b/install.sh @@ -51,7 +51,7 @@ read -p "Press enter to install my dotfiles " WAIT_FOR_INPUT # If the update script exists, try to do a normal update if [ -x "${DOTFILES}/check_for_upgrade.sh" ]; then source "${DOTFILES}/.environment" - env DOTFILES=${DOTFILES} DISABLE_UPDATE_PROMPT='FALSE' zsh -f "${DOTFILES}/check_for_upgrade.sh" + env DOTFILES=${DOTFILES} DISABLE_UPDATE_PROMPT=false zsh -f ${DOTFILES}/check_for_upgrade.sh else echo "Cloning dotfiles to ${DOTFILES}" rm -rf "${DOTFILES}" diff --git a/internal_bin/upgrade.sh b/upgrade.sh similarity index 100% rename from internal_bin/upgrade.sh rename to upgrade.sh