Home

Awesome

zsh-hist

Edit your Zsh history, without ever leaving the command line.

Installation

  1. git clone this repo.
  2. Add the following to your ~/.zshrc file:
    source path/to/zsh-hist.plugin.zsh
    

To update, cd into your clone and git pull.

Uniform code formatting

Whenever you finish your command line, zsh-hist will automatically format it for you, before it is saved to history. You can also retroactively format your history with hist n.

Notes on code formatting

Automatic alias expansion (Optional)

zsh-hist can automatically expand your aliases before each command line is saved to history. This is disabled by default, but to enable it, add the following to your .zshrc file:

zstyle ':hist:*' expand-aliases yes

Added <kbd>Undo</kbd> functionality

On any new command line, you can now press <kbd>Undo</kbd> to pop the last command from your history into the line editor, letting you correct any mistakes you made, before running it back. Afterwards, the old, faulty command will be gone from your history and only the new, corrected one remains.

Additionally, if you make a typo and end up on the secondary prompt, you can now press <kbd>Undo</kbd> to return to the primary prompt.

Push lines to history

When you press <kbd></kbd><kbd>Q</kbd>, your line is now written to history (without being executed) instead of to the buffer stack.

This has the following benefits:

Pressing <kbd></kbd><kbd>Q</kbd> on the secondary prompt will return you to the primary prompt.

hist command syntax

Usage
  hist [<option>...] compress <delta>
  hist [<option>...] {reload|undo}
  hist [<option>...] <command> <selection> ...

Return value
  $reply  an associative array of history index -> entry tuples

Options
  -f  force: never ask for confirmation
  -i  interactive: always ask for confirmation
  -q  quiet: do not print anything
  -s  silent: same as quiet
By default, hist asks for confirmation only when operating on multiple history
entries.

Commands (can be shortened to first letter):
  compress   delete each entry that differs <delta> chars or less from the next
  delete     remove from history
  edit       delete, then modify & append as new
  fix        delete + get
  get        load into buffer
  list       look, but do not touch
  normalize  delete, then auto-format & append as new
  reload     re-initialize local history from file
  undo       roll back to before last command in same session

Selections (for commands other than compress, reload or undo):
  negative int  offset from end of history
  positive int  index from beginning of history
  pattern       all matching entries

Examples
  hist f -1         # Fix last entry (cut from history; paste into command line)
  hist n {1..9}     # Normalize (uniformly format) a range of history items
  hist d $'*(\n|;)' # Delete all entries ending in newline or semicolon

Author

© 2020 Marlon Richert

License

This project is licensed under the MIT License. See the LICENSE file for details.