zsh-users
 help / color / mirror / code / Atom feed
* How to get 'fc' context?
@ 2015-03-14 23:44 Han Pingtian
  2015-03-15  1:38 ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Han Pingtian @ 2015-03-14 23:44 UTC (permalink / raw)
  To: zsh-user

Hi,

I'm reading the manual:

  fc     Code from the shell history executed by the -e
         option to the fc builtin.

But looks like I cannot get the 'fc' context when doing this:


localhost% print $zsh_eval_context
toplevel
localhost% fc -e -
print $zsh_eval_context
toplevel file
localhost%

How can we get the 'fc' context, please?

Thanks!


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

* Re: How to get 'fc' context?
  2015-03-14 23:44 How to get 'fc' context? Han Pingtian
@ 2015-03-15  1:38 ` Bart Schaefer
  2015-03-15 21:39   ` Han Pingtian
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2015-03-15  1:38 UTC (permalink / raw)
  To: zsh-user

On Mar 15,  7:44am, Han Pingtian wrote:
}
} How can we get the 'fc' context, please?

I don't think there is an "fc context" in the way you seem to mean.

"fc" either invokes an external editor, in which case the shell is
not involved at all, or it feeds the history directly back to the
interpreter again, in which case it's not doing anything that would
have a context.

The reason you get "toplevel file" is because "fc -e" has copied the
history event to a file and then invoked "source" on the file.

What exactly are you trying to accomplish with this?


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

* Re: How to get 'fc' context?
  2015-03-15  1:38 ` Bart Schaefer
@ 2015-03-15 21:39   ` Han Pingtian
  2015-03-16  0:30     ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Han Pingtian @ 2015-03-15 21:39 UTC (permalink / raw)
  To: zsh-users

On Sat, Mar 14, 2015 at 06:38:02PM -0700, Bart Schaefer wrote:
> On Mar 15,  7:44am, Han Pingtian wrote:
> }
> } How can we get the 'fc' context, please?
> 
> I don't think there is an "fc context" in the way you seem to mean.
> 
> "fc" either invokes an external editor, in which case the shell is
> not involved at all, or it feeds the history directly back to the
> interpreter again, in which case it's not doing anything that would
> have a context.
> 
> The reason you get "toplevel file" is because "fc -e" has copied the
> history event to a file and then invoked "source" on the file.
> 
> What exactly are you trying to accomplish with this?

I'd like to see if there is a method showing context 'fc' to me. I was reading
the manual about the zsh_eval_context, and thought I can do this by 
calling something like "fc -e -".  But it didn't do what I want.

Thanks.


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

* Re: How to get 'fc' context?
  2015-03-15 21:39   ` Han Pingtian
@ 2015-03-16  0:30     ` Bart Schaefer
  2015-03-16  4:11       ` Han Pingtian
  0 siblings, 1 reply; 6+ messages in thread
From: Bart Schaefer @ 2015-03-16  0:30 UTC (permalink / raw)
  To: zsh-users

On Mar 16,  5:39am, Han Pingtian wrote:
}
} I was reading the manual about the zsh_eval_context

Ah.  I see now.

The value of $zsh_eval_context is only "fc" while invoking the editor,
and with "fc -e -" there is no editor.

So if you did

% autoload zed
% fc -e zed

then while zed is running, $zsh_eval_context contains "fc", but the only
way you can examine it is with something like a ZLE widget.

Try for example:

% fc -e '() { print echo $zsh_eval_context } >|'
echo toplevel fc shfunc
toplevel fc shfunc
% 


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

* Re: How to get 'fc' context?
  2015-03-16  0:30     ` Bart Schaefer
@ 2015-03-16  4:11       ` Han Pingtian
  2015-03-16  6:26         ` Bart Schaefer
  0 siblings, 1 reply; 6+ messages in thread
From: Han Pingtian @ 2015-03-16  4:11 UTC (permalink / raw)
  To: zsh-users

On Sun, Mar 15, 2015 at 05:30:22PM -0700, Bart Schaefer wrote:
> Try for example:
> 
> % fc -e '() { print echo $zsh_eval_context } >|'
> echo toplevel fc shfunc
> toplevel fc shfunc
> % 
Thanks. But what does the '>|' mean here, please?


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

* Re: How to get 'fc' context?
  2015-03-16  4:11       ` Han Pingtian
@ 2015-03-16  6:26         ` Bart Schaefer
  0 siblings, 0 replies; 6+ messages in thread
From: Bart Schaefer @ 2015-03-16  6:26 UTC (permalink / raw)
  To: zsh-users

On Mar 16, 12:11pm, Han Pingtian wrote:
} Subject: Re: How to get 'fc' context?
}
} On Sun, Mar 15, 2015 at 05:30:22PM -0700, Bart Schaefer wrote:
} > Try for example:
} > 
} > % fc -e '() { print echo $zsh_eval_context } >|'
} > echo toplevel fc shfunc
} > toplevel fc shfunc
} > % 
} Thanks. But what does the '>|' mean here, please?

Sorry, this example might be clearer:

    fc -e '() { print echo $zsh_eval_context >| $1 }'

"fc -e" constructs the editor command by appending a temporary file name
to the argument string and then "eval"-ing it.  So ending the string
with ">|" means to clobber that file (in the no_clobber option sense).


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

end of thread, other threads:[~2015-03-16  6:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-14 23:44 How to get 'fc' context? Han Pingtian
2015-03-15  1:38 ` Bart Schaefer
2015-03-15 21:39   ` Han Pingtian
2015-03-16  0:30     ` Bart Schaefer
2015-03-16  4:11       ` Han Pingtian
2015-03-16  6:26         ` Bart Schaefer

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