Last active
February 15, 2025 18:18
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# your config… | |
alias oil='~/.local/bin/oil-ssh.sh' | |
# your config… |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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