How do you print the code of a shell function in terminal?

There is built-in command functions in zsh for this purpose

functions k.pstree.n

For example in case of my preexec function:

$ functions preexec

preexec () {
    local cmd=${1:-}
    cmd=${cmd//\\/\\\\} 
    [[ "$TERM" =~ screen* ]] && cmd="S $cmd" 
    inf=$(print -Pn "%n@%m: %3~") 
    print -n "\e]2;$cmd $inf\a"
    cmd_start=$SECONDS 
}

Or use typeset -fp function_name which has the benefit of also working in ksh, bash and yash.

In zsh, the function definition is also available in the $functions special associative array (the key is the function name, the value the function body).


you can use which command :

$ which k.pstree.n

Tags:

Function

Zsh