Skip to content

Commit

Permalink
Change the default output of --files to elide './'.
Browse files Browse the repository at this point in the history
This is kind of a ticky-tack change. I do think ./ as a prefix is
reasonable default, *but* we strip ./ when showing search results, so it
does make sense to be consistent.

Fixes #21.
  • Loading branch information
BurntSushi committed Sep 24, 2016
1 parent af4dc78 commit 7b860af
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use regex::bytes::Regex;
use term::{Attr, Terminal};
use term::color;

use pathutil::strip_prefix;
use types::FileTypeDef;

/// Printer encapsulates all output logic for searching.
Expand Down Expand Up @@ -138,7 +139,8 @@ impl<W: Terminal + Send> Printer<W> {

/// Prints the given path.
pub fn path<P: AsRef<Path>>(&mut self, path: P) {
self.write(path.as_ref().to_string_lossy().as_bytes());
let path = strip_prefix("./", path.as_ref()).unwrap_or(path.as_ref());
self.write(path.to_string_lossy().as_bytes());
self.write_eol();
}

Expand Down
6 changes: 2 additions & 4 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,11 +703,9 @@ fn files() {
cmd.arg("--files");
let lines: String = wd.stdout(&mut cmd);
if cfg!(windows) {
assert!(lines == "./dir\\file\n./file\n"
|| lines == "./file\n./dir\\file\n");
assert!(lines == "dir\\file\nfile\n" || lines == "file\ndir\\file\n");
} else {
assert!(lines == "./file\n./dir/file\n"
|| lines == "./dir/file\n./file\n");
assert!(lines == "file\ndir/file\n" || lines == "dir/file\nfile\n");
}
}

Expand Down

0 comments on commit 7b860af

Please sign in to comment.