1 unstable release

0.1.0 Jan 4, 2021

#56 in #argument

Apache-2.0

18KB
371 lines

abra Actions Status GitHub release

A tool that makes data sharing between terminal windows easy.

abra can be used for displaying info about the current working directory, for splitting stdout and stderr and much more.

File tree demo

Table of contents

Installation

The recommended way to install abra is by running:

brew install denisidoro/tools/abra

You can also run:

cargo install abra-cli

If these package managers aren't available, you can download a pre-compiled binary here and extract it to your $PATH.

Basic concepts

  • abra is built over Unix sockets
  • it can publish and subscribe to channels, manipulating text as necessary
  • no terminal multiplexers are necessary

Common use cases

Some abra calls are quite verbose, so the use of aliases is recommended.

File tree sidebar

Since this is a very common use case, abra provides a hook for you.

If you call the following...

eval "$(abra hook bash)" # If you use bash, add this to ~/.bashrc
eval "$(abra hook zsh)" # If you use zsh, add this to ~/.zshrc

Then you can open a new terminal window and call abra rx --channel pwd --cmd 'ls {}'.

Whenever you cd into a directory, the sidebar will reflect the changes.

Split stdout and stderr into different windows

Let's say that you want to run some tests but errors should appear in a different window.

You can use anonymous pipes with abra for that purpose:

Split demo

The commands are:

abra rx --channel test_out # window 1
abra rx --channel test_err # window 2
cargo test > >(abra tx --channel test_out) 2> >(abra tx --channel test_err) # window 3

Filter some output lines

Let's say you want to see the contents of a file in a window but show only the lines that contain "foo" in another window:

abra rx --channel filter --cmd 'echo "{}" | grep foo' # window 1
cat myfile.txt |& tee >(abra tx --channel filter) # window 2

Forcing colorized output

Some CLIs will detect that they are being piped and will hide color information by default.

To circumvent this, each CLI may offer different paramenters: --color=always and export COLORTERM=truecolor are some examples.

In some cases, you need to trick an application into thinking its stdout is a terminal, not a pipe. For these cases you can call abra faketty --cmd '<your command>'.

Advantages over named pipes

In theory, you could run the following to achieve similar results:

mkfifo tmp
tail -f tmp
echo foo > tmp # in another window

That said:

  • with abra you don't need to worry about creating/removing named pipes
  • echo foo > tmp is blocking in case tmp isn't open for reading
    • abra tx will terminate immediately if there's no abra rx process
  • you can have many abra rx windows reacting to the same abra tx call
  • abra is cross-platform
    • to correctly create temporary named pipes you need to write platform-specific code

Similar tools

Etymology

Abra is a Pokémon who is able to teleport.

Dependencies

~4–11MB
~123K SLoC