Skip to main content
https://travis-ci.com/imomaliev/ptrepl.svg?branch=master https://badge.fury.io/py/ptrepl.svg

About

Make REPL out of any bash command

  • has bash completion

  • has vi mode

  • has PS1 parsing(experimental)

  • stores history in $XDG_DATA_HOME/ptrepl/history

  • bash like history expansion

  • list history

  • command mode

  • aliases

Installation

Requires python>=3.6, prompt_toolkit>=2.0.7,<3.0.0, pygments

Recommended way of installation is via pipx

pipx install ptrepl

ptrepl vendors https://github.com/xonsh/py-bash-completion

Usage

Basic Usage

$ 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

Custom prompt command

$ ptrepl git --prompt g
$ g >

Multiword command

$ ptrepl "echo prefix"
$ echo prefix > 1
echo prefix 1

Config

Place settings file in :bash:$XDG_CONFIG_HOME/ptrepl/config.json

Here is example of config with enabled vi mode and git alias

{
    "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"
    }
}

Available settings

  • EXIT_COMMAND - change exit command

  • EDITING_MODE - choose mode vi/emacs

  • SHOW_MODE_IN_PROMPT - show editing mode string in prompt

  • EMACS_MODE_STRING - set emacs mode prompt string

  • VI_INS_MODE_STRING - set vi insert mode prompt string

  • VI_CMD_MODE_STRING - set vi command mode prompt string

  • READLINE_COMPLETION: use readline like completion instead of dropdown one

  • PARSE_PS1 {experimental} - will try to adgust ptrepl’s prompt according to your PS1 setting

  • LOCAL_SHADA - store shada(history) in LOCAL_SHADA_PATH

  • LOCAL_SHADA_PATH - path to local shada

Default settings

{
    "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/",
}

Features

Parsing PS1(requires PARSE_PS1 set to true)

Here is how my bash prompt(PS1) looks like by default

{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 ❯

Completion

$ ptrepl git
$ git > sta (press TAB)
# result
$ git > sta
        status
        stage
        stash

Readline like completion(requires READLINE_COMPLETION set to true)

$ ptrepl git
$ git > sta (press TAB)
# result
$ git > sta
stage  stash  status

System mode

$ ptrepl git
$ git > (press Escape + !)
# result
# you could enter your shell commands here
Shell command: ls

Command mode

$ ptrepl git
$ git > (press Escape + :)
# result
# you could enter your command mode commands here
# to list history
Command mode: history

Bash like history expansion

$ ptrepl git
$ git > status
# repeat last command
$ git > !!
# repeat 10th command
$ git > !10
# repeat 10th command from bottom of history stack
$ git > !-10

Bash like aliases

$ 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

Similar projects

Written in Ruby

https://github.com/defunkt/repl

Written in Bash

https://github.com/joh6nn/shrepl

https://github.com/mchav/with

Written in Python

https://github.com/mbr/repl

https://github.com/renanivo/with

Metadata

Release files for ptrepl 0.9.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ptrepl 0.9.8
File Size Uploaded
ptrepl-0.9.8.tar.gz 19.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ptrepl 0.9.8
File Interpreter ABI Platform
ptrepl-0.9.8-py3-none-any.whl Python 3 none any Details

Total release size: 40.2 kB

Release files / ptrepl-0.9.8.tar.gz

Download URL ptrepl-0.9.8.tar.gz
Size 19.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f7fba6ade029b4d1930c613cc8464077a784938e9cb4591673bebbebf5aedba0
BLAKE2b-256 checksum
How to use checksums
eba690ecb8e2fc14118d8a91cb6f39a26dc755e4f15bca0b7783c53b4e56a032
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.1 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.7.1

Release files / ptrepl-0.9.8-py3-none-any.whl

Download URL ptrepl-0.9.8-py3-none-any.whl
Size 21.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fb7a50dbc769d1428a87c1227d9b4fe3dfdfee8321782dbe4be2a2b746970bde
BLAKE2b-256 checksum
How to use checksums
f7ed6ca02c9504a9d1a71bd2893d31f486633ddc90e27a343fa3a8306ac8dd8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.1 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.7.1

Release history Release notifications | RSS feed

This release

0.9.8 This release

2 release files

0.9.7

2 release files

0.9.6

2 release files

0.9.5

2 release files

0.9.4

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.4

2 release files

0.8.3

2 release files

0.8.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page