One big caveat here: In Zsh (and maybe other shells) you might have to explictly enable comments in interactive sessions:
setopt interactivecomments
One big caveat here: In Zsh (and maybe other shells) you might have to explictly enable comments in interactive sessions:
setopt interactivecomments
Nice tip, I will start doing it from now on. I recommend Atuin to keep and sync the shell history, although I don't like its default bindings.
Interesting, syncing history across machines is pretty cool. While writing this I went looking for my yabai logs helper as an example, but of course, it's on my other machine, haha
Security (sharing secrets from that history) comes to mind, so I feel compelled to mention that adding a space
before a command is a pattern for preventing it from being stored in history, though I think I had to opt-in to that in my zsh config: setopt HIST_IGNORE_SPACE
Oh, I didn't know that, thanks! Do you know any quick way to search and delete password contained commands in the history?
The simple and probably better answer is that you can just vim ~/.zsh_history
and search for/delete the lines directly.
Buuuuut! I wrote zsh command for doing exactly that a few years ago (in my dotfiles, but i've pasted it below as well):
################################################################################
# Delete from history via fzf
################################################################################
# https://superuser.com/questions/1316668/zsh-bash-delete-specific-lines-from-history
function delete-command () {
# Prevent the specified history line from being saved.
local HISTORY_IGNORE="${(b)$(fc -ln $1 $1)}"
# Write out the history to file, excluding lines that match `$HISTORY_IGNORE`.
fc -W
# Dispose of the current history and read the new history from file.
fc -p "$HISTFILE" "$HISTSIZE" "$SAVEHIST"
# TA-DA!
print "Deleted '$HISTORY_IGNORE' from history."
}
function pick_from_history () {
history | fzf --tac --tiebreak=index | perl -ne 'm/^\s*([0-9]+)/ and print "$1"'
}
function delete_from_history () {
delete-command "$(pick_from_history)"
}
It uses fzf
to filter and select a command to delete. It's cool but might be slow b/c you're doing it one at a time. It also may depend on your zsh config (i think the history
command i'm using there comes from ohmyzsh, but i'm not too sure).
I tried it, it's nice, thank you man! I'm on zsh, so I have to add history 0
in pick_from_history
tho. It would be nicer if it allows continuous deletion and not need to rerun every time. Btw, even when I delete it locally it wouldn't delete already synced history on Atuin, I guess I'll take a look at that later.
After further inspection, Atuin looks sweet! Looks like they encrypt your history and offer finer-grained search (like dates and things). Great rec, thanks for sharing!
Good idea.
Another tool in the same vein is tldr:
$ tldr tar
tar
Archiving utility.
Often combined with a compression method, such as gzip or bzip2.
More information: https://www.gnu.org/software/tar.
- [c]reate an archive and write it to a [f]ile:
tar cf path/to/target.tar path/to/file1 path/to/file2 ...
- [c]reate a g[z]ipped archive and write it to a [f]ile:
tar czf path/to/target.tar.gz path/to/file1 path/to/file2 ...
- [c]reate a g[z]ipped archive from a directory using relative paths:
tar czf path/to/target.tar.gz --directory=path/to/directory .
- E[x]tract a (compressed) archive [f]ile into the current directory [v]erbosely:
tar xvf path/to/source.tar[.gz|.bz2|.xz]
- E[x]tract a (compressed) archive [f]ile into the target directory:
tar xf path/to/source.tar[.gz|.bz2|.xz] --directory=path/to/directory
- [c]reate a compressed archive and write it to a [f]ile, using [a]rchive suffix to determine the compression program:
tar caf path/to/target.tar.xz path/to/file1 path/to/file2 ...
- Lis[t] the contents of a tar [f]ile [v]erbosely:
tar tvf path/to/source.tar
- E[x]tract files matching a pattern from an archive [f]ile:
tar xf path/to/source.tar --wildcards "*.html"
Yesssss tldr is awesome!
Great tip. This is simple enough to use on the daily.