Commit 999c407e authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Use %C replacement in SSH configs if available

parent a67e5b93
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -52,6 +52,7 @@ make_config() {
			`rule_mux`
			`rule_mux_persist`
			`rule_canonisation`
			`rule_percent_C`
			`rule_include`

			1
@@ -123,6 +124,21 @@ rule_canonisation() {
	echo 'match($1, /^Canonical/) { remove_line() }'
}

rule_percent_C() {
	# %C requires >=6.7
	[ $SSH_MAJOR -gt 6 ] && return
	[ $SSH_MAJOR -eq 6 ] && [ $SSH_MINOR -ge 7 ] && return
	cat <<-'END_AWK'
		match($1, /^(ControlPath|LocalCommand)/) {
			# Temporarily encode %% as the invalid line-feed character to 
			# prevent accidental replacement of "%%C" with "%%l:%r@%h:%p"
			gsub(/%%/, "\n")
			gsub(/%C/, "%l:%r@%h:%p")
			gsub(/\n/, "%%")
		}
	END_AWK
}

rule_include() {
	# Include requires >=7.2
	# If including config.local, remove as it is concatenated by this script
+2 −1
Original line number Diff line number Diff line
@@ -37,10 +37,11 @@ Host 192.168.* 10.* *.lan *.local localhost
## REQUIRES: (Match exec) 6.5
## REQUIRES: (ControlMaster, ControlPath) 3.9
## REQUIRES: (ControlPersist) 5.6
## REQUIRES: (%C) 6.7
#@fallback: test ${PLATFORM:-unknown} != windows
Match exec "test ${PLATFORM:-unknown} != windows"
	ControlMaster auto
	ControlPath ~/.ssh/%l:%r@%h:%p
	ControlPath ~/.ssh/%C.sock
	ControlPersist 2h

# === Local Includes ===