I have set the ls program dired uses via
(setq insert-directory-program "gls"))
(so that I can specify --group-directories-first in dired-listing-switches).
Trouble is when I browse a remote directory, TRAMP seems to use the same variable insert-directory-program, but on arbitrary remote machines the gls command might not be available.
How can I set the ls program dired uses to gls only for local directories?