Coder Social home page Coder Social logo

xontrib-hist-format's Introduction

Format xonsh history to post it to Github or another page.

The mission of xontrib-hist-format is to make commands repeatable, copy-pastable and save time to preparing.

If you like the idea click โญ on the repo and stay tuned.

Installation

xpip install xontrib-hist-format
# or: xpip install -U git+https://github.com/anki-code/xontrib-hist-format

Usage

xontrib load hist_format
hist-format --help         # Basic command
hist-md                    # Markdown format shortcut
hist-txt                   # Text format shortcut

Arguments:

usage: hist-format [-h] [-f FORMAT] [-c COMMANDS_COUNT] [-l]
                   [-H [OUTPUT_HEAD_COUNT]] [-T [OUTPUT_TAIL_COUNT]]
                   [-m] [--lines]

Format xonsh history to post it to Github or another page.

optional arguments:
  -h, --help            show this help message and exit
  -f FORMAT, --format FORMAT
                        Format: md, txt.
  -c COMMANDS_COUNT, --commands-count COMMANDS_COUNT
                        Count of commands
  -l, --commands-list   Show commands in distinct section.
  -H [OUTPUT_HEAD_COUNT], --output-head-count [OUTPUT_HEAD_COUNT]
                        Count of lines from output head to show.
  -T [OUTPUT_TAIL_COUNT], --output-tail-count [OUTPUT_TAIL_COUNT]
                        Count of lines from output tail to show.
  -m, --min             Make block minimized i.e. by adding <details> tag in Markdown.
  --lines               Add additional lines before and after.

Note! The clear command is used as marker of the beginning of commands list. If you run commands 1, 2, 3 then run clear, and run 4, 5, 6 and finally run hist-md it will show 4, 5, 6 commands. Feel free to open an issue with feedback on this approach.

Example

Run commands:

echo 123
ls / | head -n 3

Run hist-format:

hist-md -c 2 -l --lines    # latest 2 commands + commands list + header and footer as line

As result you will get the output that you can copy and paste to the Github comment or md-file:


Output:

echo 123
#123

ls / | head -n 3
#boot
#cdrom
#dev

# Prepared by xontrib-hist-format

Commands:

echo 123
ls / | head -n 3

# Prepared by xontrib-hist-format

You can disable the "Prepared by" message by setting XONTRIB_HIST_FORMAT_FOOTER = '' in your environment. If you like this xontrib, tell your friends!


Clipboard

You can redirect the output to clipboard. Example for xclip:

hist-md | xclip

Known issues

Not every command has output in the __xonsh__.history.

Workaround in some cases is to use pipe into head i.e. cat file | head.

Not working after xonsh 0.10.0 (4283)

Workaround: Check XONSH_CAPTURE_ALWAYS environment variable to bring the capturing of the output back.

Credits

xontrib-hist-format's People

Contributors

anki-code avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

playfloor

xontrib-hist-format's Issues

Space before the output?

How about adding a space before the command output?

Current

Output:

echo hi
#hi

echo bye
#bye

# Prepared by xontrib-hist-format

With space

Output:

echo hi
# hi

echo bye
# bye

# Prepared by xontrib-hist-format

Short output

This is really cool!

It seems that I can't get output without the links to the xontrib and without both commands and output sections..
Could you maybe add a flag for short output/make the default short?

When I run echo hi and then hist-md -c1:

Current output

History output:

echo hi
#hi

History commands:

echo hi

What I really want

echo hi
#hi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.