forked from extern/nushell
add more columns to the history command when using sqlite history (#5817)
This commit is contained in:
parent
6cc8402127
commit
a17d46f200
4
Cargo.lock
generated
4
Cargo.lock
generated
@ -3825,13 +3825,13 @@ dependencies = [
|
|||||||
[[package]]
|
[[package]]
|
||||||
name = "reedline"
|
name = "reedline"
|
||||||
version = "0.7.0"
|
version = "0.7.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "git+https://github.com/nushell/reedline?branch=main#680bc7a162b3536dd2db7353b4714bf540f4ae62"
|
||||||
checksum = "3f8163ab90fabf0b8978b824743bb7a384394501b4b40c198a146c0eb9670ca4"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"crossterm",
|
"crossterm",
|
||||||
"fd-lock",
|
"fd-lock",
|
||||||
"gethostname",
|
"gethostname",
|
||||||
|
"itertools",
|
||||||
"nu-ansi-term",
|
"nu-ansi-term",
|
||||||
"rusqlite",
|
"rusqlite",
|
||||||
"serde",
|
"serde",
|
||||||
|
@ -119,3 +119,6 @@ debug = false
|
|||||||
[[bin]]
|
[[bin]]
|
||||||
name = "nu"
|
name = "nu"
|
||||||
path = "src/main.rs"
|
path = "src/main.rs"
|
||||||
|
|
||||||
|
[patch.crates-io]
|
||||||
|
reedline = { git = "https://github.com/nushell/reedline", branch = "main"}
|
||||||
|
@ -76,7 +76,8 @@ impl Command for History {
|
|||||||
.ok(),
|
.ok(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let data = history_reader
|
match engine_state.config.history_file_format {
|
||||||
|
HistoryFileFormat::PlainText => Ok(history_reader
|
||||||
.and_then(|h| {
|
.and_then(|h| {
|
||||||
h.search(SearchQuery::everything(SearchDirection::Forward))
|
h.search(SearchQuery::everything(SearchDirection::Forward))
|
||||||
.ok()
|
.ok()
|
||||||
@ -101,8 +102,102 @@ impl Command for History {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
.ok_or(ShellError::FileNotFound(head))?
|
.ok_or(ShellError::FileNotFound(head))?
|
||||||
.into_pipeline_data(ctrlc);
|
.into_pipeline_data(ctrlc)),
|
||||||
Ok(data)
|
HistoryFileFormat::Sqlite => Ok(history_reader
|
||||||
|
.and_then(|h| {
|
||||||
|
h.search(SearchQuery::everything(SearchDirection::Forward))
|
||||||
|
.ok()
|
||||||
|
})
|
||||||
|
.map(move |entries| {
|
||||||
|
entries
|
||||||
|
.into_iter()
|
||||||
|
.enumerate()
|
||||||
|
.map(move |(idx, entry)| Value::Record {
|
||||||
|
cols: vec![
|
||||||
|
"item_id".into(),
|
||||||
|
"start_timestamp".into(),
|
||||||
|
"command_line".to_string(),
|
||||||
|
"session_id".into(),
|
||||||
|
"hostname".into(),
|
||||||
|
"cwd".into(),
|
||||||
|
"duration".into(),
|
||||||
|
"exit_status".into(),
|
||||||
|
"index".to_string(),
|
||||||
|
],
|
||||||
|
vals: vec![
|
||||||
|
Value::Int {
|
||||||
|
val: match entry.id {
|
||||||
|
Some(id) => {
|
||||||
|
let ids = id.to_string();
|
||||||
|
match ids.parse::<i64>() {
|
||||||
|
Ok(i) => i,
|
||||||
|
_ => 0i64,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => 0i64,
|
||||||
|
},
|
||||||
|
span: head,
|
||||||
|
},
|
||||||
|
Value::String {
|
||||||
|
val: match entry.start_timestamp {
|
||||||
|
Some(time) => time.to_string(),
|
||||||
|
None => "".into(),
|
||||||
|
},
|
||||||
|
span: head,
|
||||||
|
},
|
||||||
|
Value::String {
|
||||||
|
val: entry.command_line,
|
||||||
|
span: head,
|
||||||
|
},
|
||||||
|
Value::Int {
|
||||||
|
val: match entry.session_id {
|
||||||
|
Some(sid) => {
|
||||||
|
let sids = sid.to_string();
|
||||||
|
match sids.parse::<i64>() {
|
||||||
|
Ok(i) => i,
|
||||||
|
_ => 0i64,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => 0i64,
|
||||||
|
},
|
||||||
|
span: head,
|
||||||
|
},
|
||||||
|
Value::String {
|
||||||
|
val: match entry.hostname {
|
||||||
|
Some(host) => host,
|
||||||
|
None => "".into(),
|
||||||
|
},
|
||||||
|
span: head,
|
||||||
|
},
|
||||||
|
Value::String {
|
||||||
|
val: match entry.cwd {
|
||||||
|
Some(cwd) => cwd,
|
||||||
|
None => "".into(),
|
||||||
|
},
|
||||||
|
span: head,
|
||||||
|
},
|
||||||
|
Value::Duration {
|
||||||
|
val: match entry.duration {
|
||||||
|
Some(d) => d.as_millis().try_into().unwrap_or(0),
|
||||||
|
None => 0,
|
||||||
|
},
|
||||||
|
span: head,
|
||||||
|
},
|
||||||
|
Value::Int {
|
||||||
|
val: entry.exit_status.unwrap_or(0),
|
||||||
|
span: head,
|
||||||
|
},
|
||||||
|
Value::Int {
|
||||||
|
val: idx as i64,
|
||||||
|
span: head,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
span: head,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
.ok_or(ShellError::FileNotFound(head))?
|
||||||
|
.into_pipeline_data(ctrlc)),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Err(ShellError::FileNotFound(head))
|
Err(ShellError::FileNotFound(head))
|
||||||
|
Loading…
Reference in New Issue
Block a user