Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is there a way to get the SVN controlled folders list with different colors in the terminal? Like an alias for "ls". So when we type "ls", all the folders with an ".svn" sub-folder should be yellow for example?

Thanks. (Sorry if that is a stupid question.)

share|improve this question

migrated from Jul 4 '12 at 13:51

This question came from our site for professional and enthusiast programmers.

this link seem like what you wanted. – Jasonw Apr 13 '12 at 2:12
@Jasonw: Not quite. That link talks about the .svn directory only, not which are part of a SVN repo. – Ignacio Vazquez-Abrams Apr 13 '12 at 3:07
This is duplicate question. Please have a look this link.… – Sergey Beduev Apr 14 '12 at 19:11
Thanks. Sorry for the duplicate. – symbolix Apr 18 '12 at 13:43

You'd need a wrapper around ls to do this.

I wrote such a wrapper below...

How it basically works:

  • ls -F is forced because directories are then guaranteed to have a / suffix that can be detected.
  • To resolve a directory's name to its location, either the current directory is used or the first non-dash argument (presumed to be a target directory).
  • The foreground/background colors are achieved using the first number sets of each line. The XTerm-style numbers are triplets, so the 3rd and 6th numbers are the colors (19 and 85 in my example). The colors can of course be changed to anything you want.
  • This relies on original versions of svn where .svn was present in every subdirectory. If you're using the latest version where .svn is only present at the top, the script should change to "drill upward" from a "$root/$dir" until it finds a parent directory containing .svn.

Here is my entire script (use instead of ls directly):

#!/usr/bin/env perl
# by Kevin Grant (
use FileHandle;
my $term = (exists $ENV{'TERM'} && defined $ENV{'TERM'}) ? $ENV{'TERM'} : 'vt100';
my $is_xterm = ($term =~ /xterm/);
my $ifh = new FileHandle("ls -F @ARGV|");
(defined $ifh) or die;
my $root = '.';
foreach (@ARGV) {
  (! /^\-/) and $root = $_; # assume bare argument is the directory being listed
foreach (<$ifh>) {
  # 1st is for "ls -l" output (no spaces supported), 2nd is normal "ls" output
  if (m|\s(\S+)/| or m|^([^/]+/)|) {
    my $dir = $1;
    if (-e "$root/$dir/.svn") {
      # has a ".svn" subdirectory; colorize it
      if ($is_xterm) {
      } else {
share|improve this answer

You must log in to answer this question.