I've set an alias to xdg-open adding alias op="xdg-open" to my ~/.bashrc file.

The command op file.pdf works, but I'm not able to autocomplete when typing, for example, op fi and hitting TAB.

This is kind of annoying as the point of setting the alias is to save time. How can I fix this?


I guess you have bash-completion installed, which automatically loads the completion it ships for the op command when you try to complete a command line starting with your op alias.

You can avoid this by:

  • Choosing a different alias (and looking at the files in /usr/share/bash-completion/completions/ to make sure you pick a safe name); or

  • Adding complete -o default -o bashdefault op to your ~/.bashrc to instruct bash-completion not to use the shipped completion (see "How can I override a completion shipped by bash-completion?" in the FAQ at the GitHub repository linked above).

    Of course, if you are defining an alias to a command for which a completion file exists on your system, you may use the completion function defined there instead of resetting the completion to its default behavior. Note, though, that this would probably require you to explicitly load the completion function. The resulting .bashrc snippet could be:

    alias your_alias=aliased_command
    _completion_loader aliased_command
    complete -F completion_function your_alias

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.