有用的xonsh-shell命令/别名函数
项目描述
xontrib-commands
有用的xonsh-shell命令/别名/补全函数
安装
使用pip进行安装
xpip install xontrib-commands
# or: xpip install -U git+https://github.com/jnoortheen/xontrib-commands
用法
xontrib load commands
构建别名
使用 xontrib_commands.argerize:Command
来构建你函数的 arger 分派器。这将创建一个带有自动补全支持的漂亮别名函数。
from xontrib_commands.argerize import Command
@Command.reg
def record_stats(pkg_name=".", path=".local/stats.txt"):
stat = $(scc @(pkg_name))
echo @($(date) + stat) | tee -a @(path)
- 也支持直接传递
Arger
实例。
from xontrib_commands.argerize import Arger, Command
arger = Arger(prog="tst", description="App Description goes here")
@arger.add_cmd
def create(name: str):
"""Create new test.
:param name: Name of the test
"""
print(locals())
@arger.add_cmd
def remove(*name: str):
"""Remove a test with variadic argument.
:param name: tests to remove
"""
print(locals())
Command.reg(arger)
现在完整的CLI已准备就绪
$ record-stats --help
usage: xonsh [-h] [-p PKG_NAME] [-a PATH]
optional arguments:
-h, --help show this help message and exit
-p PKG_NAME, --pkg-name PKG_NAME
-a PATH, --path PATH
命令
- 一旦加载了xontrib,以下命令即可使用。
1. reload-mods
usage: reload-mods [-h] name
Reload any python module in the current xonsh session.
Helpful during development.
positional arguments:
name Name of the module/package to reload. Giving partial names matches all the nested modules.
optional arguments:
-h, --help show this help message and exit
Examples
-------
$ reload-mods xontrib
- this will reload all modules imported that starts with xontrib name
Notes
-----
Please use
`import module` or `import module as mdl` patterns
Using
`from module import name`
will not reload the name imported
2. report-key-bindings
usage: report-key-bindings [-h]
Show current Prompt-toolkit bindings in a nice table format
optional arguments:
-h, --help show this help message and exit
3. dev
dev - A command to cd into a directory. (Default action)
Usage:
dev [COMMAND] [OPTIONS] [NAME]
Arguments:
[NAME] - name of the folder to cd into. This searches for names under $PROJECT_PATHS or the ones registered with ``dev add``
Options:
--help [SUBCOMMANDS...] - Display this help and exit
Commands:
add - Register the current folder to dev command.
When using this, it will get saved in a file, also that is used during completions.
ls - Show currently registered paths
load-env FILE - Load environment variables from the given file into Xonsh session
Using https://github.com/theskumar/python-dotenv
Run "dev COMMAND --help" for more information on a command.
4. parallex
usage: parallex [-h] [-s] [-n] [-c] [args ...]
Execute multiple subprocess in parallel
positional arguments:
args individual commands need to be quoted and passed as separate arguments
options:
-h, --help
show this help message and exit
-s, --shell
each command should be run with system's commands
-n, --no-order
commands output are interleaved and not ordered
-c, --hide-cmd
do not print the running command
Examples
--------
running linters in parallel
$ parallex "flake8 ." "mypy xonsh"
项目详情
下载文件
下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。
源代码发行版
xontrib-commands-0.4.4.tar.gz (10.9 kB 查看哈希值)
构建发行版
xontrib_commands-0.4.4-py3-none-any.whl (12.2 kB 查看哈希值)