From c8733f1cf1242e4b2d84d793168b74e6381ae339 Mon Sep 17 00:00:00 2001 From: Nicole O'Connor Date: Fri, 4 Sep 2020 20:41:59 -0700 Subject: [PATCH] command@sshhost works --- modules/ssh.zsh | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/modules/ssh.zsh b/modules/ssh.zsh index e83747a..0356bf3 100644 --- a/modules/ssh.zsh +++ b/modules/ssh.zsh @@ -1,3 +1,33 @@ function zle-accept-line-with-ssh () { - echo "stub" + # prevent replacing empty lines with "ssh -p" + if [[ ${BUFFER} == "" ]]; then + zle .accept-line + return + fi + + firstword=${BUFFER[(w)1]} + # Rough translation: "if @ is in firstword" + if [[ ${firstword[(i)@]} -le ${#firstword} ]]; then # Lit: "if the index of '@' within firstword is less than the length of firstword" + origbuffer=$BUFFER + + cmd=${firstword%@*} # set cmd to everything BEFORE the @ + host=${firstword#*@} # set host to everything AFTER the @ + # ports! + if [[ ${host[(i):]} -le ${#host} ]]; then + port="-p ${host#*:}" + host=${host%:*} + fi + args=${origbuffer#${firstword} } # set args to everything AFTER the first word + [[ $args == $firstword ]] && args="" # Prevent "command command@host" from running a command with no args + + if [[ $cmd == "" ]] && [[ $args == "" ]]; then + BUFFER="ssh $port $host" + else + BUFFER="ssh $port -t $host \"$cmd ${args}\"" + fi + fi + unset host port cmd + zle .accept-line } + +zle -N accept-line zle-accept-line-with-ssh