Skip to content

Instantly share code, notes, and snippets.

@kodaka
Last active August 26, 2019 17:19
Show Gist options
  • Save kodaka/c32bdc70b02899230a294605e558f536 to your computer and use it in GitHub Desktop.
Save kodaka/c32bdc70b02899230a294605e558f536 to your computer and use it in GitHub Desktop.
2019-08-06-filtering-ssh-host-with-peco.md
title date tags
Filtering SSH Host with peco
2019-08-06 18:00:00 +0900
ssh
peco
bash

Filtering Host from ~/.ssh/config using peco, and execute SSH.

You need to install peco.

brew install peco

And define function like this:

# .bashrc or somewhere
function peco-ssh() {
    local host=$(grep -iE '^host[[:space:]]+[^*]' $HOME/.ssh/config | sort | peco | awk '{print $2}')
    if [[ $host ]]; then
        echo "ssh $host"
        ssh $host
    fi
}

Then call it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment