bash - Shell : get function's body by it's name -


i use zsh (sometimes bash). thing have multiple shell scripts , i've got no idea how code small function printing function code it's name (with highlighting; use pygmentize -g). here's small example of want get:


$ getfunc "somefunc"  #    my_little_hacks.sh somefunc () {     # function code } 

is clean , efficient way in shell or awk without using nl , cat in best time available shell interpreter?

it improbable function have word function in it's body except when there nested ones there. next impossible has { or } legally unpaired inside quotes.

declare -f funcname 

...will retrieve code function funcname in both bash , zsh. thus:

getfunc() {   declare -f "$@" | pygmentize -l bash } 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -