Support unix pipes (as a bin target `rt`)
Closed this issue · 1 comments
Create a bin target for this crate that can be used in unix pipes. The idea is to enable something like the following.
cat Cargo.toml | rt -s single -c "echo foo \'%\'"
Due to the way in which unix pipes are implemented, it is not possible to pipe the stdout of this command to anything else. Unix pipes are non blocking. So there is no way to stop the pipe mid way. Instead, the rt
binary simply takes a command that it will run after the user has made their selection. Using the selected item(s) and applying them to this command.
This bin target named rt
can be used in scripts to select a single line from the output of a program (that outputs to stdout
). Very much like grep
but for making selections using tuify.
Helpful links:
-
This will require a check to see whether the terminal is interactive mode or not, ie whether stdin is piped. More info here.
-
And it will require the use of
clap
.clap
tutorial.- Short video of how to use clap https://youtu.be/B_UZu-jBYgw?si=PKXAe_CPe0A9AtJx
Note: Windows powershell also supports pipelining: https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_pipelines?view=powershell-7.3
GitHub Copilot: Yes, PowerShell supports command pipelining using the|
operator. This allows you to pass the output of one command as input to another command. Here's an example:Get-ChildItem | Where-Object { $_.Extension -eq ".txt" } | ForEach-Object { Get-Content > $_ }
In this example,
Get-ChildItem
retrieves a list of files, which is then piped toWhere-Object
to filter the list to only include files with a.txt
extension. The resulting list is then piped toForEach-Object
, which reads the contents of each file and outputs them to the console.
You can chain together as many commands as you like using the|
operator.
Video of this bin target in action