zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: vared history not working inside scripts
Date: Sun, 13 Jan 2013 10:54:21 -0800	[thread overview]
Message-ID: <130113105421.ZM5620@torch.brasslantern.com> (raw)
In-Reply-To: <CACQNQ9NcJoXNHVePAKr9eW1HVtwN=4ZH9E__-yghPXXb_aWj_Q@mail.gmail.com>

On Jan 13,  7:55pm, rahul wrote:
} 
} On the command line, "vared -h" allows me to access history using arrow
} keys or Control-R.
} Inside a script, nothing happens. Is there some setting I have to make in
} scripts.

History is normally disabled in scripts.  On the "Expansion" summary page
in the documentation, under "History Expansion", it is noted that "This
is performed only in interactive shells."

To enable history in a script, you need to run the "fc -p" command to
initialize it.  If your script is going to be run as a shell function,
it's best to use "fc -a -p" to automatically restore the regular shell
history when the function exits.

fc -p [ -a ] [ FILENAME [ HISTSIZE [ SAVEHISTSIZE ] ] ]

     `fc -p' pushes the current history list onto a stack and switches
     to a new history list.  If the -a option is also specified, this
     history list will be automatically popped when the current
     function scope is exited, which is a much better solution than
     creating a trap function to call `fc -P' manually.  If no
     arguments are specified, the history list is left empty, $HISTFILE
     is unset, and $HISTSIZE & $SAVEHIST are set to their default
     values.  If one argument is given, $HISTFILE is set to that
     filename, $HISTSIZE & $SAVEHIST are left unchanged, and the history
     file is read in (if it exists) to initialize the new list.  If a
     second argument is specified, $HISTSIZE & $SAVEHIST are instead
     set to the single specified numeric value.  Finally, if a third
     argument is specified, $SAVEHIST is set to a separate value from
     $HISTSIZE.  You are free to change these environment values for
     the new history list however you desire in order to manipulate the
     new history list.

     `fc -P' pops the history list back to an older list saved by `fc
     -p'.  ...

There's an example of this in Functions/Misc/sticky-note in the sources
(usually found at ${^fpath}/sticky-note(N:[1]) after installation).


  reply	other threads:[~2013-01-13 18:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-13 14:25 rahul
2013-01-13 18:54 ` Bart Schaefer [this message]
2013-01-13 19:25   ` rahul
2013-01-14  9:37   ` Han Pingtian
2013-01-13 18:56 ` Peter Stephenson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=130113105421.ZM5620@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).