Skip to content

Commit

Permalink
Allows editing remote files with local nvim via sshfs mount.
Browse files Browse the repository at this point in the history
  • Loading branch information
TechDufus committed Nov 16, 2023
1 parent c8a5f1e commit a5e408b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
29 changes: 29 additions & 0 deletions roles/bash/files/bash/neovim_functions.sh
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
3 changes: 0 additions & 3 deletions roles/neovim/files/lua/techdufus/plugins/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ return {
{
"sbdchd/neoformat",
},
{
"tjdevries/sPoNGe-BoB.NvIm",
},
{
'akinsho/bufferline.nvim',
version = "*",
Expand Down

0 comments on commit a5e408b

Please sign in to comment.