简体   繁体   English

Bash - 选项卡上的预期文件扩展名

[英]Bash - expected file extension on tab

I'm not sure if this is something that can be done in the Linux/Unix terminal, so I thought I'd ask. 我不确定这是否可以在Linux / Unix终端中完成,所以我想我会问。

For certain programs (unfortunately I can't think of any besides bibtex off the top of my head, which on tab auto-'extends' the .aux extension) when I'm finished typing out the file name (minus dot and extension) in front of it, I've noticed that if I hit tab it will 'auto-complete' the dot + file extension. 对于某些程序(不幸的是,当我输入完文件名(减去点和扩展名)时,我不能想到除了bibtex之外的任何东西,在tab上自动''扩展'.aux扩展名)在它面前,我注意到如果我点击tab ,它将“自动完成”点+文件扩展名。

Is this something you can actually control somehow ? 这是你可以实际控制的东西吗? For example, if I wrote a bash script (we'll call it compile.sh ) that only worked with *.tex files, I could do the following: 例如,如果我编写了一个仅与* .tex文件一起使用的bash脚本(我们称之为compile.sh ),我可以执行以下操作:

$ ./compile.sh nameOfProgram -- tab and autocomplete .tex extension -- 

Certainly it's not inherent to the bash script itself, but by some other means that recognizes I'm using said executable. 当然,它不是bash脚本本身所固有的,而是通过其他一些方法来识别我正在使用所述可执行文件。

Sometimes, as is often the case while using LaTeX, there are multiple files with the same base name but different extensions in the same directory - I would like it to only accept that which has the predefined extension. 有时,与使用LaTeX时的情况一样,有多个文件在同一目录中具有相同的基本名称但扩展名不同 - 我希望它只接受具有预定义扩展名的文件。

It is certainly possible to define a custom completion function for compile.sh which only matches *.tex files. 当然可以为compile.sh定义一个自定义完成函数,它只匹配*.tex文件。 Writing a good completion function is a broad task, but you can do something very simple with 编写一个好的完成函数是一项广泛的任务,但你可以做一些非常简单的事情

# Add to your .bashrc file to enable in every shell, not just
# the current shell
complete -G '*.tex' compile.sh

which will only treat files matching *.tex as valid completions for any argument to compile.sh . 只会将匹配*.tex文件视为compile.sh任何参数的有效完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM