Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 20 Feb 2022 13:23:47 +0000
From:      =?UTF-8?Q?Xianwen_Chen_=28=E9=99=88=E8=B4=A4=E6=96=87=29?= <xchen@live.no>
To:        freebsd-questions@freebsd.org
Subject:   Automatic save of .history in .cshrc
Message-ID:  <AM6PR10MB232898EA2C4FADB276703EB4BB399@AM6PR10MB2328.EURPRD10.PROD.OUTLOOK.COM>

next in thread | raw e-mail | index | archive | help
--=_6e2d251f6a92335d8d027addcd4e1692
Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=US-ASCII;
 format=flowed



Hi!

I set the history to 8000:

   set history = 8000
   set savehist = (8000 merge)

I would like to move the first 4000 lines of .history to a directory. 
Let's call the directory ~/.history_archive.

The reason that I don't want to move all the contents of .history, is 
because I would like to have the recent history for auto completion.

I found out a csh script to partly do what I envisioned, from 
https://forums.freebsd.org/threads/csh-history-file.65582/:

   set HIST="~/.history"

   if (`wc --libxo text -l ${HIST} | cut -d '/' -f1` == 2000) then
         mv ${HIST} ${HIST}.old
         touch ${HIST} && chmod 600 ${HIST}
   endif

Would the following csh code be correct? Because csh only saves / 
appends to ~/.history when I log out, I use greater or equal to as the 
the condition. When there are 6000 lines or more, I split the .history 
files into two. The first one has 4000 lines, which will be moved to 
~/.history_archive, with a file name that contains time information. The 
other file is moved to be the current ~/.history.

   set HIST="~/.history"

   if (`wc --libxo text -l ${HIST} | cut -d '/' -f1` >= 6000) then

         split -l 4000 ${HIST}

         mv xaa ~/.history_archive/history-`date +"%Y-%m-%d-%H-%M" `

         mv xab ${HIST}

         chmod 600 ${HIST}
   endif

Cheers,

Xianwen
--=_6e2d251f6a92335d8d027addcd4e1692
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html; charset=UTF-8

<html><head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Dutf-8"></=
head><body style=3D"font-size: 10pt; font-family: Verdana,Geneva,sans-serif=
">
<p>Hi!</p>
<p>I set the history to 8000:</p>
<p>&nbsp; set history =3D 8000<br>&nbsp; set savehist =3D (8000 merge)</p>
<p>I would like to move the first 4000 lines of .history to a directory. Le=
t's call the directory ~/.history_archive.</p>
<p>The reason that I don't want to move all the contents of .history, is be=
cause I would like to have the recent history for auto completion.</p>
<p>I found out a csh script to partly do what I envisioned, from <a href=3D=
"https://forums.freebsd.org/threads/csh-history-file.65582/">https://forums=
.freebsd.org/threads/csh-history-file.65582/</a>:</p>
<p>&nbsp; set HIST=3D&quot;~/.history&quot;</p>
<p>&nbsp; if (`wc --libxo text -l ${HIST} | cut -d '/' -f1` =3D=3D 2000) th=
en<br>&nbsp; &nbsp; &nbsp; &nbsp; mv ${HIST} ${HIST}.old<br>&nbsp; &nbsp; &=
nbsp; &nbsp; touch ${HIST} &amp;&amp; chmod 600 ${HIST}<br>&nbsp; endif</p>
<p>Would the following csh code be correct? Because csh only saves / append=
s to ~/.history when I log out, I use greater or equal to as the the condit=
ion. When there are 6000 lines or more, I split the .history files into two=
. The first one has 4000 lines, which will be moved to ~/.history_archive, =
with a file name that contains time information. The other file is moved to=
 be the current ~/.history.</p>
<p>&nbsp; set HIST=3D&quot;~/.history&quot;</p>
<p>&nbsp; if (`wc --libxo text -l ${HIST} | cut -d '/' -f1` &gt;=3D 6000) t=
hen</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; split -l 4000 ${HIST}</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; mv xaa ~/.history_archive/history-`date +&qu=
ot;%Y-%m-%d-%H-%M&quot; `</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mv xab ${HIST}</p>
<p>&nbsp; &nbsp; &nbsp; &nbsp; chmod 600 ${HIST}<br>&nbsp; endif</p>
<p>Cheers,</p>
<p>Xianwen</p>

</body></html>

--=_6e2d251f6a92335d8d027addcd4e1692--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?AM6PR10MB232898EA2C4FADB276703EB4BB399>