mirror of
https://github.com/jarun/nnn.git
synced 2024-11-28 05:41:31 +00:00
SSHFS refinements
This commit is contained in:
parent
92bbeb360d
commit
99b1b1f489
14
README.md
14
README.md
|
@ -375,7 +375,6 @@ The following indicators are used in the detail view:
|
||||||
| `NNN_COPIER='/absolute/path/to/copier'` | system clipboard copier script [default: none] |
|
| `NNN_COPIER='/absolute/path/to/copier'` | system clipboard copier script [default: none] |
|
||||||
| `NNN_NOTE=/home/user/Dropbox/notes` | path to note file [default: none] |
|
| `NNN_NOTE=/home/user/Dropbox/notes` | path to note file [default: none] |
|
||||||
| `NNN_TMPFILE=/tmp/nnn` | file to write current open dir path to for cd on quit |
|
| `NNN_TMPFILE=/tmp/nnn` | file to write current open dir path to for cd on quit |
|
||||||
| `NNN_SSHFS_MNT_ROOT=/home/user/.netmnt` | absolute path to SSHFS mount point root |
|
|
||||||
| `NNN_USE_EDITOR=1` | Open text files in `$EDITOR` (`$VISUAL`, if defined; fallback vi) |
|
| `NNN_USE_EDITOR=1` | Open text files in `$EDITOR` (`$VISUAL`, if defined; fallback vi) |
|
||||||
| `NNN_NO_AUTOSELECT=1` | do not auto-select matching dir in _nav-as-you-type_ mode |
|
| `NNN_NO_AUTOSELECT=1` | do not auto-select matching dir in _nav-as-you-type_ mode |
|
||||||
| `NNN_RESTRICT_NAV_OPEN=1` | open files on <kbd> ↵</kbd>, not <kbd>→</kbd> or <kbd>l</kbd> |
|
| `NNN_RESTRICT_NAV_OPEN=1` | open files on <kbd> ↵</kbd>, not <kbd>→</kbd> or <kbd>l</kbd> |
|
||||||
|
@ -385,10 +384,7 @@ The following indicators are used in the detail view:
|
||||||
|
|
||||||
#### SSHFS mounts
|
#### SSHFS mounts
|
||||||
|
|
||||||
To connect to and mount remote shares using SSHFS, `nnn` requires the following:
|
To connect to and mount remote shares using SSHFS, `nnn` requires the ssh configuration file `~/.ssh/config` to have the host entries. sshfs reads this file.
|
||||||
|
|
||||||
1. ssh configuration file `~/.ssh/config` should have the host entries. sshfs reads this file.
|
|
||||||
2. `$NNN_SSHFS_MNT_ROOT` should be set to the **absolute path** to the directory under which `nnn` creates the mount point for a host. The mount point is the same as the host name.
|
|
||||||
|
|
||||||
Example host entry for a Termux environment on Android device:
|
Example host entry for a Termux environment on Android device:
|
||||||
|
|
||||||
|
@ -399,14 +395,12 @@ Host phone
|
||||||
Port 8022
|
Port 8022
|
||||||
```
|
```
|
||||||
|
|
||||||
If `$NNN_SSHFS_MNT_ROOT` is set to `/home/user/remotes`, the above host `phone` will be mounted at `/home/user/remotes/phone`. `nnn` creates the directory `phone` if it doesn't exist.
|
The above host `phone` will be mounted at `~/.config/nnn/phone`. `nnn` creates the directory `phone` if it doesn't exist.
|
||||||
|
|
||||||
To unmount a mount point highlight it in `nnn` (so that it's the current entry) and press the relevant keybind to unmount. It might be a good idea to bookmark `$NNN_SSHFS_MNT_ROOT`.
|
|
||||||
|
|
||||||
Notes:
|
Notes:
|
||||||
|
|
||||||
1. `nnn` places you inside the mount point after a successful (un)mount so you can ensure the operation completed successfully indeed. To jump back to the last directory, press the usual <kbd>-</kbd>.
|
1. `nnn` takes you to the mount point after successful mounts. To jump back to the last directory, press the usual <kbd>-</kbd>.
|
||||||
2. `nnn` doesn't delete the mount point on unmount to prevent accidental data loss.
|
2. `nnn` doesn't delete the mount point on unmount to prevent accidental data loss. **Please ensure the mount point is not mounted if you are deleting it manually.**
|
||||||
3. More information on [SSHFS](https://wiki.archlinux.org/index.php/SSHFS).
|
3. More information on [SSHFS](https://wiki.archlinux.org/index.php/SSHFS).
|
||||||
|
|
||||||
#### Help
|
#### Help
|
||||||
|
|
5
nnn.1
5
nnn.1
|
@ -184,11 +184,6 @@ when dealing with the !, e and p commands respectively. A single combination to
|
||||||
export NNN_TMPFILE=/tmp/nnn
|
export NNN_TMPFILE=/tmp/nnn
|
||||||
.Ed
|
.Ed
|
||||||
.Pp
|
.Pp
|
||||||
\fBNNN_SSHFS_MNT_ROOT:\fR absolute path to SSHFS mount point root. Mount points are created at this location.
|
|
||||||
.Bd -literal
|
|
||||||
export NNN_SSHFS_MNT_ROOT=/home/user/.netmnt`
|
|
||||||
.Ed
|
|
||||||
.Pp
|
|
||||||
\fBNNN_USE_EDITOR:\fR use EDITOR (VISUAL takes preference, preferably CLI, fallback vi) to handle text
|
\fBNNN_USE_EDITOR:\fR use EDITOR (VISUAL takes preference, preferably CLI, fallback vi) to handle text
|
||||||
files.
|
files.
|
||||||
.Bd -literal
|
.Bd -literal
|
||||||
|
|
82
src/nnn.c
82
src/nnn.c
|
@ -283,7 +283,6 @@ static char *home;
|
||||||
static char *cfgdir;
|
static char *cfgdir;
|
||||||
static char *g_cppath;
|
static char *g_cppath;
|
||||||
static char *plugindir;
|
static char *plugindir;
|
||||||
static char *sshfsmnt;
|
|
||||||
static blkcnt_t ent_blocks;
|
static blkcnt_t ent_blocks;
|
||||||
static blkcnt_t dir_blocks;
|
static blkcnt_t dir_blocks;
|
||||||
static ulong num_files;
|
static ulong num_files;
|
||||||
|
@ -389,16 +388,15 @@ static const char * const messages[] = {
|
||||||
#define NNN_COPIER 4
|
#define NNN_COPIER 4
|
||||||
#define NNN_NOTE 5
|
#define NNN_NOTE 5
|
||||||
#define NNN_TMPFILE 6
|
#define NNN_TMPFILE 6
|
||||||
#define NNN_SSHFS_MNT_ROOT 7
|
#define NNNLVL 7 /* strings end here */
|
||||||
#define NNNLVL 8 /* strings end here */
|
#define NNN_USE_EDITOR 8 /* flags begin here */
|
||||||
#define NNN_USE_EDITOR 9 /* flags begin here */
|
#define NNN_NO_AUTOSELECT 9
|
||||||
#define NNN_NO_AUTOSELECT 10
|
#define NNN_RESTRICT_NAV_OPEN 10
|
||||||
#define NNN_RESTRICT_NAV_OPEN 11
|
#define NNN_RESTRICT_0B 11
|
||||||
#define NNN_RESTRICT_0B 12
|
#define NNN_OPENER_DETACH 12
|
||||||
#define NNN_OPENER_DETACH 13
|
#define NNN_TRASH 13
|
||||||
#define NNN_TRASH 14
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#define NNN_OPS_PROG 15
|
#define NNN_OPS_PROG 14
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const char * const env_cfg[] = {
|
static const char * const env_cfg[] = {
|
||||||
|
@ -409,7 +407,6 @@ static const char * const env_cfg[] = {
|
||||||
"NNN_COPIER",
|
"NNN_COPIER",
|
||||||
"NNN_NOTE",
|
"NNN_NOTE",
|
||||||
"NNN_TMPFILE",
|
"NNN_TMPFILE",
|
||||||
"NNN_SSHFS_MNT_ROOT",
|
|
||||||
"NNNLVL",
|
"NNNLVL",
|
||||||
"NNN_USE_EDITOR",
|
"NNN_USE_EDITOR",
|
||||||
"NNN_NO_AUTOSELECT",
|
"NNN_NO_AUTOSELECT",
|
||||||
|
@ -2407,34 +2404,35 @@ static bool execute_file(int cur, char *path, char *newpath, int *presel)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool create_dir(const char *path)
|
||||||
|
{
|
||||||
|
if (!xdiraccess(path)) {
|
||||||
|
if (errno != ENOENT)
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
if (mkdir(path, 0777) == -1)
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static bool sshfs_mount(char *path, char *newpath, int *presel)
|
static bool sshfs_mount(char *path, char *newpath, int *presel)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
||||||
if (!sshfsmnt) {
|
tmp = xreadline(NULL, "host: ");
|
||||||
printwait("set NNN_SSHFS_MNT_ROOT", presel);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
tmp = xreadline(NULL, "Host: ");
|
|
||||||
if (!tmp[0])
|
if (!tmp[0])
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* Create the mount point */
|
/* Create the mount point */
|
||||||
mkpath(sshfsmnt, tmp, newpath);
|
mkpath(cfgdir, tmp, newpath);
|
||||||
r = mkdir(newpath, 0777);
|
if (!create_dir(newpath)) {
|
||||||
if (r == -1 && errno != EEXIST) {
|
|
||||||
printwait(strerror(errno), presel);
|
printwait(strerror(errno), presel);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if directory can be accessed */
|
|
||||||
if (!xdiraccess(newpath)) {
|
|
||||||
*presel = MSGWAIT;
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!getutil("sshfs")) {
|
if (!getutil("sshfs")) {
|
||||||
printwait("sshfs missing", presel);
|
printwait("sshfs missing", presel);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -2454,19 +2452,22 @@ static bool sshfs_mount(char *path, char *newpath, int *presel)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool sshfs_unmount(char *path, char *fname, char *newpath, int *presel)
|
static bool sshfs_unmount(char *path, char *newpath, int *presel)
|
||||||
{
|
{
|
||||||
static char cmd[] = "fusermount3"; /* Arch Linux utility */
|
static char cmd[] = "fusermount3"; /* Arch Linux utility */
|
||||||
static bool found = FALSE;
|
static bool found = FALSE;
|
||||||
|
char *tmp;
|
||||||
|
|
||||||
/* On Ubuntu it's fusermount */
|
/* On Ubuntu it's fusermount */
|
||||||
if (!found && !getutil(cmd))
|
if (!found && !getutil(cmd))
|
||||||
cmd[10] = '\0';
|
cmd[10] = '\0';
|
||||||
|
|
||||||
if (!ndents)
|
tmp = xreadline(NULL, "host: ");
|
||||||
|
if (!tmp[0])
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
mkpath(path, dents[cur].name, newpath);
|
/* Create the mount point */
|
||||||
|
mkpath(cfgdir, tmp, newpath);
|
||||||
if (!xdiraccess(newpath)) {
|
if (!xdiraccess(newpath)) {
|
||||||
*presel = MSGWAIT;
|
*presel = MSGWAIT;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
@ -3981,10 +3982,6 @@ nochange:
|
||||||
goto begin;
|
goto begin;
|
||||||
case SEL_SSHFS:
|
case SEL_SSHFS:
|
||||||
if (!sshfs_mount(path, newpath, &presel))
|
if (!sshfs_mount(path, newpath, &presel))
|
||||||
goto nochange; // fallthrough
|
|
||||||
case SEL_UMOUNT:
|
|
||||||
if (sel == SEL_UMOUNT
|
|
||||||
&& !sshfs_unmount(path, dents[cur].name, newpath, &presel))
|
|
||||||
goto nochange;
|
goto nochange;
|
||||||
|
|
||||||
lastname[0] = '\0';
|
lastname[0] = '\0';
|
||||||
|
@ -3997,6 +3994,9 @@ nochange:
|
||||||
|
|
||||||
setdirwatch();
|
setdirwatch();
|
||||||
goto begin;
|
goto begin;
|
||||||
|
case SEL_UMOUNT:
|
||||||
|
sshfs_unmount(path, newpath, &presel);
|
||||||
|
goto nochange;
|
||||||
case SEL_QUITCD: // fallthrough
|
case SEL_QUITCD: // fallthrough
|
||||||
case SEL_QUIT:
|
case SEL_QUIT:
|
||||||
for (r = 0; r < CTX_MAX; ++r)
|
for (r = 0; r < CTX_MAX; ++r)
|
||||||
|
@ -4098,19 +4098,6 @@ static void usage(void)
|
||||||
"v%s\n%s\n", __func__, VERSION, GENERAL_INFO);
|
"v%s\n%s\n", __func__, VERSION, GENERAL_INFO);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool create_dir(const char *path)
|
|
||||||
{
|
|
||||||
if (!xdiraccess(path)) {
|
|
||||||
if (errno != ENOENT)
|
|
||||||
return FALSE;
|
|
||||||
|
|
||||||
if (mkdir(path, 0777) == -1)
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static bool setup_config(void)
|
static bool setup_config(void)
|
||||||
{
|
{
|
||||||
size_t r, len;
|
size_t r, len;
|
||||||
|
@ -4401,9 +4388,6 @@ int main(int argc, char *argv[])
|
||||||
if (!set_tmp_path())
|
if (!set_tmp_path())
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
/* Get SSHFS mountpoint */
|
|
||||||
sshfsmnt = getenv("NNN_SSHFS_MNT_ROOT");
|
|
||||||
|
|
||||||
/* Get the clipboard copier, if set */
|
/* Get the clipboard copier, if set */
|
||||||
copier = getenv(env_cfg[NNN_COPIER]);
|
copier = getenv(env_cfg[NNN_COPIER]);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue