Commit 11813265 authored by Dom Sekotill's avatar Dom Sekotill Committed by Dom Sekotill
Browse files

Fix scripts for Git for Windows (and probably others)

parent 83c3f211
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -109,7 +109,7 @@ linux)
*)
	# Set title
	# (not suported by linux VT)
	hostname=`hostname -f`
	hostname=`hostname -f 2>/dev/null || hostname`
	SET_TITLE=`printf '\e]2;%s\007' "$hostname"`
	PROMPTCODES="$SET_TITLE"
	echo "$SET_TITLE"
+15 −7
Original line number Diff line number Diff line
@@ -67,16 +67,24 @@ git_check()
{
	local v
	GIT_VERSION=0
	for v in `git --version|cut -f3 -d\ |tr '.' ' '`; do
	for v in `git --version|cut -f3 -d\ |tr '.' ' '|cut -f1-3 -d\ `; do
		let 'GIT_VERSION = (GIT_VERSION << 8) + (v & 0xff)'
	done

	if [ $GIT_VERSION -ge $((0x020900)) ]; then
		local numcpu=`lscpu -p|grep '^[^#]'|wc -l`
		GIT_JOBS="--jobs=$(((numcpu>1)?(numcpu-1):(numcpu)))"
		local numcpu
		if has lscpu; then
			numcpu=`lscpu -p|grep '^[^#]'|wc -l`
		elif [ -n "${NUMBER_OF_PROCESSORS:-}" ]; then
			numcpu="$NUMBER_OF_PROCESSORS"
		else
		GIT_JOBS=
			numcpu=1
		fi
		GIT_JOBS="--jobs=$(((numcpu>1)?(numcpu-1):(numcpu)))"
		return
	fi

	GIT_JOBS=
}

update_worktree()
@@ -122,7 +130,7 @@ update_repos()
			Automatically generated:
			  source: .shell/funcs:update_submodules()
			  time:   `date`
			  host:   `hostname -f`
			  host:   `hostname -f 2>/dev/null || hostname`
		END_MESSAGE

		if git push origin HEAD:master; then
@@ -142,9 +150,9 @@ do_update()
	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 unit
	local unit ans

	if [ -n "$USE_PROMPT" ]; then
	if [ -n "${USE_PROMPT:-}" ]; then
		if [ $now -lt $((updated + 604800)) ]; then
			return
		fi
+25 −6
Original line number Diff line number Diff line
@@ -4,6 +4,9 @@ set -eu
: ${SSH_BIN:=`which ssh`}; export SSH_BIN


. ~/.shell/funcs


die() {
	[ ${CODE:=$?} -gt 1 ] || CODE=2
	echo >&2 "$*"
@@ -19,13 +22,29 @@ platform() {
	case `uname` in
		Linux*) PLATFORM=linux ;;
		CYGWIN*) PLATFORM=windows ;;
		MING*) PLATFORM=windows ;;
		Darwin*) PLATFORM=darwin ;;
		*) echo >&2 "Unrecognised platform: `uname`"; exit 2 ;;
	esac

	if [ -n "${ZSH_NAME:-}" ]; then
		SHELL=zsh
	elif [ -n "${BASH:-}" ]; then
		SHELL=bash
	else
		SHELL=sh
	fi
}

config_sed() {
	case "$SHELL" in
		bash) SED_WORD_DELIM='\b' ;;
		zsh|sh) SED_WORD_DELIM='\\b' ;;
	esac
}

runtime() {
	if [ -n "$XDG_RUNTIME_DIR" ] && [ -d "$XDG_RUNTIME_DIR" ]; then
	if [ -n "${XDG_RUNTIME_DIR:-}" ] && [ -d "$XDG_RUNTIME_DIR" ]; then
		RUNTIME="$XDG_RUNTIME_DIR/ssh"
	elif [ -d /tmp ]; then
		RUNTIME=/tmp/user/`id -u`/ssh
@@ -59,16 +78,16 @@ rule_canonisation() {
rule_runtime() {
	# Replace RUNTIME with the value of the RUNTIME variable
	[ -n "$RUNTIME" ] || die "RUNTIME not set"
	echo "s!\\\bRUNTIME\\\b!${RUNTIME-.}!g;"
	echo "s!${SED_WORD_DELIM}RUNTIME${SED_WORD_DELIM}!${RUNTIME-.}!g;"
}

make_config() {
	[ -z "${CONFIG-}" ] || return 0

	platform && ssh_version && runtime
	platform && ssh_version && runtime && config_sed

	PLATFORM="$PLATFORM:`hostname -f`:$SSH_MAJOR.$SSH_MINOR"
	PLATFORM_ID=`echo "$PLATFORM" | md5sum | cut -f1 -d' '`
	PLATFORM_UNIQ="$PLATFORM:`hostname -f 2>/dev/null || hostname`:$SSH_MAJOR.$SSH_MINOR"
	PLATFORM_ID=`echo "$PLATFORM_UNIQ" | md5sum | cut -f1 -d' '`
	CONFIG="$RUNTIME/config-$PLATFORM_ID"

	if [ -f "$CONFIG" ] &&
@@ -88,7 +107,7 @@ make_config() {
}

# Ensure the GPG agent is running if installed
if type gpg-agent; then
if has gpg-agent; then
	gpg-connect-agent /bye
fi >&2