Commit 6bcaf01c authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Change timestamp during do_update

parent 4c3f80db
Loading
Loading
Loading
Loading
+16 −4
Original line number Diff line number Diff line
@@ -141,9 +141,10 @@ check_submodule()
do_update()
{
	local timestamp=${HOME}/.shell/.update
	local now=`date +%s` updated=`date -r $timestamp +%s 2>/dev/null`
	local now=`date +%s` updated=`date -r "$timestamp" +%s 2>/dev/null`
	local BOLD_BLUE=$'\033[34;1m' DEFAULT=$'\033[m'
	local prompt="${BOLD_BLUE}Would you like to update dotfiles?${DEFAULT} "
	local shell=`get_shell`
	local unit ans

	if [ -n "${USE_PROMPT:-}" ]; then
@@ -151,7 +152,7 @@ do_update()
			return
		fi

		case `get_shell` in
		case $shell in
			zsh) read "?$prompt" ans ;;
			*) read -p "$prompt" ans ;;
		esac
@@ -162,6 +163,19 @@ do_update()
		esac
	fi

	finalise_timestamp() {
		code=$?
		unset -f finalise_timestamp
		case $code in
			0) rm "$1.old" ;;
			*) mv "$1.old" "$1" ;;
		esac 2>/dev/null
	}
	trap "finalise_timestamp '$timestamp' || rm '$timestamp'" \
		`test $shell = bash && echo RETURN || echo EXIT`
	test -e "$timestamp" && mv "$timestamp" "$timestamp.old"
	touch "$timestamp"

	(cd ~
		set -eu
		git fetch origin &&
@@ -169,8 +183,6 @@ do_update()
		update_worktree
	) || return

	touch "$timestamp"

	# re-source this file
	unset SOURCED_SHELL_FUNCS
	. ~/.shell/funcs