如何在bash中更改標簽自動完成功能以瀏覽文件夾?

[英]How do I alter tab autocomplete in bash to dive through folders?


I have a folder 'test' which contains another folder 'test2'

我有一個文件夾'test',其中包含另一個文件夾'test2'

When I type 'cd te[tab]' it auto-completes to 'cd test/'

當我輸入'cd te [tab]'時,它會自動完成'cd test /'

How do I make it autocomplete to 'cd test/test2/', without hitting tab again?

如何讓它自動完成'cd test / test2 /',而不再次點擊標簽?

To clarify: test is the only folder/file in the folder test. I want this to work recursively so if there is a folder/with/a/lot/of/single/files/or/folders/in/it

澄清一下:test是文件夾測試中唯一的文件夾/文件。我希望這個遞歸工作,所以如果有一個文件夾/與/ a / lot / of / single / files /或/ folders / in / it

2 个解决方案

#1


Bash supports programmable auto completion (at least since version 3.0). There is some documentation in the bash manual on

Bash支持可編程自動完成(至少從3.0版本開始)。 bash手冊中有一些文檔

http://www.gnu.org/software/bash/manual/bashref.html#Programmable-Completion

It might also be a good idea to look at existing scripts to get an idea how to really make use of that feature. Debian for example has a /etc/bash_completion file with completion scripts for various programms. I'm sure other distributions have something similar

查看現有腳本以了解如何真正使用該功能也可能是一個好主意。例如,Debian有一個/ etc / bash_completion文件,其中包含各種程序的完成腳本。我相信其他發行版也有類似之處

#2


It is hard for bash to understand either you want to jump to test or to test/test. So I believe there is no standard settings.

bash很難理解你想要跳轉到測試或測試/測試。所以我相信沒有標准設置。

But you can always alias commands for particular cases like

但是你總是可以為特定情況命名別名命令

alias cdtest="cd test/test"

注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2009/04/01/72f43863f5ff4945c323d9af000348e4.html



 
粤ICP备14056181号  © 2014-2021 ITdaan.com