How to extend existing zsh completion functions?












1















I'm trying to add auto-completion for some custom ant parameters. However, it seems to be overwriting the existing oh my zsh ant plugin auto-completions which I'd like to keep. Is there a simple way to have both the oh my zsh plugin and my custom ant auto-completion live in harmony?



Here's the existing plugin at ~/.oh-my-zsh/plugins/ant/ant.plugin.zsh



_ant_does_target_list_need_generating () {
[ ! -f .ant_targets ] && return 0;
[ build.xml -nt .ant_targets ] && return 0;
return 1;
}

_ant () {
if [ -f build.xml ]; then
if _ant_does_target_list_need_generating; then
ant -p | awk -F " " 'NR > 5 { print lastTarget }{lastTarget = $1}' > .ant_targets
fi
compadd -- `cat .ant_targets`
fi
}

compdef _ant ant


And my auto complete at ~/my_completions/_ant



#compdef ant

_arguments '-Dprop=-[properties file]:filename:->files' '-Dsrc=-[build directory]:directory:_files -/'
case "$state" in
files)
local -a property_files
property_files=( *.properties )
_multi_parts / property_files
;;
esac


And here is my $fpath, the path for my completion is earlier in the list which I guess is why my script gets precedence.



/Users/myusername/my_completions /Users/myusername/.oh-my-zsh/plugins/git /Users/myusername/.oh-my-zsh/functions /Users/myusername/.oh-my-zsh/completions /usr/local/share/zsh/site-functions /usr/share/zsh/site-functions /usr/share/zsh/5.0.8/functions









share|improve this question



























    1















    I'm trying to add auto-completion for some custom ant parameters. However, it seems to be overwriting the existing oh my zsh ant plugin auto-completions which I'd like to keep. Is there a simple way to have both the oh my zsh plugin and my custom ant auto-completion live in harmony?



    Here's the existing plugin at ~/.oh-my-zsh/plugins/ant/ant.plugin.zsh



    _ant_does_target_list_need_generating () {
    [ ! -f .ant_targets ] && return 0;
    [ build.xml -nt .ant_targets ] && return 0;
    return 1;
    }

    _ant () {
    if [ -f build.xml ]; then
    if _ant_does_target_list_need_generating; then
    ant -p | awk -F " " 'NR > 5 { print lastTarget }{lastTarget = $1}' > .ant_targets
    fi
    compadd -- `cat .ant_targets`
    fi
    }

    compdef _ant ant


    And my auto complete at ~/my_completions/_ant



    #compdef ant

    _arguments '-Dprop=-[properties file]:filename:->files' '-Dsrc=-[build directory]:directory:_files -/'
    case "$state" in
    files)
    local -a property_files
    property_files=( *.properties )
    _multi_parts / property_files
    ;;
    esac


    And here is my $fpath, the path for my completion is earlier in the list which I guess is why my script gets precedence.



    /Users/myusername/my_completions /Users/myusername/.oh-my-zsh/plugins/git /Users/myusername/.oh-my-zsh/functions /Users/myusername/.oh-my-zsh/completions /usr/local/share/zsh/site-functions /usr/share/zsh/site-functions /usr/share/zsh/5.0.8/functions









    share|improve this question

























      1












      1








      1








      I'm trying to add auto-completion for some custom ant parameters. However, it seems to be overwriting the existing oh my zsh ant plugin auto-completions which I'd like to keep. Is there a simple way to have both the oh my zsh plugin and my custom ant auto-completion live in harmony?



      Here's the existing plugin at ~/.oh-my-zsh/plugins/ant/ant.plugin.zsh



      _ant_does_target_list_need_generating () {
      [ ! -f .ant_targets ] && return 0;
      [ build.xml -nt .ant_targets ] && return 0;
      return 1;
      }

      _ant () {
      if [ -f build.xml ]; then
      if _ant_does_target_list_need_generating; then
      ant -p | awk -F " " 'NR > 5 { print lastTarget }{lastTarget = $1}' > .ant_targets
      fi
      compadd -- `cat .ant_targets`
      fi
      }

      compdef _ant ant


      And my auto complete at ~/my_completions/_ant



      #compdef ant

      _arguments '-Dprop=-[properties file]:filename:->files' '-Dsrc=-[build directory]:directory:_files -/'
      case "$state" in
      files)
      local -a property_files
      property_files=( *.properties )
      _multi_parts / property_files
      ;;
      esac


      And here is my $fpath, the path for my completion is earlier in the list which I guess is why my script gets precedence.



      /Users/myusername/my_completions /Users/myusername/.oh-my-zsh/plugins/git /Users/myusername/.oh-my-zsh/functions /Users/myusername/.oh-my-zsh/completions /usr/local/share/zsh/site-functions /usr/share/zsh/site-functions /usr/share/zsh/5.0.8/functions









      share|improve this question














      I'm trying to add auto-completion for some custom ant parameters. However, it seems to be overwriting the existing oh my zsh ant plugin auto-completions which I'd like to keep. Is there a simple way to have both the oh my zsh plugin and my custom ant auto-completion live in harmony?



      Here's the existing plugin at ~/.oh-my-zsh/plugins/ant/ant.plugin.zsh



      _ant_does_target_list_need_generating () {
      [ ! -f .ant_targets ] && return 0;
      [ build.xml -nt .ant_targets ] && return 0;
      return 1;
      }

      _ant () {
      if [ -f build.xml ]; then
      if _ant_does_target_list_need_generating; then
      ant -p | awk -F " " 'NR > 5 { print lastTarget }{lastTarget = $1}' > .ant_targets
      fi
      compadd -- `cat .ant_targets`
      fi
      }

      compdef _ant ant


      And my auto complete at ~/my_completions/_ant



      #compdef ant

      _arguments '-Dprop=-[properties file]:filename:->files' '-Dsrc=-[build directory]:directory:_files -/'
      case "$state" in
      files)
      local -a property_files
      property_files=( *.properties )
      _multi_parts / property_files
      ;;
      esac


      And here is my $fpath, the path for my completion is earlier in the list which I guess is why my script gets precedence.



      /Users/myusername/my_completions /Users/myusername/.oh-my-zsh/plugins/git /Users/myusername/.oh-my-zsh/functions /Users/myusername/.oh-my-zsh/completions /usr/local/share/zsh/site-functions /usr/share/zsh/site-functions /usr/share/zsh/5.0.8/functions






      zsh autocomplete oh-my-zsh






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Oct 23 '18 at 0:02









      Ralph CallawayRalph Callaway

      1063




      1063






















          1 Answer
          1






          active

          oldest

          votes


















          0














          I think the best way to do it is to extend completion function. Here is how you can do it:
          https://unix.stackexchange.com/a/450133



          First you would need to find the name of your existing function, to do it, you can bind _complete_help to CTRL-h (or any other shortcut), then type your command and look for completion function. Here is an example running it for git:



          % bindkey '^h' _complete_help  
          % git [press ctrl-h]
          tags in context :completion::complete:git::
          argument-1 options (_arguments _git)
          tags in context :completion::complete:git:argument-1:
          aliases main-porcelain-commands user-commands third-party-commands ancillary-manipulator-commands ancillary-interrogator-commands interaction-commands plumbing-manipulator-commands plumbing-interrogator-commands plumbing-sync-commands plumbing-sync-helper-commands plumbing-internal-helper-commands (_git_commands _git)


          In this case the completion function is _git.
          Next you can redefine it in your .zshrc like this:



          # Call the function to make sure that it is loaded.
          _git 2>/dev/null
          # Save the original function.
          functions[_git-orig]=$functions[_git]
          # Redefine your completion function referencing the original.
          _git() {
          _git-orig "$@"
          ...
          }


          You wouldn't need to call compdef again, since it is already bound to that function, and you just changed the function definition.






          share|improve this answer








          New contributor




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




















            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "106"
            };
            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: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            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%2funix.stackexchange.com%2fquestions%2f477142%2fhow-to-extend-existing-zsh-completion-functions%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I think the best way to do it is to extend completion function. Here is how you can do it:
            https://unix.stackexchange.com/a/450133



            First you would need to find the name of your existing function, to do it, you can bind _complete_help to CTRL-h (or any other shortcut), then type your command and look for completion function. Here is an example running it for git:



            % bindkey '^h' _complete_help  
            % git [press ctrl-h]
            tags in context :completion::complete:git::
            argument-1 options (_arguments _git)
            tags in context :completion::complete:git:argument-1:
            aliases main-porcelain-commands user-commands third-party-commands ancillary-manipulator-commands ancillary-interrogator-commands interaction-commands plumbing-manipulator-commands plumbing-interrogator-commands plumbing-sync-commands plumbing-sync-helper-commands plumbing-internal-helper-commands (_git_commands _git)


            In this case the completion function is _git.
            Next you can redefine it in your .zshrc like this:



            # Call the function to make sure that it is loaded.
            _git 2>/dev/null
            # Save the original function.
            functions[_git-orig]=$functions[_git]
            # Redefine your completion function referencing the original.
            _git() {
            _git-orig "$@"
            ...
            }


            You wouldn't need to call compdef again, since it is already bound to that function, and you just changed the function definition.






            share|improve this answer








            New contributor




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

























              0














              I think the best way to do it is to extend completion function. Here is how you can do it:
              https://unix.stackexchange.com/a/450133



              First you would need to find the name of your existing function, to do it, you can bind _complete_help to CTRL-h (or any other shortcut), then type your command and look for completion function. Here is an example running it for git:



              % bindkey '^h' _complete_help  
              % git [press ctrl-h]
              tags in context :completion::complete:git::
              argument-1 options (_arguments _git)
              tags in context :completion::complete:git:argument-1:
              aliases main-porcelain-commands user-commands third-party-commands ancillary-manipulator-commands ancillary-interrogator-commands interaction-commands plumbing-manipulator-commands plumbing-interrogator-commands plumbing-sync-commands plumbing-sync-helper-commands plumbing-internal-helper-commands (_git_commands _git)


              In this case the completion function is _git.
              Next you can redefine it in your .zshrc like this:



              # Call the function to make sure that it is loaded.
              _git 2>/dev/null
              # Save the original function.
              functions[_git-orig]=$functions[_git]
              # Redefine your completion function referencing the original.
              _git() {
              _git-orig "$@"
              ...
              }


              You wouldn't need to call compdef again, since it is already bound to that function, and you just changed the function definition.






              share|improve this answer








              New contributor




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























                0












                0








                0







                I think the best way to do it is to extend completion function. Here is how you can do it:
                https://unix.stackexchange.com/a/450133



                First you would need to find the name of your existing function, to do it, you can bind _complete_help to CTRL-h (or any other shortcut), then type your command and look for completion function. Here is an example running it for git:



                % bindkey '^h' _complete_help  
                % git [press ctrl-h]
                tags in context :completion::complete:git::
                argument-1 options (_arguments _git)
                tags in context :completion::complete:git:argument-1:
                aliases main-porcelain-commands user-commands third-party-commands ancillary-manipulator-commands ancillary-interrogator-commands interaction-commands plumbing-manipulator-commands plumbing-interrogator-commands plumbing-sync-commands plumbing-sync-helper-commands plumbing-internal-helper-commands (_git_commands _git)


                In this case the completion function is _git.
                Next you can redefine it in your .zshrc like this:



                # Call the function to make sure that it is loaded.
                _git 2>/dev/null
                # Save the original function.
                functions[_git-orig]=$functions[_git]
                # Redefine your completion function referencing the original.
                _git() {
                _git-orig "$@"
                ...
                }


                You wouldn't need to call compdef again, since it is already bound to that function, and you just changed the function definition.






                share|improve this answer








                New contributor




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










                I think the best way to do it is to extend completion function. Here is how you can do it:
                https://unix.stackexchange.com/a/450133



                First you would need to find the name of your existing function, to do it, you can bind _complete_help to CTRL-h (or any other shortcut), then type your command and look for completion function. Here is an example running it for git:



                % bindkey '^h' _complete_help  
                % git [press ctrl-h]
                tags in context :completion::complete:git::
                argument-1 options (_arguments _git)
                tags in context :completion::complete:git:argument-1:
                aliases main-porcelain-commands user-commands third-party-commands ancillary-manipulator-commands ancillary-interrogator-commands interaction-commands plumbing-manipulator-commands plumbing-interrogator-commands plumbing-sync-commands plumbing-sync-helper-commands plumbing-internal-helper-commands (_git_commands _git)


                In this case the completion function is _git.
                Next you can redefine it in your .zshrc like this:



                # Call the function to make sure that it is loaded.
                _git 2>/dev/null
                # Save the original function.
                functions[_git-orig]=$functions[_git]
                # Redefine your completion function referencing the original.
                _git() {
                _git-orig "$@"
                ...
                }


                You wouldn't need to call compdef again, since it is already bound to that function, and you just changed the function definition.







                share|improve this answer








                New contributor




                Attila 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




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









                answered 20 mins ago









                AttilaAttila

                1011




                1011




                New contributor




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





                New contributor





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






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






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • 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%2funix.stackexchange.com%2fquestions%2f477142%2fhow-to-extend-existing-zsh-completion-functions%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

                    Entries order in /etc/network/interfaces

                    新発田市

                    Grub takes very long (several minutes) to open Menu (in Multi-Boot-System)