4 ms·
I do something very similar, but without the prompt settings. I have settings in .bashrc[0] to have the history file based on date. I then use fzf[1] (fzf-tmux
by howeyc 10y ago
I do something very similar, but without the prompt settings. I have settings in .bashrc[0] to have the history file based on date. I then use fzf[1] (fzf-tmux is great) and a grep-like tool(sift[2]) to use for ctrl-r that fuzzy-searches history and orders by usage frequency[3]. This way I can easily search for the command I'm thinking of fairly quickly. Particularly useful for those times I want to run a command again that was quite long or had more than a couple options/flags.
---
[0] HISTFILE="${HOME}/Sync/Dotfiles/history/$(date -u +%Y-%m-%d.%H.%M.%S)_${HOSTNAME_SHORT}_$$"; export HISTFILE
[1] https://github.com/junegunn/fzf https://github.com/junegunn/fzf
[2] https://sift-tool.org/ https://sift-tool.org/
[3] __fzf_history__() {
sift --no-color -e "^[^#]" --files "_${HOSTNAME_SHORT}_" -N --no-filename $HOME/Sync/Dotfiles/history | sort | uniq -c | sort | $(__fzfcmd) +s --tac +m -n1..,.. --tiebreak=index --toggle-sort=ctrl-r | sed "s/ [0-9] *//"
}
- gingerlime 10y agoThanks for the awesome tips and simple recipe to tie things together. Had to tweak mine slightly though: ${HOSTNAME_SHORT} -> ${HOSTNAME} $HOME/Sync/Dotfiles/history -> $HOME/Sync/Dotfiles/history/* (maybe the missing star was due to HN formatting?)
- howeyc 10y agoYes, the stars are missing, but not where you think. The --files option has a star on the inside of each quote. This makes the search only show history for the host you are on (I sync my Dotfiles between machines). sift searches a path/folder so the star you have is not needed. But yeah, HOSTNAME_SHORT is something I derive from HOSTNAME.
- gingerlime 10y agoThanks for clarifying! Now I'm curious to hear more about how you sync your dotfiles ;-)
- howeyc 10y agoI sync my "$HOME/Sync" folder to pretty much every device I have. Android phone/tablet, Windows Laptop, FreeBSD Desktop, Linux VPS.... syncthing[0]/SyncTrazor[1] [0] https://syncthing.net/ https://syncthing.net/ [1] https://github.com/canton7/SyncTrayzor#installation https://github.com/canton7/SyncTrayzor#installation
- rawnlq 10y agoDropbox with a symlink also works fine though I have had it generate conflicts within .ssh folder which I also sync.
- biomcgary 10y agoFor those who want a well thought out solution, I have a co-worker that created a very useful history shell script with lots of integrated tools for search. Just source in your bash profile. https://github.com/autochthe/history https://github.com/autochthe/history
- nzjrs 10y agoI having trouble seeing what's going on here. Is the formatting ok? Maybe throw it in a gist?