Skip to content

Instantly share code, notes, and snippets.

@AdamGagorik
Created October 3, 2025 16:43
Show Gist options
  • Save AdamGagorik/3ba2f025525a692570b652b510f885a4 to your computer and use it in GitHub Desktop.
Save AdamGagorik/3ba2f025525a692570b652b510f885a4 to your computer and use it in GitHub Desktop.
Mount a remote directory locally temporarily for editing in local IDE
#!/usr/bin/env bash
set -euo pipefail
SOURCE="$(dirname "${BASH_SOURCE[0]}")"
declare -a R_PATHS=(
"$1:$2"
)
declare -a L_PATHS=(
"${SOURCE}/mounts/$3"
)
do_mount() {
local l_path
local r_path
l_path="${1}"
r_path="${2}"
if [[ ! -d "${l_path}" ]]; then
mkdir -p "${l_path}"
fi
sshfs -o sshfs_debug "${r_path}" "${l_path}"
}
do_unmount() {
local l_path
l_path="${1}"
fusermount -u "${l_path}"
rmdir "${l_path}"
}
loop_do_mount() {
local i
for i in "${!R_PATHS[@]}"; do
do_mount "${L_PATHS[i]}" "${R_PATHS[i]}"
done
}
loop_do_unmount() {
local i
for i in "${!R_PATHS[@]}"; do
do_unmount "${L_PATHS[i]}"
done
}
trap loop_do_unmount EXIT
loop_do_mount
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment