选项卡自动完成python CLI

选项卡自动完成python CLI,python,shell,kde,tcsh,Python,Shell,Kde,Tcsh,我只是想知道是否有可能编写一个在shell中运行的Python脚本,以便在用户点击Tab时向用户提供建议 例如,某些应用程序如何限制所支持的文件类型。 我在optParse中找不到这样的东西 理想的情况是: myScript.py[选项卡] (shell打印选项列表) 有什么建议吗?特别是在OpenSuse和tcsh下使用KDE 非常感谢这是shell的一个特性,而不是被调用的Python脚本的特性。有关shell完成的更多信息,请参阅。特别是,您正在寻找。关于如何为git实现这一点,有一个非常

我只是想知道是否有可能编写一个在shell中运行的Python脚本,以便在用户点击Tab时向用户提供建议

例如,某些应用程序如何限制所支持的文件类型。 我在optParse中找不到这样的东西

理想的情况是:

myScript.py[选项卡] (shell打印选项列表)

有什么建议吗?特别是在OpenSuse和tcsh下使用KDE


非常感谢

这是shell的一个特性,而不是被调用的Python脚本的特性。有关shell完成的更多信息,请参阅。特别是,您正在寻找。

关于如何为git实现这一点,有一个非常好的解释。我把它包括在内,但要归功于


我想你在找类似的东西。它为bash实现了一个完成模块,该模块将自动完成任何使用
optpasse
的Python程序的选项。你可以从中得到提示,并将其转化为你所需要的

使用简单的用法描述在bash中启用制表符完成<代码>!命令语法应允许动态筛选文件名。

查看
cmd
模块。具体地说:@KirkStrauser展示了一种使用
readline
执行此操作的方法。这两种解决方案似乎都需要先执行python文件?有什么方法可以帮我:>myScript.py[TAB]解决方案列表谢谢你的链接。很高兴知道这些。是的,我想这可能是很多,但只是想看看是否有可能把它包括在内。谢谢谢谢我去看看,看能不能让它为我工作。谢谢,我可以试着在家里设置,在那里我可以访问zsh和bash。不过,这项工作严格来说是tcsh的,它看起来依赖于一些看起来确实有用的bash基础,正如下面的completat一样。我会在家里尝试,那里有bash/zsh,但工作严格来说是为了可预见的未来。(这是一种痛苦,因为bash/zsh拥有更好的社区)好吧,如果tcsh具有可编程完成功能,那么您可能能够调整optcomplete来为您完成工作。
# Source this script in tcsh to setup shell completions
# for git. Completions are activated by typing or Control-D
# in the shell after entering a partial command.
#
# Usage:
# source git-completion.tcsh (e.g. in ~/.cshrc)
#
# Supported completions:
# git (lists git commands)
# git help (lists git commands)
# git branch (lists branch names)
# git checkout (lists branch names)
# git log (lists the most commonly used flags)
# git remote (lists git remote commands)
# git remote add|prune|rm|show|update
# (lists git remote names)
# In addition to entering where shown, you can enter it after
# typing part of the word, e.g. git branch bug to auto-complete
# branches starting with “bug”.
#
# Author: David Adler, David Aguilar

if ( -x /usr/bin/git) then
# Git is installed so define tcsh completions for it.

# List of known git subcommands
# This is a hard-coded list to avoid calling ‘git help’ at startup.
set __git_cmd_names = (add bisect blame branch checkout clone commit config \
diff diff-files difftool fetch grep gui init log merge mv pull push \
rebase reset rm show shortlog stash status tag)

alias __git_aliases ‘git config –get-regexp “alias.*” | sed -n “s,alias\.\([^ ]*\).*,\1,p”‘
alias __git_branches ‘git for-each-ref –format=”%(refname)” refs/heads refs/remotes | sed -e s,refs/remotes/,, | sed -e s,refs/heads/,,’
alias __git_origin_branches ‘git for-each-ref –format=”%(refname)” refs/remotes/origin | grep -v HEAD | sed -e s,refs/remotes/origin/,,’

# Define the completions (see the tcsh man page).
complete git \
‘p/1/`__git_aliases | xargs echo $__git_cmd_names`/’ \
“n/help/($__git_cmd_names)/” \
‘n/branch/`__git_branches | xargs echo -m -d`/’ \
‘n/config/(–global –get-regexp –list)/’ \
‘n/diff/`__git_branches | xargs echo –check –staged –stat — *`/’ \
‘n/difftool/`__git_branches | xargs echo –no-prompt –staged — *`/’ \
‘n/fetch/`git remote`/’ \
‘n/merge/`__git_branches`/’ \
‘n/log/`__git_branches | xargs echo — –name-only –name-status –reverse –committer= –no-color –relative –ignore-space-change –ignore-space-at-eol –format=medium –format=full –format=fuller`/’ \
‘n/stash/(apply list save pop clear)/’ \
‘n/push/`git remote`/’ \
‘N/push/`__git_origin_branches`/’ \
‘n/pull/`git remote | xargs echo –rebase`/’ \
‘n/–rebase/`git remote`/’ \
‘N/–rebase/`__git_origin_branches`/’ \
‘N/pull/`__git_origin_branches`/’ \
‘n/rebase/`__git_branches | xargs echo –continue –abort –onto –skip –interactive`/’ \
‘N/rebase/`__git_branches`/’ \
‘n/remote/(show add rm prune update)/’ \
‘N/remote/`git remote`/’ \
‘n/checkout/`__git_branches | xargs echo -b –`/’ \
‘N/-b/`__git_branches`/’
endif