开发者

Need more humane completion of environment variables

Suppose we have this environment:

mkdir -p /tmp/foo/bar/
export TEST=/tmp/foo

Out of the box, bash completion of $TEST is extremely inconsistent. Witness: →

$ cd $TES<Tab>     →  $ cd $TEST<cursor>
$ cd $TEST<Tab>    →  $ cd $TEST<cursor>
$ cd $TEST/<Tab>   →  $ cd $TEST/<cursor> 
$ cd $TEST/b<Tab>  →  $ cd $TEST/b<cursor>        # no actual completion!

$ ls $TES<Tab>     →  $ ls $TES<cursor>           # no actual completion!
$ ls $TEST<Tab>    →  $ ls $TEST<cursor>          # same
$ ls $TEST/<Tab>   →  $ ls /tmp/foo/bar/<cursor>  # expands var, annoying!

$ echo $TES<Tab>   →  $ echo $TEST <cursor>        # with a space, annoying!
$ echo $TEST<Tab>  →  $ echo $TEST <cursor>        # same
$ echo $TEST/<Tab> →  $ echo /tmp/foo/bar/<cursor> # expands var, annoying!

Compare this with how e.g. tcsh does completion, which is always completing $TES to $TEST/ (if $TEST expands to a directory-name) or to $TEST (if it doesn't) and never expanding anything. Which is, in my arrogant opinion, The Right Thing, and bash has it completely wrong.

So the question is obvious. Is it possible to make bash do The Right Thing too, and if so, how? I tried to understand the manua开发者_JAVA技巧l, but without much success.


Tab completion in Bash is extremely configurable and quite complex. If you are on Ubuntu, maybe note https://bugs.launchpad.net/ubuntu/+source/bash-completion/+bug/769866

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜