Skip to content

Commit

Permalink
Use references instead of values
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkdp committed Jun 9, 2017
1 parent f7910c1 commit c8d4ec8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fd"
version = "1.0.0"
version = "1.1.0"
authors = ["David Peter <[email protected]>"]

[dependencies]
Expand Down
13 changes: 7 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ fn print_entry(base: &Path, entry: &Path, config: &FdOptions) {
let is_executable = |p: &std::path::PathBuf| {false};

if let Some(ref ls_colors) = config.ls_colors {
let default_style = ansi_term::Style::default();

let mut component_path = base.to_path_buf();

if config.path_display == PathDisplay::Absolute {
Expand All @@ -110,11 +112,11 @@ fn print_entry(base: &Path, entry: &Path, config: &FdOptions) {
if component_path.symlink_metadata()
.map(|md| md.file_type().is_symlink())
.unwrap_or(false) {
ls_colors.symlink
&ls_colors.symlink
} else if component_path.is_dir() {
ls_colors.directory
&ls_colors.directory
} else if is_executable(&component_path) {
ls_colors.executable
&ls_colors.executable
} else {
// Look up file name
let o_style =
Expand All @@ -123,14 +125,13 @@ fn print_entry(base: &Path, entry: &Path, config: &FdOptions) {
.and_then(|n| ls_colors.filenames.get(n));

match o_style {
Some(s) => *s,
Some(s) => s,
None =>
// Look up file extension
component_path.extension()
.and_then(|e| e.to_str())
.and_then(|e| ls_colors.extensions.get(e))
.cloned()
.unwrap_or_default()
.unwrap_or(&default_style)
}
};

Expand Down

0 comments on commit c8d4ec8

Please sign in to comment.