3

When connected to an old remote system with Tramp 2.4.3.27.1, the buffer shows no files. With tramp-verbose set to 6, I looked at the Tramp debug buffer, then found (anonymized):

13:27:21.657267 tramp-send-command (6) # /bin/ls --color=never --dired -algGh /user/user/. 2>/dev/null

When I remove 2>/dev/null and execute the above command, I get:

/bin/ls: invalid option -- h
Try `/bin/ls --help' for more information.

ls on the remote system is part of GNU fileutils 3.16 and does not support the option -h. For my regular system I have configured dired+:

(dired-listing-switches "-algGh")

Is there any way to use a different configuration for that remote system?

What I tried, unsuccessfully:

(connection-local-set-profile-variables
  'example.com
  '((dired-listing-switches nil)))
(connection-local-set-profiles
 '(:application 'tramp :machine "example.com")
 'example.com)

How I connect to the old system

The system only supports connection by SSH v1. For that purpose, plink and pscp do support the option -1. So I added to tramp-connection-properties:

("/plink:user@example\\.com:" "login-args"
 (("-1")
  ("-l" "%u")
  ("%h")))))

Now I can connect to /plink:user@example.com:.

My solution

Thanks to Michael Albinus’ answer, I came up with:

(defun my-dired-before-readin-hook ()
  (let ((remote-host (file-remote-p default-directory 'host)))
    (when (string= remote-host "example.com")
      (setq dired-actual-switches "-algG"))))
(add-hook 'dired-before-readin-hook 'my-dired-before-readin-hook)
3

And not to forget the hint in the Tramp manual:

Emacs computes the ‘dired’ options based on the local host but if the remote host cannot understand the same ls command, then set them with a hook as follows:

(add-hook
 'dired-before-readin-hook
 (lambda ()
   (when (file-remote-p default-directory)
     (setq dired-actual-switches "-al"))))
1
  • I added detection of the correct host. Find the solution added to my question. – feklee Mar 24 at 5:35
2

Set tramp-verbose to 6, and rerun the test. There will be a Tramp debug buffer. Look for messages tagged with (6), they contain sent commands, and the responses. Perhaps you'll see what's going on.

5
  • Thanks! I updated my question. Have to dig around. Guess this is not a new problem. – feklee Mar 19 at 5:36
  • Tramp doesn't send ls ... -algGh .... I guess you have configured dired to do so. Check variable dired-listing-switches and alike. – Michael Albinus Mar 19 at 10:13
  • Right. I forgot about my own Emacs configuration tweaks from long ago. Now I wonder wether I should rephrase my question or close it. The new question is how to tell Dired+ to use a different ls command when connected to that machine. – feklee Mar 19 at 14:00
  • It's up to you how to continue. Likely, my answer would be "use connection-local variables", but I cannot say yet, because it would require testing for a recipe. And it would require to know which Emacs/Tramp version you use. – Michael Albinus Mar 19 at 19:04
  • I rephrased the question, and added the Tramp version number. Although using the keyword connection-local variables, I can probably figure it out myself, I think it would be nice if you add an answer here, so that we have a complete Q&A. – feklee Mar 21 at 4:12
1

Something like this works for me:

(defconst tramp-connection-local-default-dired-switches
  '((dired-listing-switches . "-al")
    (dired-actual-switches . "-al"))
  "Default connection-local dired switches.")

(connection-local-set-profile-variables
 'tramp-connection-local-default-dired-switches
 tramp-connection-local-default-dired-switches)

(defun tramp-dired-connection-local-variables-apply ()
  "Set `dired-listing-switches' in dired buffers."
  (when (file-remote-p default-directory)
    (let ((enable-connection-local-variables t))
      (hack-connection-local-variables-apply
       `(:application dired
         :protocol ,(file-remote-p default-directory 'method)
         :user     ,(file-remote-p default-directory 'user)
         :machine  ,(file-remote-p default-directory 'host))))))

(with-eval-after-load 'dired
  (tramp-compat-funcall
   'connection-local-set-profiles
   '(:application dired)
   'tramp-connection-local-default-dired-switches)

  (add-hook
    'dired-mode-hook
    #'tramp-dired-connection-local-variables-apply))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.