-
-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from TechDufus/nvim_remote_edit
Allows editing remote files with local nvim via sshfs mount.
- Loading branch information
Showing
2 changed files
with
29 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Write a function that first ensures that ~/.sshfs exists, then mounts the | ||
# remote directory to ~/.sshfs/<name_of_server_input>, then opens the remote directory in | ||
# Neovim. When neovim is closed, unmount the remote directory. | ||
|
||
function nisshfs() { | ||
local remote_dir='/' | ||
if [ ! -d ~/.sshfs ]; then mkdir ~/.sshfs > /dev/null 2>&1; fi | ||
if [ ! -d ~/.sshfs/$1 ]; then mkdir ~/.sshfs/$1 > /dev/null 2>&1; fi | ||
if [ ! -z $2 ]; then remote_dir=$2; fi | ||
sshfs -o default_permissions $1:$remote_dir $HOME/.sshfs/$1 | ||
nvim $HOME/.sshfs/$1 | ||
fusermount -zu $HOME/.sshfs/$1 | ||
rm -rf $HOME/.sshfs/$1 | ||
} | ||
|
||
|
||
# give nisshfs ssh tab completion for servers in ~/.ssh/config | ||
function _nisshfs() { | ||
local cur prev opts | ||
COMPREPLY=() | ||
cur="${COMP_WORDS[COMP_CWORD]}" | ||
prev="${COMP_WORDS[COMP_CWORD-1]}" | ||
opts=$(grep -E '^Host ' ~/.ssh/config | awk '{print $2}') | ||
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) | ||
return 0 | ||
} | ||
complete -F _nisshfs nisshfs |
This file contains 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