作为REPL环境运行命令
项目描述
关于
将任何bash命令转换为REPL
具有bash补全功能
具有vi模式
具有PS1解析(实验性)
在$XDG_DATA_HOME/ptrepl/history中存储历史记录
类似bash的历史记录扩展
列出历史记录
命令模式
别名
安装
需要 python>=3.6,prompt_toolkit>=2.0.7,<3.0.0,pygments
推荐的安装方式是通过 pipx
pipx install ptrepl
用法
基本用法
$ ptrepl --help
Usage: ptrepl [OPTIONS] COMMAND
Options:
--prompt TEXT Override prompt
--help Show this message and exit.
$ ptrepl git
$ git >
# to call "git status"
$ git > status
# if you need execute some other bash command see system mode below
自定义提示命令
$ ptrepl git --prompt g
$ g >
多词命令
$ ptrepl "echo prefix"
$ echo prefix > 1
echo prefix 1
配置
将设置文件放置在 :bash:$XDG_CONFIG_HOME/ptrepl/config.json
以下是启用vi模式和git别名的配置示例
{
"settings": {
"EXIT_COMMAND": "exit",
"EDITING_MODE": "vi",
"SHOW_MODE_IN_PROMPT": true,
"EMACS_MODE_STRING": "@",
"VI_INS_MODE_STRING": "+",
"VI_CMD_MODE_STRING": ":",
"READLINE_COMPLETION": false,
"PARSE_PS1": false,
"LOCAL_SHADA": false,
"LOCAL_SHADA_PATH": "$PWD/.ptrepl/",
},
"alias": {
"git st": "git status"
}
}
可用设置
EXIT_COMMAND - 更改退出命令
EDITING_MODE - 选择模式 vi/emacs
SHOW_MODE_IN_PROMPT - 在提示中显示编辑模式字符串
EMACS_MODE_STRING - 设置emacs模式提示字符串
VI_INS_MODE_STRING - 设置vi插入模式提示字符串
VI_CMD_MODE_STRING - 设置vi命令模式提示字符串
READLINE_COMPLETION: 使用类似readline的补全而不是下拉补全
PARSE_PS1 {实验性} - 尝试根据您的PS1设置调整ptrepl的提示
LOCAL_SHADA - 在LOCAL_SHADA_PATH中存储shada(历史记录)
LOCAL_SHADA_PATH - 本地shada的路径
默认设置
{
"EXIT_COMMAND": "exit",
"EDITING_MODE": "emacs",
"SHOW_MODE_IN_PROMPT": false,
"EMACS_MODE_STRING": "@",
"VI_INS_MODE_STRING": "(ins)",
"VI_CMD_MODE_STRING": "(cmd)",
"READLINE_COMPLETION": false,
"PARSE_PS1": false,
"LOCAL_SHADA": false,
"LOCAL_SHADA_PATH": "$DIRENV_DIR/.direnv/ptrepl/",
}
功能
解析PS1(需要将PARSE_PS1设置为true)
这是我的bash提示(PS1)的默认外观
{ptrepl} ~/Development/Python/ptrepl [master] |19:18:36 07-Feb-18|
+ ❯ ptrepl git
{ptrepl} ~/Development/Python/ptrepl [master] |19:20:15 07-Feb-18|
+ git ❯
补全
$ ptrepl git
$ git > sta (press TAB)
# result
$ git > sta
status
stage
stash
类似readline的补全(需要将READLINE_COMPLETION设置为true)
$ ptrepl git
$ git > sta (press TAB)
# result
$ git > sta
stage stash status
系统模式
$ ptrepl git
$ git > (press Escape + !)
# result
# you could enter your shell commands here
Shell command: ls
命令模式
$ ptrepl git
$ git > (press Escape + :)
# result
# you could enter your command mode commands here
# to list history
Command mode: history
类似 Bash 的历史扩展
$ ptrepl git
$ git > status
# repeat last command
$ git > !!
# repeat 10th command
$ git > !10
# repeat 10th command from bottom of history stack
$ git > !-10
类似别名
$ ptrepl git
$ git > (press Escape + :)
# you could enter your command mode commands here
# to list alias
Command mode: alias
alias "git st"="git status"
$ git > st
类似项目
用 Ruby 编写
用 Bash 编写
用 Python 编写
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。
源代码分发
ptrepl-0.9.8.tar.gz (19.2 kB 查看哈希值)
构建分发
ptrepl-0.9.8-py3-none-any.whl (21.1 kB 查看哈希值)