Skip to content

Commit bf07806

Browse files
authored
Use cwd in grid (#12947)
# Description Fixes #12946. The `grid` command does not use the cwd when trying to get the icon or color for a file/path.
1 parent 0b5a4c0 commit bf07806

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

crates/nu-command/src/viewers/griddle.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use nu_engine::{command_prelude::*, env_to_string};
55
use nu_protocol::Config;
66
use nu_term_grid::grid::{Alignment, Cell, Direction, Filling, Grid, GridOptions};
77
use nu_utils::get_ls_colors;
8+
use std::path::Path;
89
use terminal_size::{Height, Width};
910

1011
#[derive(Clone)]
@@ -67,6 +68,7 @@ prints out the list properly."#
6768
};
6869
let use_grid_icons = config.use_grid_icons;
6970
let use_color: bool = color_param && config.use_ansi_coloring;
71+
let cwd = engine_state.cwd(Some(stack))?;
7072

7173
match input {
7274
PipelineData::Value(Value::List { vals, .. }, ..) => {
@@ -81,6 +83,7 @@ prints out the list properly."#
8183
separator_param,
8284
env_str,
8385
use_grid_icons,
86+
&cwd,
8487
)?)
8588
} else {
8689
Ok(PipelineData::empty())
@@ -98,6 +101,7 @@ prints out the list properly."#
98101
separator_param,
99102
env_str,
100103
use_grid_icons,
104+
&cwd,
101105
)?)
102106
} else {
103107
// dbg!(data);
@@ -120,6 +124,7 @@ prints out the list properly."#
120124
separator_param,
121125
env_str,
122126
use_grid_icons,
127+
&cwd,
123128
)?)
124129
}
125130
x => {
@@ -161,6 +166,7 @@ prints out the list properly."#
161166
}
162167
}
163168

169+
#[allow(clippy::too_many_arguments)]
164170
fn create_grid_output(
165171
items: Vec<(usize, String, String)>,
166172
call: &Call,
@@ -169,6 +175,7 @@ fn create_grid_output(
169175
separator_param: Option<String>,
170176
env_str: Option<String>,
171177
use_grid_icons: bool,
178+
cwd: &Path,
172179
) -> Result<PipelineData, ShellError> {
173180
let ls_colors = get_ls_colors(env_str);
174181

@@ -196,8 +203,8 @@ fn create_grid_output(
196203
if use_color {
197204
if use_grid_icons {
198205
let no_ansi = nu_utils::strip_ansi_unlikely(&value);
199-
let path = std::path::Path::new(no_ansi.as_ref());
200-
let icon = icon_for_file(path, call.head)?;
206+
let path = cwd.join(no_ansi.as_ref());
207+
let icon = icon_for_file(&path, call.head)?;
201208
let ls_colors_style = ls_colors.style_for_path(path);
202209

203210
let icon_style = match ls_colors_style {

0 commit comments

Comments
 (0)