2 unstable releases
0.3.0 | Oct 2, 2024 |
---|---|
0.1.0 | Sep 21, 2024 |
#1486 in Command line utilities
204 downloads per month
36KB
711 lines
Argument execute is xargs alternative that focus on arguments processing and ordering.
This tool is still under heavy development
Table of Contents
Features
Placing arguments in defined order
echo "foo bar baz" | axe echo {2} {1} {0}
output: baz bar foo
Processing input as data series
echo "a b c\nd e f" | axe echo {}
output:
a b c
d e f
Explanation: Each new line is treated as a data entry. Echo command will be run for each line. This is equal to calling
echo a b c
echo d e f
Arguments splitting for individual arguments
echo "lord_of_the_rings.txt" | axe echo "this is file name '{0.0}' and this is file extension '{0.1}'"
output: this is file name 'lord_of_the_rings' and this is file extension 'txt'
Arguments splitting for array arguments
echo "a_b c_d e_f" | axe echo {_0}
output: a c e
Installation
Archives of precompiled binaries for axe are available for Linux and macOS.
With dra
dra download -i -a -o ~/.local/bin jacek-kurlit/axe
With eget
eget jacek-kurlit/axe --to=~/.local/bin
If you're a Rust programmer, axe can be installed with cargo
.
cargo install axe-cli
How does axe work?
Entries and command execution
Lets consider the following example stdin input:
a b c
d e f
h i j
If we pass it to axe echo {}
axe will call echo 3 times for each line.
On each line space will be treated as an arguments separator.
As result axe will resolve and call echo like this:
echo a b c
echo d e f
echo h i j
Arguments resolution
Each entry line will be split by arguments separator that can be chosen by the user (by default space). You may then refer to each argument by its index. For example:
echo "a b c" | axe echo {0}
There is only one entry with 3 arguments.
Echo will print first argument which is a
.
Arguments splitting
Each argument can be splitted into multiple arguments. For example:
echo "a.b c.d e.d_f.g" | axe echo {1.1} {0.0} {2_0}
Axe will read this as follows:
- {1.1} split second argument ('c.d') by '.' and choose second part (
d
) - {0.0} split first argument ('a.b') by '.' and choose first part (
a
) - {2_0} split third argument ('e.d_f.g') by '_' and choose first part (
e.d
)
Arguments resolving into arrays
Arguments can be resolved into arrays. For example:
echo "f1.txt f2.txt f3.txt" | axe echo {.0}
Axe will read this as follows:
{.0} split all arguments by '.' and for each item choose first part (f1, f2, f3
)
You may split each argument into multiple items
echo "f1.txt f2.txt f3.txt" | axe echo {0.} {1}
Axe will read this as follows:
{0.} split first argument by '.' and choose all parts (f1, txt
)
{1} take second argument(f2.txt
)
Output f1 txt f2.txt
Motivation
Every time I was using xargs command I was frustrated that I cannot tell where I want to place arguments. This missing feature made me decide to create my own tool.
Development
Setup
Building
git clone https://github.com/jacek-kurlit/axe
cd axe
cargo build --release
./target/release/axe --version
Special thanks to
Dependencies
~3MB
~33K SLoC