pier-cli / pier Goto Github PK
View Code? Open in Web Editor NEWA Linux script management CLI written in Rust
License: MIT License
A Linux script management CLI written in Rust
License: MIT License
I think it would be cool if we had some sort of platform where we can share scripts, workflow examples, extensions etc. I always appreciate learning about other people's workflows and it feels appropriate to have something like that considering the tool. It's also a good place to increase the documentation and link to related tools.
pfz() {
pier list -q \
| fzf -m --preview 'pier show {} | bat --color=always' \
--bind 'ctrl-y:execute(pier show {} | xsel -b)+abort' \
| xargs -n 1 -I {} pier run {}
}
As someone looking to try out pier, it would be nice if I could just "cargo install" it, and not have to worry about manually needing to keep it updated.
Hi, I'm trying to add a one-liner with this snippet in it:
sed -r "s/^[0-9.]+\s+//"
However, when it gets parsed, this part of the command transforms to:
sed -r s/^[0-9.]+s+//
Once I replaced \s
with [ ]
, the command parsed correctly. Is this a bug or something I have to work around?
Was looking into how the commands were being run and noticed that commands with | or ' doesn't work by default and thought I would document it as an issue.
However both | and ' does work if you wrap it in for example bash -c as seen in the config at the bottom.
Perhaps this issue could be solved by wrapping all commands in the default shell from the environment variable $SHELL?
Might also be a good idea when creating new commands through the cli to save them as string literals in the toml config file, it helps avoid a lot of escaping.
[scripts.pass-me]
alias = "pass-me"
command = '''bash -c "echo 'hello'" '''
[scripts.fail-me]
alias = "fail-me"
command = '''echo 'hello' '''
[scripts.fail-me-2]
alias = "fail-me-2"
command = '''echo 1001_hello_1001 | grep -oe "_\\s+_"'''
[scripts.pass-me-2]
alias = "pass-me-2"
command = '''bash -c "echo 1001_hello_1001 | grep -oe "_\\s+_""'''
Currently it's a bit hard to pipe the output of pier into anything else as there is a bit of boiler plate in the run output. I've been thinking a bit about how to solve this, some of my ideas are:
Personally I think the best option would be to move it to only print in verbose mode, I think it can be nice to see sometimes. But usually you want to be able to do something with the output and having to use a flag every time you want to pipe pier to something else could get a bit annoying.
I'd love to hear your opinion Ben / anyone else :)
Hi, just getting started with the tool, so I may have overlooked something!
From what I understand, we are meant to create our own config file and store the path as an environment variable for pier, right?
Would it be beneficial to have pier automatically generate a config file (and store it in /usr/bin or something) by default? Or is this against the vision/idea in some way?
Adding the option to programatically export the pier data would be a nice feature and would make it a lot easier to make 3rd plugins to pier, especially if we're planning on adding more complex features.
I think it would be nice to keep it relatively open and use an output flag with a parameter format, which we could expand upon later. e.g.
-o json
/ --output json
instead of:
-j
/ --json
Currently the config has a duplicate definition of the script alias, would be nice to remove one of them. Will probably require a bit of code shuffling to make work though.
[scripts.this-is-the-alias]
alias = 'this-is-the-alias'
command = '''
#!/bin/sh
echo "Hello $1, my name is $2. -- script $0"
'''
Perhaps pier should pass on some variables to the script with basic pier information?
Some examples:
PIER_ALIAS=<alias>
PIER_COMMAND=pier run <alias> -c /path/to/config
PIER_CONFIG=/path/to/config
PIER_VERSION=0.1.x
PIER_STARTED_UNIX=1583917662
PIER_STARTED_UTC=2020-03-11T09:08:16Z
This option would make migrating existing shell scripts to pier a lot easier!
echo 'for i in {1..10}; do echo $i; done' | pier add -a count_to_ten
Perhaps in the future we could add a json input option as well where you dump the whole script struct into stdin. :)
I often find myself typing pier ls
instead of list
- probably because of being used to that with Docker, and the ls
CLI tool. It should be fairly easy having two options for listing. Another thought was whether the default when running pier
should be to list, as that's quite a common task? Feedback welcome! Maybe I'll take this on, haven't been active in a while.
Currently the description field is declared in the Script struct, however it doesn't have a cli option and isn't being represented in the table list output.
I would suggest these options: -d
/ --decription
.
The args feature has been mocked up for a while and I've had it in the back of my mind how it would be good to implement it, initially I was thinking you could just do some templating but I pretty soon realized that it's a pretty big security flaw as you could then literally inject code before you run it.
Right now I'm leaning towards the best option would be to implement arguments/options as env variables, perhaps via a key/value cli arg with the ability to set defaults for a tag/script in the configt.
I imagine the cli option for setting environment variables to something like -E/--env it could look something like this perhaps:
pier run build_something -E RUST_BACKTRACE:1 -E DB_HOST:127.0.0.1
Adding optional pager would be really nice and it's pretty convient to do with the pager crate.
-p <my pager>
--pager <my pager>
use_pager = true // Sets wheter to page by default
PAGER
PIER_PAGER
-p
/ --pager
(cli)Pier is lacking shell completions at the moment for all the cli options, however since pier is using clap / structopt this does not seem relatively easy to do.
To start with perhaps we should limit it to bash / zsh just to keep it simple, however it seems like it's possible to generate powershell / fish completions via clap as well.
I'm not sure how well pier works on windows right now at least, but I'd be curious to know.
docs.rs about the shell generation in clap
structopt example code for generating shell completions
Currently pier won't exit unsuccessfully even if the script being run does.
One way to do this would be to check for an unsucessful exit with the Output struct that we get back from the command and if it's unsucessful return an error like ScriptError with pier_err! and then in the main function compare the error returned using the EnumKind proc macro that is applied to the PierError enum.
An example of this type of comparison on errors can be found in these files tests/macros.rs and test/error_handling.rs.
Links:
[https://doc.rust-lang.org/std/process/struct.Output.html](Rust docs - std::process::Output)
[https://docs.rs/enum-kinds/0.4.1/enum_kinds/](docs.rs - enum_kinds)
The list command is creating a new table row when dispaying multiline commands, ex:
Alias | tags | Command |
---|---|---|
1-test-single-line | - |
echo this is a single line command |
2-test-multi-line | - |
echo This |
- |
- |
echo is |
- |
- |
echo over |
- |
- |
echo multiple |
- |
- |
echo lines |
3-test-another-single-line | - |
echo this is another single line command |
Converted the ascii table to markdown table for nicer viewing. The minus sign can be interpreted as nothing or whitespace.
Config to reproduce error:
[scripts.1-test-single-line]
alias = '1-test-single-line'
command = '''
echo this is a single line command
'''
[scripts.2-test-multi-line]
alias = '2-test-multi-line'
command = '''
echo This
echo is
echo over
echo multiple
echo lines
'''
[scripts.3-test-another-single-line]
alias = '3-test-another-multi-line'
command = '''
echo this is another single line command
'''
pier rename <original> <new>
with the alias:
pier mv <original> <new>
The subcommand should not allow you to write over an existing script, but we could perhaps add a -f
/ --force
flag. This is something that could be useful for the add command as well.
Hello,
Unfortunately, when I attempt to run pier list
it simply segfaults:
zsh โฏ pier list
[1] 503177 segmentation fault (core dumped) pier list
From syslog:
2024-01-20T10:45:50.051578-06:00 mosthated-pc kernel: [ 3786.184976] pier[503177]: segfault at 89 ip 0000561acae62840 sp 00007ffd0699a570 error 4 in pier[561acae22000+ea000] likely on CPU 19 (core 3, socket 0)
2024-01-20T10:45:50.051588-06:00 mosthated-pc kernel: [ 3786.184985] Code: 73 08 31 c9 45 31 d2 eb 46 90 49 89 d0 49 83 e0 fc 4c 8d 8e 10 01 00 00 31 c9 45 31 d2 66 66 66 66 2e 0f 1f 84 00 00 00 00 00 <49> 03 89 28 ff ff ff 49 03 89 70 ff ff ff 49 03 49 b8 49 03 09 49
I only just installed it and attempted to run pier config-init
then was trying other commands, one being list
which lead the the segfault.
I checked my config and there was not an interpreter, so I set it and my config looks like this:
[scripts.hello-pier]
alias = 'hello-pier'
command = 'echo Hello, Pier!'
description = 'This is an example command.'
[default]
interpreter = ["/bin/bash", "-c"]
OS: Ubuntu 23.10 x86_64
Host: X670E Taichi
Kernel: 6.5.0-14-generic
Uptime: 1 hour, 9 mins
Packages: 3591 (dpkg), 73 (flatpak), 27 (snap)
Shell: zsh 5.9
Resolution: 2560x1080
DE: GNOME 45.2
WM: Mutter
WM Theme: Adwaita
Theme: Yaru-dark [GTK2/3]
Icons: Yaru [GTK2/3]
Terminal: alacritty
CPU: AMD Ryzen 9 7950X (32) @ 5.881GHz
GPU: AMD ATI Radeon RX 6800/6800 XT / 6900 XT
GPU: AMD ATI 5a:00.0 Raphael
Memory: 13501MiB / 63398MiB
pier copy <original> <new>
with the alias:
pier cp <original> <new>
The subcommand should not allow you to write over an existing script, but we could perhaps add a -f
/ --force
flag. This is something that could be useful for the add command as well.
I'm using a shell script managed by pier to perform various update tasks. One of these tasks is running rustup update
. Currently, when I run this script, some of the progress output goes to stderr and is only visible after the whole script finishes. I think it would be better to show stderr output as it is produced by the script subprocess.
I think the issue might stem from this line.
may its a bit different concept. i possible please add to your to-do-list: add fuzzy search menu bolow.
i tried to do something with https://github.com/sl5net/Lintalist4Linux
thanks
Most of the code in main.rs should probably be moved into lib.rs so it's possible to create unit tests for the code.
I could start working on this next time I get a chance to sit down and do some coding.
I tried to compile pier
and one of the tests was failing. It turns out it depends on the user's current shell, which in my case is fish
. Doing SHELL="/bin/bash" cargo test
made them pass.
It makes sense that pier
defaults to $SHELL
to run scripts, but the tests probably shouldn't depend on the user's shell :)
An option to allow new scripts to be started from a base template when adding a new script using your $EDITOR instead of specifying the command in the commandline.
The template
would really just be a dumb file that is inserted into the new script as a base, an example base template could look like this:
tmpfile=$(mktemp)
trap 'rm "$tmpfile"' 0 1 15
# --- continues ---
I would suggest -T
/ --template
since tag is already taken.
A pier command using the templating flag could perhaps look something like this:
pier add -a my_alias --template sh-tmpfile
[scripts.refresh-wifi] command = "ip link set wlp58s0 down && sleep 5 && ip link set wlp58s0 up" [scripts.twa-analyze] command = "docker run --rm -t trailofbits/twa -vw" tags = [ "infosec" ] [scripts.enabled-services] command = "systemctl list-unit-files --state=enabled" [scripts.flush-docker] command = "docker container stop $(docker container ls -a -q) && docker system prune -a -f --volumes" description = "A script to clear out old Docker containers and images" tags = [ "docker", "flush" ]
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.