Giter Site home page Giter Site logo

alias completion broken about bash-completion HOT 5 CLOSED

scop avatar scop commented on July 23, 2024
alias completion broken

from bash-completion.

Comments (5)

afoglia avatar afoglia commented on July 23, 2024 1

The last two sentences of your commit leave a lot to be desired.

They basically say "use this completely uncommented master-level bash function." All the user wants, and all I want to do, is use a predefined completion for an alias.

The only way I can see that is either to put a symlink of the alias name under the completions directory--that requires root, while aliases are defined per-user--or just load the completion first in the shell, defeating the point of the dynamic loading you've set up.

How do I register an alias or my own custom function or command for dynamic completion loading? Or is that not possible. And can you explain that with an example that does not require root?

from bash-completion.

scop avatar scop commented on July 23, 2024

The git completion is not shipped by us, it comes with git itself, and this doesn't look like an issue with bash-completion or related aliases in the first place. But anyway, here's some ideas you may find useful: The function git uses may not be named _git, you can check what it is with complete -p git (for me it's __git_wrap__git_main). Also, if your git completion is not eagerly loaded at shell startup, you need to ensure it gets loaded on demand when your own completion that uses it is invoked. There are a couple of ways to do this; one is to use our _xfunc helper function, and another is to place appropriately named symlink in your bash-completion's completions dir. See examples in bash-completion for these for more info.

from bash-completion.

radi-ka avatar radi-ka commented on July 23, 2024

i think i wasn't clear on this. this isnt specific to git. it happens with all aliases, i just used git as an example.
when typing git <tab> i get the correct git completion output.

here my output: note the second gitalias

test@test:~$ complete -p git
bash: complete: git: no completion specification

test@test:~$ gitalias bash: completion: function '_git' not found`

test@test:~$ git 
add                 config              log                 reset 
am                  credential          meld                revert 
annotate            describe            merge               rm 
apply               diff                mergetool           shortlog 
archive             difftool            mv                  show 
bisect              fetch               name-rev            show-branch 
blame               filter-branch       notes               stage 
branch              format-patch        pull                stash 
bundle              fsck                push                status 
checkout            gc                  rebase              submodule 
cherry              get-tar-commit-id   reflog              subtree 
cherry-pick         grep                relink              tag 
clean               help                remote              verify-commit 
clone               imap-send           repack              whatchanged 
column              init                replace             
commit              instaweb            request-pull     

test@test:~$ gitalias 
add                 config              log                 reset 
am                  credential          meld                revert 
annotate            describe            merge               rm 
apply               diff                mergetool           shortlog 
archive             difftool            mv                  show 
bisect              fetch               name-rev            show-branch 
blame               filter-branch       notes               stage 
branch              format-patch        pull                stash 
bundle              fsck                push                status 
checkout            gc                  rebase              submodule 
cherry              get-tar-commit-id   reflog              subtree 
cherry-pick         grep                relink              tag 
clean               help                remote              verify-commit 
clone               imap-send           repack              whatchanged 
column              init                replace             
commit              instaweb            request-pull    

test@test:~$ complete -p git
complete -o bashdefault -o default -o nospace -F __git_wrap__git_main git

after reading your answer this looks like the completion is not loaded at shell startup. How can i achieve this?
my bashrc should already do it, i think, as it contains

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
if ! shopt -oq posix; then
  if [ -f /usr/share/bash-completion/bash_completion ]; then
    . /usr/share/bash-completion/bash_completion
  elif [ -f /etc/bash_completion ]; then
    . /etc/bash_completion
  fi
fi

what gets shipped with debian

But i will look through your other ideas as soon as i get off work. thanks

EDIT:
adding _completion_loader git does the trick. Thanks for pointing me in the right direction!
But for complete -p git to work i still need to trigger the completion at least once. I can live with that...

from bash-completion.

scop avatar scop commented on July 23, 2024

The last two sentences of my previous comment already contained pointers towards how to take care of this the recommended way, dynamically. Direct invocation of _completion_loader could work too, but it's not intended to be used like that.

from bash-completion.

scop avatar scop commented on July 23, 2024

User completion files are dynamically loaded from $BASH_COMPLETION_USER_DIR/completions. See the source of __load_completion for what the user dir defaults to.

from bash-completion.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.