{"id":719,"date":"2011-10-03T17:38:08","date_gmt":"2011-10-03T17:38:08","guid":{"rendered":"http:\/\/blog.designed79.co.uk\/?p=719"},"modified":"2011-10-03T17:38:08","modified_gmt":"2011-10-03T17:38:08","slug":"zsh-history","status":"publish","type":"post","link":"https:\/\/blog.designed79.co.uk\/?p=719","title":{"rendered":"ZSH history"},"content":{"rendered":"<p>In fact, the shell is able to read and write history without being told. You need to tell it where to save the history, however, and for that you have to set the parameter\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">$HISTFILE<\/div><\/div>\n<p>\u00a0to the name of the file you want to use (a common choice is `<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">~\/.history<\/div><\/div>\n<p>&#8216;). Next, you need to set the parameter\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">$SAVEHIST<\/div><\/div>\n<p>\u00a0to the number of lines of your history you want saved. When these two are set, the shell will read\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">$HISTSIZE<\/div><\/div>\n<p>\u00a0lines from\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">$HISTFILE<\/div><\/div>\n<p>\u00a0at the start of an interactive session, and save the last\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">$SAVEHIST<\/div><\/div>\n<p>\u00a0lines you executed at the end of the session. For it to read or write in the middle, you will either need to set one of the options described below (<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">INC_APPEND_HISTORY<\/div><\/div>\n<p>\u00a0and\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">SHARE_HISTORY<\/div><\/div>\n<p>), or use the\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">fc<\/div><\/div>\n<p>\u00a0command:\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">fc -R<\/div><\/div>\n<p>\u00a0and\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">fc -W<\/div><\/div>\n<p>read and write the history respectively, while\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">fc -A<\/div><\/div>\n<p>\u00a0appends it to the the file (although pruning it if it&#8217;s longer than\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">$SAVEHIST<\/div><\/div>\n<p>);\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">fc -WI<\/div><\/div>\n<p>\u00a0and\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">fc -AI<\/div><\/div>\n<p>\u00a0are similar, but the\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">I<\/div><\/div>\n<p>\u00a0means only write out events since the last time history was written.<\/p>\n<p>There is a third parameter\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">$HISTSIZE<\/div><\/div>\n<p>, which determines the number of lines the shell will keep within one session; except for special reasons which I won&#8217;t talk about, you should set<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">$SAVEHIST<\/div><\/div>\n<p>\u00a0to be no more than\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">$HISTSIZE<\/div><\/div>\n<p>, though it can be less. The default value for\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">$HISTSIZE<\/div><\/div>\n<p>\u00a0is 30, which is a bit stingy for the memory and disk space of today&#8217;s computers; zsh users often use anything up to 1000. So a simple set of parameters to set in\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">.zshrc<\/div><\/div>\n<p>\u00a0is<\/p>\n<pre>  HISTSIZE=1000\r\n  SAVEHIST=1000\r\n  HISTFILE=~\/.history<\/pre>\n<p>and that is enough to get things working. Note that you\u00a0<em>must<\/em>\u00a0set\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">$SAVEHIST<\/div><\/div>\n<p>\u00a0and\u00a0<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">$HISTFILE<\/div><\/div>\n<p>\u00a0for automatic reading and writing of history lines to work.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In fact, the shell is able to read and write history without being told. You need to tell it where to save [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-719","post","type-post","status-publish","format-standard","hentry","category-info-on-tech"],"_links":{"self":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/719","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=719"}],"version-history":[{"count":0,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/719\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=719"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=719"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=719"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}