zsh-users
 help / color / mirror / code / Atom feed
* vared history not working inside scripts
@ 2013-01-13 14:25 rahul
  2013-01-13 18:54 ` Bart Schaefer
  2013-01-13 18:56 ` Peter Stephenson
  0 siblings, 2 replies; 5+ messages in thread
From: rahul @ 2013-01-13 14:25 UTC (permalink / raw)
  To: zsh-users

[-- Attachment #1: Type: text/plain, Size: 1376 bytes --]

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. Here is an example:

    #!/usr/bin/env zsh

    export HISTFILE=~/.zhistory

    print "HIST: " $HISTFILE

    bindkey "^R" history-incremental-search-backward

    bindkey "^[[5~" up-line-or-history

    bindkey "^[[6~" down-line-or-history

    bindkey "^[[A" up-line-or-history

    bindkey "^[[B" down-line-or-history

    bindkey "^[OA"  up-line-or-history
    foo="default text"

    vared -h -p "Enter :" foo

(I have tried putting commands prior to the vared so some history is built
up in the program, or putting two vared calls, but in no case is history
called or available. ) After putting the key bindings into the script,
control-R prompts for backward search but there's only one item in history
which is the value of foo. That is perhaps why the up arrow does nothing.

How can i get some history for the user to choose from ?    I'd of course
prefer that if the user selected this option several times during the
running of the program, that i could build up the history for this variable
-- but most importantly I'd like to know what I am missing here due to
which I get no history.

 (I use OSX ML, latest zsh from homebrew 5.0.2 and zprezto).

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: vared history not working inside scripts
  2013-01-13 14:25 vared history not working inside scripts rahul
@ 2013-01-13 18:54 ` Bart Schaefer
  2013-01-13 19:25   ` rahul
  2013-01-14  9:37   ` Han Pingtian
  2013-01-13 18:56 ` Peter Stephenson
  1 sibling, 2 replies; 5+ messages in thread
From: Bart Schaefer @ 2013-01-13 18:54 UTC (permalink / raw)
  To: zsh-users

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).


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: vared history not working inside scripts
  2013-01-13 14:25 vared history not working inside scripts rahul
  2013-01-13 18:54 ` Bart Schaefer
@ 2013-01-13 18:56 ` Peter Stephenson
  1 sibling, 0 replies; 5+ messages in thread
From: Peter Stephenson @ 2013-01-13 18:56 UTC (permalink / raw)
  To: zsh-users

On Sun, 13 Jan 2013 19:55:43 +0530
rahul <rahul2012@gmail.com> 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.

I think you'll need to use interactive mode to get history to work.  Use
"zsh -i".  That'll stop you using "env" to find the shell, however ---
you can't change the option when the shell is running.

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: vared history not working inside scripts
  2013-01-13 18:54 ` Bart Schaefer
@ 2013-01-13 19:25   ` rahul
  2013-01-14  9:37   ` Han Pingtian
  1 sibling, 0 replies; 5+ messages in thread
From: rahul @ 2013-01-13 19:25 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

[-- Attachment #1: Type: text/plain, Size: 308 bytes --]

On Mon, Jan 14, 2013 at 12:24 AM, Bart Schaefer
<schaefer@brasslantern.com>wrote:

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


Thanks a lot. I am going through sticky-note. Great learning for me, also.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: vared history not working inside scripts
  2013-01-13 18:54 ` Bart Schaefer
  2013-01-13 19:25   ` rahul
@ 2013-01-14  9:37   ` Han Pingtian
  1 sibling, 0 replies; 5+ messages in thread
From: Han Pingtian @ 2013-01-14  9:37 UTC (permalink / raw)
  To: zsh-users

On Sun, Jan 13, 2013 at 10:54:21AM -0800, Bart Schaefer wrote:
> There's an example of this in Functions/Misc/sticky-note in the sources
> (usually found at ${^fpath}/sticky-note(N:[1]) after installation).
Looks like the ':' here is unnecessary, right?

Thanks.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-01-14  9:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-13 14:25 vared history not working inside scripts rahul
2013-01-13 18:54 ` Bart Schaefer
2013-01-13 19:25   ` rahul
2013-01-14  9:37   ` Han Pingtian
2013-01-13 18:56 ` Peter Stephenson

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).