vim-fern-ssh icon indicating copy to clipboard operation
vim-fern-ssh copied to clipboard

[bug] wrong cmd args

Open Freed-Wu opened this issue 3 years ago • 15 comments

❯ vi ssh://wzy@localhost:22//home/wzy/
[fern] ERROR: {'stderr': [''], 'args': ['ssh', '-T', '-x', 'wzy@localhost:22', 'cat /home/wzy/'], 'exitval': 143, 'stdout': ['']}
❯ ssh -T -x wzy@localhost:22 cat /home/wzy/
ssh: Could not resolve hostname localhost:22: Name or service not known
❯ ssh -T -x ssh://wzy@localhost:22 cat /home/wzy
cat: /home/wzy: Is a directory
❯ ssh -T -x ssh://wzy@localhost:22 ls /home/wzy/
Applications
Desktop
Documents
Downloads
...

Should add ssh:// prefix, and judge the file type (directory or normal file) then use ls or cat

index e126d13..6b52c24 100644
--- a/autoload/fern_ssh/connection.vim
+++ b/autoload/fern_ssh/connection.vim
@@ -11,7 +11,7 @@ endfunction
 
 function! s:connection_start(args, ...) abort dict
   let options = copy(a:0 ? a:1 : {})
-  let args = ['ssh', '-T', '-x', self.host, s:cmdline(a:args)]
+  let args = ['ssh', '-T', '-x', 'ssh://' . self.host, s:cmdline(a:args)]
   call fern#logger#debug(args)
   return s:Process.start(args, options)
 endfunction

it can fix the prefix bug, for ls and cat, I think a command like test -d $(realpath /home/wzy/Desktop/h) && ls /home/wzy/Desktop/h || cat /home/wzy/Desktop/h to judge filetype may be useful, but directory is different from normal file -- vi should get a files list containing by a directory, then use fern to handle it.

A weird behaviour is Fern /home/wzy/Desktop in vi can work normally -- use Fern to open the directory, Fern /home/wzy/LICENSE cannot work, fern will return a blank buffer only containing a line LICENSE/. Looks like fern think LICENSE is a directory not a normal file.

Freed-Wu avatar Mar 15 '22 15:03 Freed-Wu

Like this:

index 3008d53..a7dc4c6 100644
--- a/autoload/fern_ssh/buffer.vim
+++ b/autoload/fern_ssh/buffer.vim
@@ -22,7 +22,7 @@ function! s:BufReadCmd() abort
   let fri = fern#fri#parse(expand('<afile>'))
   let conn = fern_ssh#connection#new(fri.authority)
   let bufnr = expand('<abuf>') + 0
-  return conn.start(['cat', fri.path], {
+  return conn.start(split(printf('test -d $(realpath %s) && ls %s || cat %s', fri.path, fri.path, fri.path)), {
         \ 'reject_on_failure': v:true,
         \})
         \.then({ r -> r.stdout })
diff --git a/autoload/fern_ssh/connection.vim b/autoload/fern_ssh/connection.vim
index e126d13..6b52c24 100644
--- a/autoload/fern_ssh/connection.vim
+++ b/autoload/fern_ssh/connection.vim
@@ -11,7 +11,7 @@ endfunction
 
 function! s:connection_start(args, ...) abort dict
   let options = copy(a:0 ? a:1 : {})
-  let args = ['ssh', '-T', '-x', self.host, s:cmdline(a:args)]
+  let args = ['ssh', '-T', '-x', 'ssh://' . self.host, s:cmdline(a:args)]
   call fern#logger#debug(args)
   return s:Process.start(args, options)
 endfunction

However,

it is the result of vi ssh://wzy@localhost:22//home/wzy/Desktop/h:

Applications
Desktop
Documents
Downloads
...

it is the result of Fern ssh://wzy@localhost:22//home/wzy/Desktop/h:

h/
 Applications/
 bin/
 Desktop/
 Documents/
 Downloads/

Appearantly, the latter is better. How to make vi ssh://wzy@localhost:22//home/wzy/Desktop/h also get the latter result?

Freed-Wu avatar Mar 15 '22 15:03 Freed-Wu

A weird behaviour is Fern /home/wzy/Desktop in vi can work normally -- use Fern to open the directory, Fern /home/wzy/LICENSE cannot work, fern will return a blank buffer only containing a line LICENSE/. Looks like fern think LICENSE is a directory not a normal file.

I see. In vi, any file should be opened with :e ssh://wzy@localhost:22//home/wzy/LICENSE, and directory should be opened with :Fern ssh://wzy@localhost:22//home/wzy

Freed-Wu avatar Mar 15 '22 16:03 Freed-Wu

Now, how to let vi ssh://wzy@localhost:22//home/wzy/Desktop work like vi -c 'Fern ssh://wzy@localhost:22//home/wzy/Desktop'?

Freed-Wu avatar Mar 15 '22 16:03 Freed-Wu

Now, how to let vi ssh://wzy@localhost:22//home/wzy/Desktop work like vi -c 'Fern ssh://wzy@localhost:22//home/wzy/Desktop'?

Probabaly it's difficult. Something similar to fern-hijack.vim is required but I'm not sure if it works.

lambdalisue avatar Mar 16 '22 02:03 lambdalisue

So Can the prefix ssh:// be added? I think it can be meaningful.

Freed-Wu avatar Mar 16 '22 06:03 Freed-Wu

So Can the prefix ssh:// be added? I think it can be meaningful.

Added to...? I’m sorry, you lost me.

lambdalisue avatar Mar 19 '22 06:03 lambdalisue

Sorry for my expression. I means

index e126d13..6b52c24 100644
--- a/autoload/fern_ssh/connection.vim
+++ b/autoload/fern_ssh/connection.vim
@@ -11,7 +11,7 @@ endfunction
 
 function! s:connection_start(args, ...) abort dict
   let options = copy(a:0 ? a:1 : {})
-  let args = ['ssh', '-T', '-x', self.host, s:cmdline(a:args)]
+  let args = ['ssh', '-T', '-x', 'ssh://' . self.host, s:cmdline(a:args)]
   call fern#logger#debug(args)
   return s:Process.start(args, options)
 endfunction

can be added?

Freed-Wu avatar Mar 19 '22 09:03 Freed-Wu

I don't know why you'd like to add ssh:// on that. Does ssh command understand the protocol prefix????

lambdalisue avatar Mar 19 '22 13:03 lambdalisue

I could found that ssh command support ssh:// prefix on BSD

ssh connects and logs into the specified destination, which may be specified as either [user@]hostname or a URI of the form ssh://[user@]hostname[:port]. The user must prove their identity to the remote machine using one of several methods (see below).

https://man.openbsd.org/ssh

but Linux

ssh connects and logs into the specified hostname (with optional user name). The user must prove his/her identity to the remote machine using one of several methods depending on the protocol version used (see below).

https://linux.die.net/man/1/ssh https://manpages.ubuntu.com/manpages/bionic/en/man1/ssh.1.html

So the change is not acceptable I think.

lambdalisue avatar Mar 19 '22 13:03 lambdalisue

However, in linux, ssh -T -x wzy@localhost:22 will fail, only ssh -T -x ssh://wzy@localhost:22 is right. I don't know the result in BSD, but I want this plugin can work in all platforms. If BSD doesn't support ssh -T -x ssh://wzy@localhost:22 and only support ssh -T -x wzy@localhost:22, we should add a if-else to use different cmd args. If BSD support ssh -T -x ssh://wzy@localhost:22 too, I think use ssh -T -x ssh://wzy@localhost:22 will be better because it can cross platforms.

❯ vi ssh://wzy@localhost:22//home/wzy/
[fern] ERROR: {'stderr': [''], 'args': ['ssh', '-T', '-x', 'wzy@localhost:22', 'cat /home/wzy/'], 'exitval': 143, 'stdout': ['']}
❯ ssh -T -x wzy@localhost:22 cat /home/wzy/
ssh: Could not resolve hostname localhost:22: Name or service not known
❯ ssh -T -x ssh://wzy@localhost:22 cat /home/wzy
cat: /home/wzy: Is a directory
❯ ssh -T -x ssh://wzy@localhost:22 ls /home/wzy/
Applications
Desktop
Documents
Downloads
...

Freed-Wu avatar Mar 19 '22 13:03 Freed-Wu

Well, opposite. I couldn't find documentation that points ssh:// on LINUX but BSD. Do you have any official documentation that point ssh:// on Linux?

lambdalisue avatar Mar 19 '22 17:03 lambdalisue

However, in linux, ssh -T -x wzy@localhost:22 will fail

We may need to use -p and -l instead then.

lambdalisue avatar Mar 19 '22 17:03 lambdalisue

I found word 'BSD' in the man of openssh in my OS, I guess the support for ssh:// prefix is different in various ssh version, such as openssh and libressh, not related in various OS.:)

Freed-Wu avatar Mar 21 '22 05:03 Freed-Wu

I found word 'BSD' in the man of openssh in my OS, I guess the support for ssh:// prefix is different in various ssh version, such as openssh and libressh, not related in various OS.:)

Then I think we should not rely on ssh:// prefix right?

lambdalisue avatar Mar 21 '22 06:03 lambdalisue

I agree to use ssh -lwzy -p22 -T -x localhost ls to replace ssh -T -x ssh://wzy@localhost:22 :smile:

Freed-Wu avatar Mar 21 '22 06:03 Freed-Wu