Skip to content

Instantly share code, notes, and snippets.

@jsongerber
Last active July 4, 2024 12:01
Show Gist options
  • Save jsongerber/7dfd9f2d22ae060b98e15c5590c4828d to your computer and use it in GitHub Desktop.
Save jsongerber/7dfd9f2d22ae060b98e15c5590c4828d to your computer and use it in GitHub Desktop.
Easily open an SSH connection using Neovim using ssh config and oil.nvim
# your config…
alias oil='~/.local/bin/oil-ssh.sh'
# your config…
#!/bin/sh
# This script is used to easily open an SSH connection through the Neovim Oil file manager.
# Before using this script you need to make it executable with `$ chmod +x oil-ssh.sh`.
# Usage: `$ ./oil-ssh.sh` (or `$ oil` with an alias)
# Select a host via fzf
host=$(grep 'Host\>' ~/.ssh/config | sed 's/^Host //' | grep -v '\*' | fzf --cycle --layout=reverse)
if [ -z "$host" ]; then
exit 0
fi
# Get user from host name
user=$(ssh -G "$host" | grep '^user\>' | sed 's/^user //')
nvim oil-ssh://"$user"@"$host"/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment