Locating the source of a function in zsh












5














I have this annoying issue in my zsh shell where a function is being declared somewhere and that function is named "cp" so it's overriding the normal cp behavior. I'm trying to locate the function declaration but I can't. I already looked in the normal places of .zshrc and the various other sources that are being included in .zshrc but so far nothing.



Other things I've tried:





  • grep -r 'function cp' . (from ~)


  • whence -f cp (gives the function definition but not where it's declared from)


Any ideas?










share|improve this question





























    5














    I have this annoying issue in my zsh shell where a function is being declared somewhere and that function is named "cp" so it's overriding the normal cp behavior. I'm trying to locate the function declaration but I can't. I already looked in the normal places of .zshrc and the various other sources that are being included in .zshrc but so far nothing.



    Other things I've tried:





    • grep -r 'function cp' . (from ~)


    • whence -f cp (gives the function definition but not where it's declared from)


    Any ideas?










    share|improve this question



























      5












      5








      5


      2





      I have this annoying issue in my zsh shell where a function is being declared somewhere and that function is named "cp" so it's overriding the normal cp behavior. I'm trying to locate the function declaration but I can't. I already looked in the normal places of .zshrc and the various other sources that are being included in .zshrc but so far nothing.



      Other things I've tried:





      • grep -r 'function cp' . (from ~)


      • whence -f cp (gives the function definition but not where it's declared from)


      Any ideas?










      share|improve this question















      I have this annoying issue in my zsh shell where a function is being declared somewhere and that function is named "cp" so it's overriding the normal cp behavior. I'm trying to locate the function declaration but I can't. I already looked in the normal places of .zshrc and the various other sources that are being included in .zshrc but so far nothing.



      Other things I've tried:





      • grep -r 'function cp' . (from ~)


      • whence -f cp (gives the function definition but not where it's declared from)


      Any ideas?







      linux shell zsh






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 26 '14 at 21:46









      terdon

      41.2k885135




      41.2k885135










      asked Jan 26 '14 at 21:26









      asolbergasolberg

      18318




      18318






















          4 Answers
          4






          active

          oldest

          votes


















          3














          First of all, a function can be defined without the function keyword so a better search would be



          grep 'cp()' .*


          That will search through files such as .zshrc and .profile and whatnot. If that finds nothing, you might also want to see the various files loaded by zsh. These are listed at the very end of man zsh:



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


          By default $ZDOTDIR should be your $HOME. So, this command should find your offending file:



          grep 'cp()|cp ()' ~/.zshenv ~/.zprofile ~/.zshrc ~/.zlogin /etc/zsh/zshenv 
          /etc/zsh/zprofile /etc/zsh/zshrc /etc/zsh/zlogin


          I added the | since you can also have spaces between the function name and the function itself. Finally, @Dennis points out that the parentheses can also be omitted if you use the function keyword. So, to be even more safe, do this:



          grep -E 'function cp|cp *()' ~/.zshenv ~/.zprofile ~/.zshrc ~/.zlogin 
          /etc/zsh/zshenv /etc/zsh/zprofile /etc/zsh/zshrc /etc/zsh/zlogin





          share|improve this answer























          • grep will not search for files beginning with a . so it is pretty much useless. That's not true. When used with the -r switch, grep will go trough all files in directories it encounters. (At least my version of grep does.)
            – Dennis
            Jan 26 '14 at 22:16










          • @Dennis I stand corrected, I was thinking of globbing which is completely irrelevant here. Thanks, answer corrected.
            – terdon
            Jan 26 '14 at 22:19










          • Also, the parentheses are optional if the function keyword is used. grep -E 'function cp|cp *()' should catch all cases.
            – Dennis
            Jan 26 '14 at 22:24










          • @Dennis fair enough, thanks again, answer edited.
            – terdon
            Jan 26 '14 at 22:26



















          11














          I needed to do this today and found that whence -v outputs the file containing the function definition.



          $ whence -v function_name
          function_name is a shell function from /path/to/file





          share|improve this answer





















          • Can you post your version of zsh? I don't see output like that with zsh 5.0.2
            – Tarrasch
            Jul 20 '16 at 10:11










          • Worked for me with zsh 5.3
            – theonlygusti
            Nov 23 '17 at 16:30



















          1














          Newer versions of zsh (since 5.4, added in commit 34f70c5) supports the $functions_source array as part of the zsh/parameter module (documentation: man zshmodules):




          functions_source



          This readonly associative array maps names of enabled functions to the name of the file containing the source of the function.



          For an autoloaded function that has already been loaded, or marked for autoload with an absolute path, or that has had its path resolved with ‘functions -r’, this is the file found for autoloading, resolved to an absolute path.



          For a function defined within the body of a script or sourced file, this is the name of that file. In this case, this is the exact path originally used to that file, which may be a relative path.



          For any other function, including any defined at an interactive prompt or an autoload function whose path has not yet been resolved, this is the empty string. However, the hash element is reported as defined just so long as the function is present: the keys to this hash are the same as those to $funcions.




          So, you can do



          echo $functions_source[cp]





          share|improve this answer








          New contributor




          univerio is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.


























            0














            Terdon's answer already gave you the appropriate grep command to catch all possible variants of a function definition.



            I want to add two more points.





            1. To get a list of files, which are actually read in (e.g. a non-standard file might be sourced by another file!), you can invoke zsh with the SOURCE_TRACE option enabled:



              $ zsh -o sourcetrace
              +/etc/zshenv:1> <sourcetrace>
              +/home/user/.zshrc:1> <sourcetrace>
              +/home/user/.zcompdump:1> <sourcetrace>
              +/home/user/.zshrc-last:1> <sourcetrace>



            2. With this ,,grep-approach'' you won't catch functions which are autoloaded via the autoload builtin. So, do a check of your fpath, too:



              $ for i ($fpath) { ls -l "$i"/cp }







            share|improve this answer























              Your Answer








              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "3"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f707354%2flocating-the-source-of-a-function-in-zsh%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              4 Answers
              4






              active

              oldest

              votes








              4 Answers
              4






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              3














              First of all, a function can be defined without the function keyword so a better search would be



              grep 'cp()' .*


              That will search through files such as .zshrc and .profile and whatnot. If that finds nothing, you might also want to see the various files loaded by zsh. These are listed at the very end of man zsh:



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


              By default $ZDOTDIR should be your $HOME. So, this command should find your offending file:



              grep 'cp()|cp ()' ~/.zshenv ~/.zprofile ~/.zshrc ~/.zlogin /etc/zsh/zshenv 
              /etc/zsh/zprofile /etc/zsh/zshrc /etc/zsh/zlogin


              I added the | since you can also have spaces between the function name and the function itself. Finally, @Dennis points out that the parentheses can also be omitted if you use the function keyword. So, to be even more safe, do this:



              grep -E 'function cp|cp *()' ~/.zshenv ~/.zprofile ~/.zshrc ~/.zlogin 
              /etc/zsh/zshenv /etc/zsh/zprofile /etc/zsh/zshrc /etc/zsh/zlogin





              share|improve this answer























              • grep will not search for files beginning with a . so it is pretty much useless. That's not true. When used with the -r switch, grep will go trough all files in directories it encounters. (At least my version of grep does.)
                – Dennis
                Jan 26 '14 at 22:16










              • @Dennis I stand corrected, I was thinking of globbing which is completely irrelevant here. Thanks, answer corrected.
                – terdon
                Jan 26 '14 at 22:19










              • Also, the parentheses are optional if the function keyword is used. grep -E 'function cp|cp *()' should catch all cases.
                – Dennis
                Jan 26 '14 at 22:24










              • @Dennis fair enough, thanks again, answer edited.
                – terdon
                Jan 26 '14 at 22:26
















              3














              First of all, a function can be defined without the function keyword so a better search would be



              grep 'cp()' .*


              That will search through files such as .zshrc and .profile and whatnot. If that finds nothing, you might also want to see the various files loaded by zsh. These are listed at the very end of man zsh:



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


              By default $ZDOTDIR should be your $HOME. So, this command should find your offending file:



              grep 'cp()|cp ()' ~/.zshenv ~/.zprofile ~/.zshrc ~/.zlogin /etc/zsh/zshenv 
              /etc/zsh/zprofile /etc/zsh/zshrc /etc/zsh/zlogin


              I added the | since you can also have spaces between the function name and the function itself. Finally, @Dennis points out that the parentheses can also be omitted if you use the function keyword. So, to be even more safe, do this:



              grep -E 'function cp|cp *()' ~/.zshenv ~/.zprofile ~/.zshrc ~/.zlogin 
              /etc/zsh/zshenv /etc/zsh/zprofile /etc/zsh/zshrc /etc/zsh/zlogin





              share|improve this answer























              • grep will not search for files beginning with a . so it is pretty much useless. That's not true. When used with the -r switch, grep will go trough all files in directories it encounters. (At least my version of grep does.)
                – Dennis
                Jan 26 '14 at 22:16










              • @Dennis I stand corrected, I was thinking of globbing which is completely irrelevant here. Thanks, answer corrected.
                – terdon
                Jan 26 '14 at 22:19










              • Also, the parentheses are optional if the function keyword is used. grep -E 'function cp|cp *()' should catch all cases.
                – Dennis
                Jan 26 '14 at 22:24










              • @Dennis fair enough, thanks again, answer edited.
                – terdon
                Jan 26 '14 at 22:26














              3












              3








              3






              First of all, a function can be defined without the function keyword so a better search would be



              grep 'cp()' .*


              That will search through files such as .zshrc and .profile and whatnot. If that finds nothing, you might also want to see the various files loaded by zsh. These are listed at the very end of man zsh:



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


              By default $ZDOTDIR should be your $HOME. So, this command should find your offending file:



              grep 'cp()|cp ()' ~/.zshenv ~/.zprofile ~/.zshrc ~/.zlogin /etc/zsh/zshenv 
              /etc/zsh/zprofile /etc/zsh/zshrc /etc/zsh/zlogin


              I added the | since you can also have spaces between the function name and the function itself. Finally, @Dennis points out that the parentheses can also be omitted if you use the function keyword. So, to be even more safe, do this:



              grep -E 'function cp|cp *()' ~/.zshenv ~/.zprofile ~/.zshrc ~/.zlogin 
              /etc/zsh/zshenv /etc/zsh/zprofile /etc/zsh/zshrc /etc/zsh/zlogin





              share|improve this answer














              First of all, a function can be defined without the function keyword so a better search would be



              grep 'cp()' .*


              That will search through files such as .zshrc and .profile and whatnot. If that finds nothing, you might also want to see the various files loaded by zsh. These are listed at the very end of man zsh:



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


              By default $ZDOTDIR should be your $HOME. So, this command should find your offending file:



              grep 'cp()|cp ()' ~/.zshenv ~/.zprofile ~/.zshrc ~/.zlogin /etc/zsh/zshenv 
              /etc/zsh/zprofile /etc/zsh/zshrc /etc/zsh/zlogin


              I added the | since you can also have spaces between the function name and the function itself. Finally, @Dennis points out that the parentheses can also be omitted if you use the function keyword. So, to be even more safe, do this:



              grep -E 'function cp|cp *()' ~/.zshenv ~/.zprofile ~/.zshrc ~/.zlogin 
              /etc/zsh/zshenv /etc/zsh/zprofile /etc/zsh/zshrc /etc/zsh/zlogin






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Mar 20 '17 at 10:17









              Community

              1




              1










              answered Jan 26 '14 at 21:55









              terdonterdon

              41.2k885135




              41.2k885135












              • grep will not search for files beginning with a . so it is pretty much useless. That's not true. When used with the -r switch, grep will go trough all files in directories it encounters. (At least my version of grep does.)
                – Dennis
                Jan 26 '14 at 22:16










              • @Dennis I stand corrected, I was thinking of globbing which is completely irrelevant here. Thanks, answer corrected.
                – terdon
                Jan 26 '14 at 22:19










              • Also, the parentheses are optional if the function keyword is used. grep -E 'function cp|cp *()' should catch all cases.
                – Dennis
                Jan 26 '14 at 22:24










              • @Dennis fair enough, thanks again, answer edited.
                – terdon
                Jan 26 '14 at 22:26


















              • grep will not search for files beginning with a . so it is pretty much useless. That's not true. When used with the -r switch, grep will go trough all files in directories it encounters. (At least my version of grep does.)
                – Dennis
                Jan 26 '14 at 22:16










              • @Dennis I stand corrected, I was thinking of globbing which is completely irrelevant here. Thanks, answer corrected.
                – terdon
                Jan 26 '14 at 22:19










              • Also, the parentheses are optional if the function keyword is used. grep -E 'function cp|cp *()' should catch all cases.
                – Dennis
                Jan 26 '14 at 22:24










              • @Dennis fair enough, thanks again, answer edited.
                – terdon
                Jan 26 '14 at 22:26
















              grep will not search for files beginning with a . so it is pretty much useless. That's not true. When used with the -r switch, grep will go trough all files in directories it encounters. (At least my version of grep does.)
              – Dennis
              Jan 26 '14 at 22:16




              grep will not search for files beginning with a . so it is pretty much useless. That's not true. When used with the -r switch, grep will go trough all files in directories it encounters. (At least my version of grep does.)
              – Dennis
              Jan 26 '14 at 22:16












              @Dennis I stand corrected, I was thinking of globbing which is completely irrelevant here. Thanks, answer corrected.
              – terdon
              Jan 26 '14 at 22:19




              @Dennis I stand corrected, I was thinking of globbing which is completely irrelevant here. Thanks, answer corrected.
              – terdon
              Jan 26 '14 at 22:19












              Also, the parentheses are optional if the function keyword is used. grep -E 'function cp|cp *()' should catch all cases.
              – Dennis
              Jan 26 '14 at 22:24




              Also, the parentheses are optional if the function keyword is used. grep -E 'function cp|cp *()' should catch all cases.
              – Dennis
              Jan 26 '14 at 22:24












              @Dennis fair enough, thanks again, answer edited.
              – terdon
              Jan 26 '14 at 22:26




              @Dennis fair enough, thanks again, answer edited.
              – terdon
              Jan 26 '14 at 22:26













              11














              I needed to do this today and found that whence -v outputs the file containing the function definition.



              $ whence -v function_name
              function_name is a shell function from /path/to/file





              share|improve this answer





















              • Can you post your version of zsh? I don't see output like that with zsh 5.0.2
                – Tarrasch
                Jul 20 '16 at 10:11










              • Worked for me with zsh 5.3
                – theonlygusti
                Nov 23 '17 at 16:30
















              11














              I needed to do this today and found that whence -v outputs the file containing the function definition.



              $ whence -v function_name
              function_name is a shell function from /path/to/file





              share|improve this answer





















              • Can you post your version of zsh? I don't see output like that with zsh 5.0.2
                – Tarrasch
                Jul 20 '16 at 10:11










              • Worked for me with zsh 5.3
                – theonlygusti
                Nov 23 '17 at 16:30














              11












              11








              11






              I needed to do this today and found that whence -v outputs the file containing the function definition.



              $ whence -v function_name
              function_name is a shell function from /path/to/file





              share|improve this answer












              I needed to do this today and found that whence -v outputs the file containing the function definition.



              $ whence -v function_name
              function_name is a shell function from /path/to/file






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Dec 26 '15 at 22:02









              Will AdamsWill Adams

              11113




              11113












              • Can you post your version of zsh? I don't see output like that with zsh 5.0.2
                – Tarrasch
                Jul 20 '16 at 10:11










              • Worked for me with zsh 5.3
                – theonlygusti
                Nov 23 '17 at 16:30


















              • Can you post your version of zsh? I don't see output like that with zsh 5.0.2
                – Tarrasch
                Jul 20 '16 at 10:11










              • Worked for me with zsh 5.3
                – theonlygusti
                Nov 23 '17 at 16:30
















              Can you post your version of zsh? I don't see output like that with zsh 5.0.2
              – Tarrasch
              Jul 20 '16 at 10:11




              Can you post your version of zsh? I don't see output like that with zsh 5.0.2
              – Tarrasch
              Jul 20 '16 at 10:11












              Worked for me with zsh 5.3
              – theonlygusti
              Nov 23 '17 at 16:30




              Worked for me with zsh 5.3
              – theonlygusti
              Nov 23 '17 at 16:30











              1














              Newer versions of zsh (since 5.4, added in commit 34f70c5) supports the $functions_source array as part of the zsh/parameter module (documentation: man zshmodules):




              functions_source



              This readonly associative array maps names of enabled functions to the name of the file containing the source of the function.



              For an autoloaded function that has already been loaded, or marked for autoload with an absolute path, or that has had its path resolved with ‘functions -r’, this is the file found for autoloading, resolved to an absolute path.



              For a function defined within the body of a script or sourced file, this is the name of that file. In this case, this is the exact path originally used to that file, which may be a relative path.



              For any other function, including any defined at an interactive prompt or an autoload function whose path has not yet been resolved, this is the empty string. However, the hash element is reported as defined just so long as the function is present: the keys to this hash are the same as those to $funcions.




              So, you can do



              echo $functions_source[cp]





              share|improve this answer








              New contributor




              univerio is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
              Check out our Code of Conduct.























                1














                Newer versions of zsh (since 5.4, added in commit 34f70c5) supports the $functions_source array as part of the zsh/parameter module (documentation: man zshmodules):




                functions_source



                This readonly associative array maps names of enabled functions to the name of the file containing the source of the function.



                For an autoloaded function that has already been loaded, or marked for autoload with an absolute path, or that has had its path resolved with ‘functions -r’, this is the file found for autoloading, resolved to an absolute path.



                For a function defined within the body of a script or sourced file, this is the name of that file. In this case, this is the exact path originally used to that file, which may be a relative path.



                For any other function, including any defined at an interactive prompt or an autoload function whose path has not yet been resolved, this is the empty string. However, the hash element is reported as defined just so long as the function is present: the keys to this hash are the same as those to $funcions.




                So, you can do



                echo $functions_source[cp]





                share|improve this answer








                New contributor




                univerio is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                Check out our Code of Conduct.





















                  1












                  1








                  1






                  Newer versions of zsh (since 5.4, added in commit 34f70c5) supports the $functions_source array as part of the zsh/parameter module (documentation: man zshmodules):




                  functions_source



                  This readonly associative array maps names of enabled functions to the name of the file containing the source of the function.



                  For an autoloaded function that has already been loaded, or marked for autoload with an absolute path, or that has had its path resolved with ‘functions -r’, this is the file found for autoloading, resolved to an absolute path.



                  For a function defined within the body of a script or sourced file, this is the name of that file. In this case, this is the exact path originally used to that file, which may be a relative path.



                  For any other function, including any defined at an interactive prompt or an autoload function whose path has not yet been resolved, this is the empty string. However, the hash element is reported as defined just so long as the function is present: the keys to this hash are the same as those to $funcions.




                  So, you can do



                  echo $functions_source[cp]





                  share|improve this answer








                  New contributor




                  univerio is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  Newer versions of zsh (since 5.4, added in commit 34f70c5) supports the $functions_source array as part of the zsh/parameter module (documentation: man zshmodules):




                  functions_source



                  This readonly associative array maps names of enabled functions to the name of the file containing the source of the function.



                  For an autoloaded function that has already been loaded, or marked for autoload with an absolute path, or that has had its path resolved with ‘functions -r’, this is the file found for autoloading, resolved to an absolute path.



                  For a function defined within the body of a script or sourced file, this is the name of that file. In this case, this is the exact path originally used to that file, which may be a relative path.



                  For any other function, including any defined at an interactive prompt or an autoload function whose path has not yet been resolved, this is the empty string. However, the hash element is reported as defined just so long as the function is present: the keys to this hash are the same as those to $funcions.




                  So, you can do



                  echo $functions_source[cp]






                  share|improve this answer








                  New contributor




                  univerio is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  share|improve this answer



                  share|improve this answer






                  New contributor




                  univerio is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.









                  answered Jan 6 at 23:06









                  univeriouniverio

                  1113




                  1113




                  New contributor




                  univerio is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.





                  New contributor





                  univerio is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.






                  univerio is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                  Check out our Code of Conduct.























                      0














                      Terdon's answer already gave you the appropriate grep command to catch all possible variants of a function definition.



                      I want to add two more points.





                      1. To get a list of files, which are actually read in (e.g. a non-standard file might be sourced by another file!), you can invoke zsh with the SOURCE_TRACE option enabled:



                        $ zsh -o sourcetrace
                        +/etc/zshenv:1> <sourcetrace>
                        +/home/user/.zshrc:1> <sourcetrace>
                        +/home/user/.zcompdump:1> <sourcetrace>
                        +/home/user/.zshrc-last:1> <sourcetrace>



                      2. With this ,,grep-approach'' you won't catch functions which are autoloaded via the autoload builtin. So, do a check of your fpath, too:



                        $ for i ($fpath) { ls -l "$i"/cp }







                      share|improve this answer




























                        0














                        Terdon's answer already gave you the appropriate grep command to catch all possible variants of a function definition.



                        I want to add two more points.





                        1. To get a list of files, which are actually read in (e.g. a non-standard file might be sourced by another file!), you can invoke zsh with the SOURCE_TRACE option enabled:



                          $ zsh -o sourcetrace
                          +/etc/zshenv:1> <sourcetrace>
                          +/home/user/.zshrc:1> <sourcetrace>
                          +/home/user/.zcompdump:1> <sourcetrace>
                          +/home/user/.zshrc-last:1> <sourcetrace>



                        2. With this ,,grep-approach'' you won't catch functions which are autoloaded via the autoload builtin. So, do a check of your fpath, too:



                          $ for i ($fpath) { ls -l "$i"/cp }







                        share|improve this answer


























                          0












                          0








                          0






                          Terdon's answer already gave you the appropriate grep command to catch all possible variants of a function definition.



                          I want to add two more points.





                          1. To get a list of files, which are actually read in (e.g. a non-standard file might be sourced by another file!), you can invoke zsh with the SOURCE_TRACE option enabled:



                            $ zsh -o sourcetrace
                            +/etc/zshenv:1> <sourcetrace>
                            +/home/user/.zshrc:1> <sourcetrace>
                            +/home/user/.zcompdump:1> <sourcetrace>
                            +/home/user/.zshrc-last:1> <sourcetrace>



                          2. With this ,,grep-approach'' you won't catch functions which are autoloaded via the autoload builtin. So, do a check of your fpath, too:



                            $ for i ($fpath) { ls -l "$i"/cp }







                          share|improve this answer














                          Terdon's answer already gave you the appropriate grep command to catch all possible variants of a function definition.



                          I want to add two more points.





                          1. To get a list of files, which are actually read in (e.g. a non-standard file might be sourced by another file!), you can invoke zsh with the SOURCE_TRACE option enabled:



                            $ zsh -o sourcetrace
                            +/etc/zshenv:1> <sourcetrace>
                            +/home/user/.zshrc:1> <sourcetrace>
                            +/home/user/.zcompdump:1> <sourcetrace>
                            +/home/user/.zshrc-last:1> <sourcetrace>



                          2. With this ,,grep-approach'' you won't catch functions which are autoloaded via the autoload builtin. So, do a check of your fpath, too:



                            $ for i ($fpath) { ls -l "$i"/cp }








                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Mar 20 '17 at 10:17









                          Community

                          1




                          1










                          answered Jan 27 '14 at 10:33









                          mpympy

                          18k45271




                          18k45271






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Super User!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f707354%2flocating-the-source-of-a-function-in-zsh%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              How to make a Squid Proxy server?

                              Is this a new Fibonacci Identity?

                              Touch on Surface Book