Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 3 down vote accepted

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

share|improve this answer
    
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 7 '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 7 '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 7 '13 at 22:13
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 Nov 7 '13 at 22:43
1  
@JosephR. Indeed, there's nothing specific to Arch here. –  Gilles Nov 7 '13 at 22:50

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.