Is there a mechanism for getting a function definition from console without grepping manually files ?
I search for a way to find fast a definition of known function name.
For example I want to know where "_kill" autocompletion function is defined.
In ruby with the use of pry I can get something like this:
show-method find
From: app/models/search/object.rb @ line 2:
Number of lines: 7
def self.find(conditions = {}, options = {})
type = extract_object_type
raise 'do not call Search::Object directly' if type == 'Object'
search_logic = "Search::#{type.camelize}Logic".constantize.new(conditions, options)
search_logic.process!
search_logic.execute
end
For zsh, try whence -f
or type -f
. For example:
myhost% whence -f _kill
_kill () {
# undefined
builtin autoload -XUz
}
For me following works:
$ autoload +X _kill # important step
$ whence -v _kill
_kill is a shell function from /usr/share/zsh/5.2/functions/_kill
Zsh Documentation – 9.1 Autoloading Functions
To load the definition of an autoloaded function myfunc without executing myfunc, use:
autoload +X myfunc
After autoload +X
you can also see the actual function with whence -f
$ whence -f _kill
_kill () {
local curcontext="$curcontext" line state ret=1
typeset -A opt_args
_arguments -C '(-s -l 1)-n[specify signal number]:signal number' '(-n -l 1)-s[specify signal name]:signal:_signals -s' '(-n -s)-l[list signal names or numbers of specified signals]:*:signal:_signals' '(-n -s -l)1::signal:_signals -p -s' '*:processes:->processes' && ret=0
if [[ -n "$state" ]]
then
local pgrp='process-groups:: _wanted '
[[ -n "$opt_args[(i)-[ns]]${${(@)line:#--}}" && -prefix - ]] && pgrp+='-x '
pgrp+="process-groups expl 'process-group' compadd - 0"
_alternative 'processes:: _pids' 'jobs:: _jobs -t' $pgrp && ret=0
fi
return ret
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.