From cffe649ad607d905a2ec990b455cd952f884b399 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20P=C5=82azie=C5=84ski?= Date: Fri, 27 Oct 2017 22:30:19 +0200 Subject: [PATCH] Update sshc command to respect sourcing files in zshrc --- zshrc | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/zshrc b/zshrc index e83687a..3c8fe81 100644 --- a/zshrc +++ b/zshrc @@ -65,6 +65,7 @@ find_up () { command-exists () { return $(command -v $1 >/dev/null); } +NEWLINE=$'\n' #---------------------------------- Listings ---------------------------------- @@ -530,14 +531,33 @@ sshc() { local source target source=${ZDOTDIR:-$HOME} target="/tmp/.zdot-${RANDOM}" + consolidate-config ssh -q -o "ControlPath=/tmp/.cm-%r@%h:%p" -o "ControlMaster=yes" -o "ControlPersist=yes" $1 'false' ssh -q -o "ControlPath=/tmp/.cm-%r@%h:%p" $1 "mkdir $target" - scp -q -o "ControlPath=/tmp/.cm-%r@%h:%p" $source/.zshrc $1:$target/.zshrc + scp -q -o "ControlPath=/tmp/.cm-%r@%h:%p" $source/.zshrc-consolidated $1:$target/.zshrc ssh -q -o "ControlPath=/tmp/.cm-%r@%h:%p" $1 -t "ZDOTDIR=$target exec zsh -l" ssh -q -o "ControlPath=/tmp/.cm-%r@%h:%p" $1 "rm -r $target" ssh -q -o "ControlPath=/tmp/.cm-%r@%h:%p" -O stop $1 } +consolidate-config() { + local initial final + initial=${ZDOTDIR:-$HOME}/.zshrc + final=${ZDOTDIR:-$HOME}/.zshrc-consolidated + cp $initial $final + while true; do + found=$(grep -oP '^source \K.*$' $final) + if [[ -z $found ]]; then + break; + fi + replaced=${(e)found} + if [[ $replaced != /* ]]; then + replaced=$(dirname $final)/$replaced + fi + sed -i "\#^source $found\$# r $replaced${NEWLINE}d" $final + done +} + #---------------------------------- Miscellaneous ---------------------------- setopt extended_glob