I am using tramp mode in Emacs to edit files over ssh. But the problem is that on remote shell I have aliased ls as "ls --color". Tramp uses ls for auto completion and it is unable to parse color coded ls output.

The solution mentioned in https://www.gnu.org/software/tramp/#Frequently-Asked-Questions is to disable coloring of output from ls by removing the alias. I do not want to do it as it is a major feature for me.

Is there are way to redefine how tramp issues ls command so that I can keep my shell configuration and still use file name completion with tramp.

Edit 1: It seems that problem is something else. I tried changing alias to 'ls --color=auto' as suggested by @chepner and then to simply 'ls'. It still doesn't work. How can I further troubleshoot the problem?

  • "Renaming" a standard command via alias or function is pretty much always a bad idea. Why don't you just call your coloureful ls "lc" instead?
    – tink
    Mar 12, 2013 at 17:54
  • Did you try (setq tramp-debug-buffer t) (setq tramp-verbose 10)?
    – Old Pro
    May 19, 2013 at 19:13
  • @OldPro Here is the debug output: pastebin.com/PZuxs1St
    – Xolve
    May 20, 2013 at 19:53
  • 1
    Hard to make sense of that. You need to put the debug statements in your .emacs file so you can see how tramp configures itself when it loads. Probably tramp is making a bad guess. It might think /home/username is a host name and be trying to connect to that host?Or maybe it's unable to run perl scripts on the target? Just guessing. See if any of the configuration options ring a bell: gnu.org/software/tramp/#Customizing-Completion
    – Old Pro
    May 20, 2013 at 21:26

4 Answers 4


Redefine your alias to read

alias ls="ls --color=auto"

This way, ls only colorizes its output when it senses it is writing to the terminal. I'm not familiar with tramp, but this should be sufficient.

  • Your alias doesn't matter. Well-written scripts (like tramp) bypass aliases by using full path names, e.g. /bin/ls.
    – Old Pro
    May 19, 2013 at 19:40
  • BSD ls has an environment variables CLICOLOR and CLICOLOR_FORCE that can also affect how ls produces colored output. I'm not sure if GNU ls has anything similar (nothing in the man page, and seemingly nothing in the Texinfo manual).
    – chepner
    May 20, 2013 at 12:15

The other thing I would do, is look in my environment if there is anything that indicates you're in "tramp mode"

Say, do:

printenv | sort > ~/notramp.txt

then in emacs/tramp-mode:

printenv | sort > ~/withtramp.txt

Diff the two env files, and see what's different.

Then, in your ~/.bashrc, you can put

if [ -z "$TRAMPFLAG" ]
    alias ls='ls --color=auto'
  • I tried your method and it doesn't same to work. Looks like its some other issue.
    – Xolve
    Mar 14, 2013 at 9:22

Tramp send following Perl snippet to get file completions

\perl5 -e 'sub case {
 my $str = shift;
 if ($ARGV[2]) {
  return lc($str);
 else {
  return $str;
opendir(d, $ARGV[0]) || die("$ARGV[0]: $!\nfail\n");
@files = readdir(d); closedir(d);
foreach $f (@files) {
 if (case(substr($f, 0, length($ARGV[1]))) eq case($ARGV[1])) {
  if (-d "$ARGV[0]/$f") {
   print "$f/\n";
  else {
   print "$f\n";
print "ok\n"
' /home/ '' 0

perl5 was broken on remote host because of missing library. The solution was to manually fix the broken perl5. All this thanks to Michael Albinus.

  • 1
    Hey, I said maybe it was unable to run perl on the target, too. :-)
    – Old Pro
    May 24, 2013 at 23:52
  • Yeah right! I could have given you bounty if you provided it as an answer.
    – Xolve
    May 25, 2013 at 5:27

Tramp uses sophisticated techniques to be portable across a variety of systems, but it is not foolproof. Often to provide things like remote filename completion tramp will actually run modest perl scripts on the remote host. So check to make sure you have perl 5 installed, configured, and available on the remote host.

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.