From 5999506f8719a7a29adca45397dba721d5b6768d Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Sat, 30 Apr 2022 09:07:46 -0500 Subject: [PATCH] allows for nushell to have tables without the index column (#5380) --- crates/nu-command/src/viewers/table.rs | 16 ++++++++++------ crates/nu-protocol/src/config.rs | 10 +++++++++- docs/sample_config/default_config.nu | 1 + 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/crates/nu-command/src/viewers/table.rs b/crates/nu-command/src/viewers/table.rs index 9a848f08c7..fbbf7eb944 100644 --- a/crates/nu-command/src/viewers/table.rs +++ b/crates/nu-command/src/viewers/table.rs @@ -304,9 +304,10 @@ fn convert_to_table( let mut input = input.iter().peekable(); let color_hm = get_color_config(config); let float_precision = config.float_precision as usize; + let disable_index = config.disable_table_indexes; if input.peek().is_some() { - if !headers.is_empty() { + if !headers.is_empty() && !disable_index { headers.insert(0, "#".into()); } @@ -323,16 +324,19 @@ fn convert_to_table( return Err(error.clone()); } // String1 = datatype, String2 = value as string - let mut row: Vec<(String, String)> = - vec![("string".to_string(), (row_num + row_offset).to_string())]; + let mut row: Vec<(String, String)> = vec![]; + if !disable_index { + row = vec![("string".to_string(), (row_num + row_offset).to_string())]; + } if headers.is_empty() { row.push(( item.get_type().to_string(), item.into_abbreviated_string(config), - )) + )); } else { - for header in headers.iter().skip(1) { + let skip_num = if !disable_index { 1 } else { 0 }; + for header in headers.iter().skip(skip_num) { let result = match item { Value::Record { .. } => { item.clone().follow_cell_path(&[PathMember::String { @@ -373,7 +377,7 @@ fn convert_to_table( x.into_iter() .enumerate() .map(|(col, y)| { - if col == 0 { + if col == 0 && !disable_index { StyledString { contents: y.1, style: TextStyle { diff --git a/crates/nu-protocol/src/config.rs b/crates/nu-protocol/src/config.rs index 98ad3d87be..8fcf9eedde 100644 --- a/crates/nu-protocol/src/config.rs +++ b/crates/nu-protocol/src/config.rs @@ -47,6 +47,7 @@ pub struct Config { pub menus: Vec, pub rm_always_trash: bool, pub shell_integration: bool, + pub disable_table_indexes: bool, } impl Default for Config { @@ -73,6 +74,7 @@ impl Default for Config { menus: Vec::new(), rm_always_trash: false, shell_integration: false, + disable_table_indexes: false, } } } @@ -254,7 +256,13 @@ impl Value { eprintln!("$config.shell_integration is not a bool") } } - + "disable_table_indexes" => { + if let Ok(b) = value.as_bool() { + config.disable_table_indexes = b; + } else { + eprintln!("$config.disable_table_indexes is not a bool") + } + } x => { eprintln!("$config.{} is an unknown config setting", x) } diff --git a/docs/sample_config/default_config.nu b/docs/sample_config/default_config.nu index 67a09c2a34..1a6a4463c9 100644 --- a/docs/sample_config/default_config.nu +++ b/docs/sample_config/default_config.nu @@ -196,6 +196,7 @@ let-env config = { max_history_size: 10000 # Session has to be reloaded for this to take effect sync_history_on_enter: true # Enable to share the history between multiple sessions, else you have to close the session to persist history to file shell_integration: true # enables terminal markers and a workaround to arrow keys stop working issue + disable_table_indexes: false # set to true to remove the index column from tables menus: [ # Configuration for default nushell menus # Note the lack of souce parameter