3

I am used to using "which stuff" do find the file that will be called when I use "stuff". I was quite surprised to see "which prompt" respond with

prompt () {
        local prompt_opts
        set_prompt "$@"
        (( $#prompt_opts )) && setopt noprompt{bang,cr,percent,subst} "prompt${^prompt_opts[@]}"
        true
}

on my Archlinux system. Where does this come from, and how do I make the prompt command avaliable inside the chroot environment I am currently building? (I just copied the other commands into it... that does not work here =) )

Edit: I am using zsh as my shell, maybe that changes something.

Jens
  • 239
  • 1
  • 9

2 Answers2

3

The command you're getting when you ran which is a a function, called prompt. The output is its definition.

You can see it using this command too:

$ declare -f prompt

Where's the prompt() function?

This is a bit trickier. You'll have to resort to using a tool such as grep to find the string "prompt ()". The usual places to look are as follows:

bash

(N.B. Don't use which in bash, use type instead)

$ grep -R "prompt ()" .bashrc .bash_profile /etc/bashrc /etc/profile*

zsh

$ grep -R "prompt ()" <files>

From the man page, these are the files that zsh makes use of:

   $ZDOTDIR/.zshenv
   $ZDOTDIR/.zprofile
   $ZDOTDIR/.zshrc
   $ZDOTDIR/.zlogin
   $ZDOTDIR/.zlogout
   ${TMPPREFIX}*   (default is /tmp/zsh*)
   /etc/zshenv
   /etc/zprofile
   /etc/zshrc
   /etc/zlogin
   /etc/zlogout    (installation-specific - /etc is the default)

It should be in one of those locations. If it doesn't show up in any of those places then you'll need to expand your search. I would suggest looking for just the string "prompt".

slm
  • 369,824
  • Oddly enough, the behavior of outputting function definition when called with a function name is characteristic of type rather than which. I'm guessing ArchLinux redefines which somehow. I wouldn't know. But I guess the OP's real problem is determining which file defines the prompt function. – Joseph R. Nov 07 '13 at 22:09
  • That is really nice to know, thank you! My immidiate problem is not solved by this ("prompt is a shell function"), but I learned something today =) – Jens Nov 07 '13 at 22:12
  • @Jens - sorry I didn't read the whole Q 8-). I've added a section on how to find prompt(). – slm Nov 07 '13 at 22:13
  • @JosephR. - thanks for pointing that out, updated Q. Should've read the whole thing 8-). BTW, I agree, never seen which show a function either, type makes more sense. – slm Nov 07 '13 at 22:14
  • @Jens - see updates. – slm Nov 07 '13 at 22:19
  • A grep -R "prompt ()" /etc /usr later I found the function definitions in /usr/share/zsh/functions/. Thanks again =) – Jens Nov 07 '13 at 22:27
  • @Jens - yeah it's a bit of a archaeologist job using Unix sometimes 8-). – slm Nov 07 '13 at 22:29
  • 1
    In zsh (as opposed to other shells such as Bourne, dash, bash or ksh), which is a builtin and can be used without compunction. – Gilles 'SO- stop being evil' Nov 07 '13 at 22:43
  • @Gilles So this type-like behavior of which is due to the zsh implementation rather than ArchLinux, right? – Joseph R. Nov 07 '13 at 22:49
  • 1
    @JosephR. Indeed, there's nothing specific to Arch here. – Gilles 'SO- stop being evil' Nov 07 '13 at 22:50
1

prompt by itself isn't useful: it's calling another function called set_prompt, you need this one as well (and all of its dependencies).

The first thing to look for would be an autoloaded function.

print -rl $fpath/prompt(N)

Barring that, search in your initialization files and in files on the function load path for the function definition.

grep -E '^ *function +prompt($|[^0-9A-Z_a-z])|^ *prompt *\(' ~/.z* /etc/zsh/*(.N) /etc/z*(.N) $fpath/*(.)

The prompt function is defined by …/Prompts/promptinit: it's part of the prompt themes component. In addition to promptinit, you'll need the prompt_*_setup file for your chosen prompt theme. Look in your ~/.zshrc for your choice of prompt theme — a call to the prompt function.