mirror of
https://github.com/nushell/nushell
synced 2024-12-28 05:53:09 +00:00
Fix reading of LS_COLORS; ls display symlink (#357)
Also a swing-by fix removing a redundant call to std::fs::symlink_metadata().
This commit is contained in:
parent
250743f60f
commit
d30dfc63c4
2 changed files with 21 additions and 4 deletions
|
@ -57,18 +57,23 @@ impl Command for Ls {
|
||||||
|
|
||||||
let call_span = call.head;
|
let call_span = call.head;
|
||||||
let glob = glob::glob(&pattern).unwrap();
|
let glob = glob::glob(&pattern).unwrap();
|
||||||
let ls_colors = LsColors::from_env().unwrap_or_default();
|
let ls_colors = match stack.get_env_var("LS_COLORS") {
|
||||||
|
Some(s) => LsColors::from_string(&s),
|
||||||
|
None => LsColors::default(),
|
||||||
|
};
|
||||||
|
|
||||||
Ok(glob
|
Ok(glob
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(move |x| match x {
|
.map(move |x| match x {
|
||||||
Ok(path) => match std::fs::symlink_metadata(&path) {
|
Ok(path) => match std::fs::symlink_metadata(&path) {
|
||||||
Ok(metadata) => {
|
Ok(metadata) => {
|
||||||
|
let is_symlink = metadata.file_type().is_symlink();
|
||||||
let is_file = metadata.is_file();
|
let is_file = metadata.is_file();
|
||||||
let is_dir = metadata.is_dir();
|
let is_dir = metadata.is_dir();
|
||||||
let filesize = metadata.len();
|
let filesize = metadata.len();
|
||||||
let mut cols = vec!["name".into(), "type".into(), "size".into()];
|
let mut cols = vec!["name".into(), "type".into(), "size".into()];
|
||||||
let style = ls_colors.style_for_path(path.clone());
|
let style =
|
||||||
|
ls_colors.style_for_path_with_metadata(path.clone(), Some(&metadata));
|
||||||
let ansi_style = style.map(Style::to_crossterm_style).unwrap_or_default();
|
let ansi_style = style.map(Style::to_crossterm_style).unwrap_or_default();
|
||||||
let use_ls_colors = config.use_ls_colors;
|
let use_ls_colors = config.use_ls_colors;
|
||||||
|
|
||||||
|
@ -84,7 +89,9 @@ impl Command for Ls {
|
||||||
span: call_span,
|
span: call_span,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
if is_file {
|
if is_symlink {
|
||||||
|
Value::string("symlink", call_span)
|
||||||
|
} else if is_file {
|
||||||
Value::string("file", call_span)
|
Value::string("file", call_span)
|
||||||
} else if is_dir {
|
} else if is_dir {
|
||||||
Value::string("dir", call_span)
|
Value::string("dir", call_span)
|
||||||
|
|
|
@ -60,6 +60,8 @@ prints out the list properly."#
|
||||||
|
|
||||||
let config = stack.get_config()?;
|
let config = stack.get_config()?;
|
||||||
|
|
||||||
|
let env_str = stack.get_env_var("LS_COLORS");
|
||||||
|
|
||||||
match input {
|
match input {
|
||||||
PipelineData::Value(Value::List { vals, .. }) => {
|
PipelineData::Value(Value::List { vals, .. }) => {
|
||||||
// dbg!("value::list");
|
// dbg!("value::list");
|
||||||
|
@ -71,6 +73,7 @@ prints out the list properly."#
|
||||||
width_param,
|
width_param,
|
||||||
color_param,
|
color_param,
|
||||||
separator_param,
|
separator_param,
|
||||||
|
env_str,
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
Ok(PipelineData::new(call.head))
|
Ok(PipelineData::new(call.head))
|
||||||
|
@ -86,6 +89,7 @@ prints out the list properly."#
|
||||||
width_param,
|
width_param,
|
||||||
color_param,
|
color_param,
|
||||||
separator_param,
|
separator_param,
|
||||||
|
env_str,
|
||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
// dbg!(data);
|
// dbg!(data);
|
||||||
|
@ -106,6 +110,7 @@ prints out the list properly."#
|
||||||
width_param,
|
width_param,
|
||||||
color_param,
|
color_param,
|
||||||
separator_param,
|
separator_param,
|
||||||
|
env_str,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
x => {
|
x => {
|
||||||
|
@ -123,8 +128,13 @@ fn create_grid_output2(
|
||||||
width_param: Option<String>,
|
width_param: Option<String>,
|
||||||
color_param: bool,
|
color_param: bool,
|
||||||
separator_param: Option<String>,
|
separator_param: Option<String>,
|
||||||
|
env_str: Option<String>,
|
||||||
) -> PipelineData {
|
) -> PipelineData {
|
||||||
let ls_colors = LsColors::from_env().unwrap_or_default();
|
let ls_colors = match env_str {
|
||||||
|
Some(s) => LsColors::from_string(&s),
|
||||||
|
None => LsColors::default(),
|
||||||
|
};
|
||||||
|
|
||||||
let cols = if let Some(col) = width_param {
|
let cols = if let Some(col) = width_param {
|
||||||
col.parse::<u16>().unwrap_or(80)
|
col.parse::<u16>().unwrap_or(80)
|
||||||
} else if let Some((Width(w), Height(_h))) = terminal_size::terminal_size() {
|
} else if let Some((Width(w), Height(_h))) = terminal_size::terminal_size() {
|
||||||
|
|
Loading…
Reference in a new issue