开发者

bash: history favourites file

i have a .bash_favourites file which containes a list of my favourite commands.

I would like this be searchable via the normal bash history. ???

thanks

开发者_StackOverflow

Ian


cat ~/.bash_favourites >> ~/.bash_history
history -r

If you want to make this permanent, you can probably just add these lines to ~/.bash_profile.


If you want to replace the regular history with your favorites: Do chmod u-w on .bash_history and edit it as you like. Bash should read it as usual but not add new commands.


You may want to try https://github.com/dvorka/hstr which allows bookmarking of your favorite commands (on top of Bash history) and searching - check my favorites filtered with e:

bash: history favourites file

Alternatively you can use trailing comments in commands you are entering i.e. # to bookmark them and search e.g.

$ find -name kernel -type d # favorite

and then search for favorite using Ctrl-r in Bash.


I wanted a similar setup though I approached it differently exert from my project could be edited to force loading of your favorites first or optionally dynamically loaded with the bastory function

if [ "$today" = "$yesterday" ]; then
    cat ~/.bash_favourites > ~/.bash_history
    head --lines=-1  $bashHistory >> $HISTFILE
else
    touch $HOME/.bash/archive/$(date +%F --date="6 hours ago" ).bash_history
    cat ~/.bash_favourites > ~/.bash_history
    cat $HOME/.bash/archive/$(date +%F  --date="6 hours ago" ).bash_history >> $HISTFILE
    head --lines=-1  $bashHistory >> $HISTFILE
fi

AS this is a old thread I will expand on this and incorporate it into my bashory project please refer comments on my answer to https://codereview.stackexchange.com/questions/32575/project-bashory-bash-history

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜