1
0
mirror of https://github.com/jbranchaud/til synced 2026-01-03 07:08:01 +00:00

Add Use A Space To Exclude Command Fromm History as a Zsh TIL

This commit is contained in:
jbranchaud
2024-10-21 11:21:21 -05:00
parent d7d331b688
commit 43ea7acd74
2 changed files with 39 additions and 1 deletions

View File

@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
_1478 TILs and counting..._
_1479 TILs and counting..._
---
@@ -1758,6 +1758,7 @@ _1478 TILs and counting..._
- [Add To The Path Via Path Array](zsh/add-to-the-path-via-path-array.md)
- [Link A Scalar To An Array](zsh/link-a-scalar-to-an-array.md)
- [Use A Space To Exclude Command From History](zsh/use-a-space-to-exclude-command-from-history.md)
## Usage

View File

@@ -0,0 +1,37 @@
# Use A Space To Exclude Command From History
When using a shell like `zsh`, you get the benefit of it keeping track of the
history of the commands you've entered into the shell. This means you can
quickly traverse pack to a previous command that you want to run again. It also
means [a tool like `fzf` can hook into your history
file](https://github.com/junegunn/fzf?tab=readme-ov-file#key-bindings-for-command-line)
so that you can fuzzy-search for a command you may have executed weeks ago.
The history is stored on your machine in a plaintext file. Not every command
should be stored in a plaintext file. For instance, you don't want `zsh` to
persist a command that includes a password.
With the `histignorespace` option enabled in `zsh`, we can put a leading space
in front of our command and it will be excluded from the history file.
Try it yourself:
```bash
$ echo 'this command will be remembered'
this command will be remembered
$ echo 'this command will be forgotten'
this command will be forgotten
```
Notice the leading space in the second command. Trying pressing your _up_ arrow
and notice only that first `echo` is remembered.
Make sure `histignorespace` is included in the list when you run `setopt`. If
it isn't, then add it:
```bash
$ setopt histignorespace
```
[source](https://stackoverflow.com/questions/8473121/execute-a-command-without-keeping-it-in-history/49643320#49643320)