Package: xontrib-rerun
xontrib-rerun===============================version number: 0.1.01author: Kevin MarilleauOverview--------Rerun previous commandsInstallation------------To install use pip:$ xpip install xontrib-xontrib-rerunOr clone the repo:| $ git clone https://github.com/kmarilleau/xontrib-rerun.git| $ xpip install ./xontrib-rerunUsage-----| $ rerun [--edit <editor>] [--startswith <sw>] [--contain <ct>]...| $       [--replace <old=new>]... [--confirm]| $ rerun LEN [OFFSET] [options] [-C <ct>]... [-R <old=new>]... [-c | --confirm-each]| $ rerun (-h | --help)| $ rerun rerun [<index>] [--confirm | --confirm-each]| $ rerun rerun list| $ rerun (-h | --help)Commands--------| $ list                     View current history.| $ ls                       Alias for ``list``.| $ rerun                    Re-execute commands that have already been executed.Arguments---------| $ LEN                      Number of commands to re-execute.| $ OFFSET                   Re-execute commands before n last commands.| $ INDEX                    Index of commands in ``rerun rerun list``.Options-------| $ -h, --help               Do we really need to explain?| $ -c, --confirm            View commands and confirm their execution.| $ --confirm-each           Confirm the execution of each command.| $ -e, --edit <editor>      Edit commands.| $ -C, --contain <ct>       Rerun from last command containing <ct>.| $ -S, --startswith <sw>    Rerun from last command starting with <sw>.| $ -R, --replace <old=new>  Replace all substring in selected commands.| $ --eq                     Rerun only if len of selected commands == LEN.Description-----------Let's assume that our history looks like this:>>> git init myproject && cd myproject>>> touch Dockerfile \\...   && echo 'FROM nginx' >> Dockerfile \\...   && echo 'WORKDIR /usr/share/nginx/html/' >> Dockerfile \\...   && echo 'RUN echo "<h1>Foo</h1>" > index.html' >> Dockerfile>>> docker build . -t last_build>>> docker run --rm -it -p 8080:80 last_buildWe created a Dockerfile, we built a docker image with it. Then we runned acontainer that uses this image.|  Note:|      All these commands work, you can launch them on your shell and then see|      the result from your browser at http://localhost:8080.If we decide to stop the container with Ctrl+C and recreate the same container,many shells offer to find and re-execute the last command by press 'Up Arrow'then 'Enter'. Otherwise, you can do the same thing by simply typing:>>> rerunWe stop our container with Ctrl+C, we run the commands below to check thatour container is no longer running:>>> docker psLet's add the Dockerfile to our project and then make our first commit:>>> git add Dockerfile>>> git commit -am "create Dockerfile"Now let's suppose that we need to modify the Dockerfile:>>> echo 'RUN echo "<h1>Bar</h1>" >> index.html' >> DockerfileIf we run ``rerun list`` or ``rerun ls``, We can see our history look like this:10: rerun ls09: git init myproject && cd myproject08: touch Dockerfile \\&& echo 'FROM nginx' >> Dockerfile \\&& echo 'WORKDIR /usr/share/nginx/html/' >> Dockerfile \\&& echo 'RUN echo "<h1>Foo</h1>" > index.html' >> Dockerfile07: docker build . -t last_build06: docker run --rm -it -p 8080:80 last_build05: rerun04: docker ps03: git add Dockerfile02: git commit -am "create Dockerfile"01: echo 'RUN echo "<h1>Bar</h1>" >> index.html' >> DockerfileTo see the result in our browser, we need to re-execute commands below:>>> docker build . -t last_build>>> docker run --rm -it -p 8080:80 last_buildTo do this, we just have to run:>>> rerun 2 5It means:"Restarts the two commands before the last five commands that have beenexecuted."If we want to see selected commands before and confirm their execution, we onlyneed to add '--confirm' option:>>> rerun 2 5 --confirmIf we want to see and confirm execution of each command, we can do this:>>> rerun 2 5 --confirm-eachLet's update our Dockerfile in our git branch, make another commit, then viewand confirm results commands:>>> rerun 2 -S 'git add' --replace create=update -cIt means:"Restart the two commands from the first latest command starting with'git add', replace all 'create' substrings by 'update' then show me theresult and let me confirm execution"The commands to be executed should now look like this:>>> git add Dockerfile>>> git commit -am "update Dockerfile"If instead we wanted to change the name of the Dockerfile by Mydockerfile, makea commit, then view and confirm commands, do:>>> rerun 2 -c -S 'git add' \\...            -R create=rename \\...            -R 'add Dockerfile'='mv Dockerfile Mydockerfile'|  Note:|      You can use single/double quotes and even none with ``--replace``|      arguments. Just remember to escape quotes from your sub-chains.|      See examples below:||      >>> rerun --replace old="new"|      >>> rerun --replace "For what it's worth"='Buffalo Springfield'|      >>> rerun --replace TVSeries='That\\'s 70 Show'As you can see, you can replace as many substrings as you want.But, you can quickly find it tiring to make all these changes with the commandline. You can use an editor with --edit instead of --replace:To use it, simply add the option --edit (or -e):>>> rerun 2 -c -S 'git add' --editModify your text and quit the editor.|  Warning:|      All comments are deleted when you exit the text editor.If you have not specified one, rerun use $RERUN_EDITOR as default editor. And$RERUN_EDITOR points directly to $EDITOR if you have not assigned a value to it.For example, if you want to use nano as default editor for rerun, add``$RERUN_EDITOR = nano`` to your .xonshrc.Now let's imagine that we need to re-execute commands that have already beenre-executed. Let's start by listing the commands:>>> rerun rerun list4: docker run --rm -it -p 8080:80 last_build3: docker build . -t last_builddocker run --rm -it -p 8080:80 last_build2: git add Dockerfilegit commit -am "update Dockerfile"1: git mv Dockerfile Mydockerfilegit commit -am "rename Dockerfile"If you need to re-execute the last re-executed commands, just run:>>> rerun rerunElse, just specified index of commands:>>> rerun rerun 3Like the rerun command, you can use modifiers and confirm arguments like``--replace``, ``--edit``, ``--confirm`` or ``--confirm-each``:>>> rerun rerun 3 -e nano -cCredits---------This package was created with cookiecutter_ and the xontrib_ template... _cookiecutter: https://github.com/audreyr/cookiecutter.. _xontrib: https://github.com/laerus/cookiecutter-xontrib