【问题标题】:bash completion directory style partial suggestion printingbash完成目录样式部分建议打印
【发布时间】:2013-02-02 07:12:40
【问题描述】:

我正在编写一个名为 to 的脚本,该脚本在 bash 中为文件系统位置添加书签(对 zsh 的支持有限)。你可以在这里找到来源:https://github.com/resultsreturned/to

脚本支持所有操作的tab补全。

假设您已将文件夹的位置“添加为书签”:

mara@andromeda:~/bin/android-sdk-linux$ to -b android

然后脚本允许您访问书签的子文件夹,如下所示:

mara@andromeda:~$ to android/docs/
mara@andromeda:~/bin/android-sdk-linux/docs$ 

按两次tab会给出建议:

mara@andromeda:~$ to android/s<TAB><TAB>
android/samples/        android/sd-card/        android/sources/        android/system-images/  

但是,我宁愿建议仅打印当前未输入到缓冲区的路径部分。例如cd 命令:

mara@andromeda:~/bin$ cd android-sdk-linux/s<TAB><TAB>
samples/       sd-card/       sources/       system-images/ 

请注意,建议仅包含当前输入的目录级别。

所以问题是,如何控制 bash 打印建议的方式?是否可以独立于完成词表(用于 compgen/complete)来执行此操作?有没有办法定义一个正则表达式来处理完成单词列表以作为建议打印?

【问题讨论】:

标签: bash bash-completion


【解决方案1】:

由于对mark a comment as an answer 的功能请求仍然被拒绝,我在此处复制上述解决方案。

因此,当调用complete 时,结果证明是使用-o filenamesShowing only the substrings of COMPREPLY bash completion options to the user - 结果返回

【讨论】:

    猜你喜欢
    • 2011-01-28
    • 2015-12-08
    • 2016-11-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多