Skip to content

Instantly share code, notes, and snippets.

@TheBunnyMan123
Last active July 1, 2024 06:40
Show Gist options
  • Save TheBunnyMan123/bddf298020e55fdfb32726c37af2129b to your computer and use it in GitHub Desktop.
Save TheBunnyMan123/bddf298020e55fdfb32726c37af2129b to your computer and use it in GitHub Desktop.
Script that automatically mounts an SFTP remote and prints the directory to STDOUT
#!/usr/bin/env bash
mkdir -p "$HOME/.remote-mount"
if mountpoint -q "$HOME/.remote-mount"
then
umount "$HOME/.remote-mount"
fi
if [ ! -z "$(ls -A "$HOME/.remote-mount")" ]
then
echo "Directory not empty and not an existing mount" 1>&2
exit 128
fi
if [ -z $1 ]
then
echo "Didn't specify a remote (first argument, port is second argument (and optional)" 1>&2
exit 128
fi
if [ ! -z $2 ]
then
sshfs "$1:/" "$HOME/.remote-mount" -p $2
else
sshfs "$1:/" "$HOME/.remote-mount"
fi
echo "running remote again will unmount the previous mount. to unmount run 'unmount ~/.remote-mount'" 1>&2
echo "$HOME/.remote-mount"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment