Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: handle syntax Host= and leading spaces and w/o preceding blank line #22

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions zsh-ssh.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ _ssh-host-list() {

ssh_config=$(_parse_config_file $SSH_CONFIG_FILE)
ssh_config=$(echo $ssh_config | command grep -v -E "^\s*#[^_]")
# Make sure each Host line is preceded by an empty line
ssh_config=$(echo $ssh_config | command sed 's/[[:space:]]*Host\b/\nHost /g')

host_list=$(echo $ssh_config | command awk '
function join(array, start, end, sep, result, i) {
Expand All @@ -52,10 +54,12 @@ _ssh-host-list() {
}

function parse_line(line) {
n = split(line, line_array, " ")
# Manualy remove leading spaces for split with regex
line = gensub(/^\s+/, "", "g", line)
n = split(line, line_array, " +|=")

key = line_array[1]
value = join(line_array, 2, n)
value = join(line_array, 2, n, " ")

return key "#-#" value
}
Expand Down Expand Up @@ -201,7 +205,6 @@ fzf-complete-ssh() {
--header-lines=2 \
--reverse \
--prompt='SSH Remote > ' \
--no-separator \
--bind 'shift-tab:up,tab:down,bspace:backward-delete-char/eof' \
--preview 'ssh -T -G $(cut -f 1 -d " " <<< {}) | grep -i -E "^User |^HostName |^Port |^ControlMaster |^ForwardAgent |^LocalForward |^IdentityFile |^RemoteForward |^ProxyCommand |^ProxyJump " | column -t' \
--preview-window=right:40%
Expand Down