2

In my .bash_aliases file I have couple of aliases, like --

shopt -s expand_aliases
alias emx='emacs'
alias em='emacs -nw'
alias gv='gvim'
alias v='vi'
alias ev='evince'

when I use them and press [tab] for auto completion, they work --

:~/$ emx main-0 [press tab]
main-04.cpp       main-05.cpp       main-06.cpp       main-06-test.cpp 

or

:~/$ em main-0 [press tab]
main-04.cpp       main-05.cpp       main-06.cpp       main-06-test.cpp 

both for emx and em they work (also ev works), but when I try to use gv or v, it does not --

:~/$ gv main-0 [press tab]
<nothing happens>

why ??

2 Answers 2

3

In case it's a point of confusion, expand_aliases determines if aliases are checked when processing commands, it's a different thing altogether to completion.

It sounds like you have per-command completion set up, check the output of complete (no arguments). gv is conventionally the ghostview command, so it's possible that gv completion is only searching for PS/EPS/PDF files.

0

First of all, Bash auto-completion simply reads what you put in the command line without resolving aliases. If you put the command name, then it reads the command name. If you put an alias, then it reads the alias. So as far as completion is concerned, gv has nothing to do with gvim in your case. In fact, gv is a name defined in bash-completion script as:

_install_xspec '!*.@(@(?(e)ps|?(E)PS|pdf|PDF)?(.gz|.GZ|.bz2|.BZ2|.Z))' gv ggv kghostview
complete -F _filedir_xspec gv

So basically it only matches uncompressed and compressed ps and pdf files.

AFAIK you have 2 ways to deal with this:

  1. Set alias completion for gv to a different function. For example, _longopt works in your case:

    complete -F _longopt gv
    
  2. Write a generic alias completion function and use it on gv. Luckily someone has done this for you: https://github.com/cykerway/complete-alias

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .