I display the history number as part of my prompt, e.g.,

{!1123}(j:~)$ ls /some/long/and/hard/to/type/path

so that I can do it later with !1123. My HISTSIZE and HISTFILESIZE are both 200, but this doesn't prevent the history number (\! in the prompt) from hitting quadruple digits because I use tmux. I want my prompt and history commands to be shorter. Is there a way to have the history wrap, such that when I hit some number the history number of the next command is set to 1, and only overwrite old commands as I reuse their history numbers? Example:

{!1}(j:~)$ ls /first/path
{!498}(j:~)$ ls /some/path
{!499}(j:~)$ ls /some/other/path
#at some target number, history number resets
{!1}(j:~)$ ls /new/path
#but remembers the old commands til they're overwritten
{!2}(j:~)$ !498
ls /some/path
#and keeps incrementing and overwriting the oldest commands
{!3}(j:~)$ !1
ls /new/path

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.