├── .gitignore ├── tmp └── .gitignore ├── sshfs-open └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.out 2 | -------------------------------------------------------------------------------- /tmp/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | !.gitignore 3 | -------------------------------------------------------------------------------- /sshfs-open: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Remove slashes ("/") from tmp directory name 4 | ROOT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" 5 | DIR="$ROOT_DIR/tmp/${1//\//,}" 6 | 7 | if [[ ! -d "$DIR" ]]; then 8 | mkdir "$DIR" 9 | fi 10 | 11 | case "$1" in 12 | "" | "-h" | "--help") 13 | echo "Usage: sshfs-open [host:directory] [command]" 14 | exit 1 15 | ;; 16 | esac 17 | 18 | sshfs "$1" "$DIR" 19 | echo "Mounted $DIR" 20 | 21 | trap "fusermount -u '$DIR'" EXIT 22 | trap "rmdir '$DIR'" EXIT 23 | 24 | if [ "$2" != "" ]; then 25 | nohup "${@:2}" "$DIR" & 26 | fi 27 | 28 | echo "Press [CTRL+C] to exit" 29 | sleep infinity 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # sshfs-open 2 | 3 | A simple helper script to mount and unmount remote directories 4 | 5 | ### Setup: 6 | 1. Install [sshfs](https://github.com/libfuse/sshfs). 7 | 2. Run `git clone https://github.com/danielrw7/sshfs-open.git` 8 | 3. If you want to add `sshfs-open` to your PATH, add this to your bashrc: 9 | ``` 10 | export PATH=$PATH:/path/to/sshfs-open 11 | ``` 12 | 13 | ### Usage: 14 | 15 | ``` 16 | $ sshfs-open [host:directory] [command] 17 | ``` 18 | 19 | ### Example: 20 | 21 | ``` 22 | $ ./sshfs-open dev@server.com:/some/dir 23 | Mounted ./tmp/dev@server.com:,some,dir 24 | Press [CTRL+C] to exit 25 | ``` 26 | 27 | To run a command on the mounted directory, pass the commands and arguments after the remote directory: 28 | 29 | ``` 30 | # Open the mounted directory with atom 31 | $ ./sshfs-open dev@server.com:/some/dir atom 32 | Mounted ./tmp/dev@server.com:,some,dir 33 | Press [CTRL+C] to exit 34 | ``` 35 | 36 | Once you press CTRL+C, the mounted directory will be unmounted, and any child processes will be killed (if you passed a command). 37 | --------------------------------------------------------------------------------