nushell

How do I delete specific history entries in Nushell?


Given a history like this in Nushell, how do I delete specific entries; e.g. entries 6, 8, and 10?

nu > history
╭────┬────────────────────╮
│  # │      command       │
├────┼────────────────────┤
│  0 │ history --clear    │
│  1 │ php --version      │
│  2 │ composer --version │
│  3 │ node --version     │
│  4 │ npm --version      │
│  5 │ composer --version │
│  6 │ history            │
│  7 │ php --version      │
│  8 │ history            │
│  9 │ php --version      │
│ 10 │ history            │
│ 11 │ composer --version │
╰────┴────────────────────╯

Solution

  • nu's history command does not (yet) provide a functionality to delete items similar to bash's history -d. However, you can query where the history file is located using $nu.history-path, then use drop nth to delete the lines in question.

    open $nu.history-path | lines | drop nth 6 8 10 | save -f $nu.history-path