One of my favorite command line tips: you can add 'comments' full of keywords to shell commands, which makes searching your command history easier.
> obscure-cmd --with-weird-flags -Qdt # searchable comment keywords
Presumably you're using something like fzf for history search, but this is still useful without it.
This is especially useful for cli tools with obscure names/flags, or when you can't remember where a particular log file is.
Some examples from my history:
tail awesomewm logs:
tail -f ~/.cache/awesome/logs -n 2000 # tail follow log awesomewm
fix linux clock drift:
sudo ntpd -qg && sudo hwclock --systohc # fix linux clock time drift
copy ngrok public url to clipboard:
curl -s http://localhost:4040/api/tunnels | jq ".tunnels[0].public_url" | tr -d '"' | tr -d '\n' | xclip -selection clipboard -i # fetch ngrok url uri, copy to clipboard
sign ssh and gpg, then refresh the emacs keychain env:
keychain --agents gpg,ssh --eval id_rsa <some-gpg-id> && emacsclient -e '(keychain-refresh-environment)' # sign ssh,gpg password, refresh emacs env
Another gpg one:
git config commit.gpgsign false # disable gpg signing for this repo
Pacman/pamac commands, like listing orphaned packages:
pacman -Qdt # list orphans
pamac list -o # list orphans
xprop - super useful for debugging window management, for some reason i can never remember what it's called:
xprop # mouse click window x11 linux describe info client helper whateveritscalled
Some helpers from my clawe project:
bb --config ~/russmatney/clawe/bb.edn -x clawe.sxhkd.bindings/reset-bindings # reset sxhkd bindings
bb --config ~/russmatney/clawe/bb.edn -x clawe.restart/reload # reload clawe
Aliases come to mind as well - in some cases that might be a better fit. I like this because it's so low-lift.
13 Comments
gamma@programming.dev · 6 pts · 3y
One big caveat here: In Zsh (and maybe other shells) you might have to explictly enable comments in interactive sessions:
howarddo@programming.dev · 5 pts · 3y
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.
russmatney@programming.dev · 4 pts · 3y
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_SPACEhowarddo@programming.dev · 2 pts · 3y
Oh, I didn't know that, thanks! Do you know any quick way to search and delete password contained commands in the history?
russmatney@programming.dev · 2 pts · 3y
The simple and probably better answer is that you can just
vim ~/.zsh_historyand 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):
It uses
fzfto 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 thehistorycommand i'm using there comes from ohmyzsh, but i'm not too sure).howarddo@programming.dev · 2 pts · 3y
I tried it, it's nice, thank you man! I'm on zsh, so I have to add
history 0inpick_from_historytho. 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.russmatney@programming.dev · 2 pts · 3y
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!
tatterdemalion@programming.dev · 4 pts · 3y
Good idea.
Another tool in the same vein is tldr:
verstra@programming.dev · 3 pts · 3y
tealdear is my recommendation
russmatney@programming.dev · 1 pts · 3y
Nice. Classic rust reimplementation.
russmatney@programming.dev · 2 pts · 3y
Yesssss tldr is awesome!
attn_dfct_dev@programming.dev · 4 pts · 3y
Great tip. This is simple enough to use on the daily.