3

If in zsh, I type set and see precmd_functions=(_precmd_function_dostuff _precmd_function_domore).

Where are _precmd_function_dostuff and _precmd_function_domore defined (i.e. are they defined in a file? which file?)?

I can type functions to see the definitions of _precmd_function_dostuff and _precmd_function_domore, but this doesn't tell me where they are defined.

6
  • 1
    Does running PS4='+%x:%I> ' zsh -x 2> >(grep precmd_func) show any output? Commented Mar 20, 2018 at 17:03
  • Yes. I see +/usr/local/etc/zshrc.d/10-xterm:20> precmd_functions+= ( _precmd_function_dostuff) and +/usr/local/etc/zshrc.d/80-PetaLinux:18> precmd_fucntions +=( _precmd_function_domore ) Commented Mar 20, 2018 at 17:09
  • Does type _precmd_function_dostuff tell you where it's defined? Commented Mar 20, 2018 at 17:13
  • @StéphaneChazelas Do you know what the zshrc.d is used for? Also, do you know what the convention/meaning for the numbers in the filenames 10-xterm and 80-Petalinux? Commented Mar 20, 2018 at 17:14
  • 1
    Those sound files that are being provided by your distribution or some packaging system that you use. They are not part of zsh. How was zsh installed on that system? Given the names, it may also be that those files are installed as part of different packages (like 10-xterm from xterm...) Commented Mar 20, 2018 at 17:15

1 Answer 1

5

In zsh 5.3 or above,

type _precmd_function_domore

should return something like

_precmd_function_domore is a shell function from /usr/local/etc/zshrc.d/80-PetaLinux

With zsh 5.4 or above, you can also use:

echo $functions_source[_precmd_function_domore]

When you run zsh with the xtrace option (like with zsh -x), it writes debugging information on stderr that shows every command it runs (not function definitions though). You can modify the $PS4 variable (the prompt variable used for the xtrace output, see info zsh PS4) so it gives you more information like for each command that it runs, from which file and on each line the command was read from.

PS4='+%x:%I> ' zsh -x 2> >(grep precmd_func)

Would run a new zsh interactive shell instance, with stderr filtered by grep to show the lines that contain precmd_func.

Or with zsh, you can invoke that _precmd_function_domore function under xtrace and with %x:%I in $PS4 to see where the function definition was read from:

$ grep -n precmd ~/.zshrc
192:precmd_foo() echo foo
$ (PS4='+%x:%I> '; set -x; precmd_foo)
+zsh:2> precmd_foo
+/home/stephane/.zshrc:194> echo foo
foo

(note the off-by-two line number here though).

3
  • When I run type _precmd_function_domore I just got the response _precmd_function_domore is a shell function without the from part you mentioned. Commented Mar 20, 2018 at 17:43
  • I'm def a newbie. If you could explain what is PS4 variable, %x:%I and > > that would be helpful too. Thanks! Commented Mar 20, 2018 at 17:51
  • @user3731622, see edit. Commented Mar 20, 2018 at 20:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .