Skip to content

Commit

Permalink
SSH autocompletions performance: avoid one SSH call
Browse files Browse the repository at this point in the history
  • Loading branch information
mjuric committed Dec 23, 2019
1 parent 277a85d commit f0ed68d
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions git-clone-completions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -844,18 +844,14 @@ __mj_ssh_read()
return 1
}

# _ssh <host> [commands]
# _ssh_ensure_started <host>
#
# connect to the SSH server, potentially reusing the connection, and execute
# <commands>
# ensure there's an open connection to $host
#
_ssh()
_ssh_ensure_started()
{
local host="$1"
shift

# start the connection
if [[ $host != $__ssh_host ]] || ! { /bin/echo '' >&217; } 2>/dev/null; then
if [[ "$host" != ${__ssh_host} ]] || ! { /bin/echo '' >&217; } 2>/dev/null; then
_dbg "new connection for $host"
# close any open connection
__mj_ssh_stop
Expand All @@ -864,11 +860,22 @@ _ssh()
else
_dbg "reusing connection for $host"
fi
}

# _ssh <host> [commands]
#
# connect to the SSH server, potentially reusing the connection, and execute
# <commands>
#
_ssh()
{
local host="$1"
shift

_ssh_ensure_started "$host"

# write commands
__mj_ssh_write "(" "$@" ")" || { _dbg "write failed"; __mj_ssh_stop; return 1; }

# read output
__mj_ssh_read || { _dbg "read failed"; __mj_ssh_stop; return 1; }
}

Expand Down Expand Up @@ -896,7 +903,7 @@ _ssh_list_files()
# prime the cached connection (as all subsequent invocations will be
# in subshells and can't set the various __ssh_* variables with
# connection reuse info)
_ssh "$userhost" : &>/dev/null
_ssh_ensure_started "$userhost" &>/dev/null

local files
if [[ $dirs_only == 1 ]]; then
Expand Down

0 comments on commit f0ed68d

Please sign in to comment.