Interactive Pipe To: The missing cli interactive workflow
- About
- News
- Examples
- Install
- Awesome aliases Gallery
- Setup
- Help
- Supported OS Terminals
- Contributing
- Alternatives
- Credits
- License
ipt (pronounced iPipeTo) introduces the missing cli interactive workflow. It takes any kind of list as an input and uses that list to build an interactive interface to let you select an element from it.
Stop manually dragging your mouse around to copy output data from a terminal, using the ipt workflow you can pipe data from a command and select what to copy to clipboard from a convenient visual menu.
Selected data is also output to stdout allowing for easily composing various workflows - Just create your custom alias!
- v1.1.0: Added autocomplete (or fuzzy finder) mode
ipt -a
The default behavior of ipt is to allow for the selection of one item from the interactive list, once selected this item will be output to stdout, you can also use -c
option to copy the result to your clipboard.
Here we get a simple list of branchs, pipe into ipt
and pipe the selected item value to git checkout
to checkout into the selected branch. xargs
is needed to get the data from standard input and read it as an argument.
In the following example we list all the files from the folder ls
and pipe that list into ipt
only that this time we use the "multiple" flag -m
that allows for selecting multiple items from a list. The selected items get piped to trash
that deletes them.
You can also read a file as source of input data instead of reading from the standard input, here we read from a TODO file and redirect the selected items to be written in a DONE file.
In the example below we show a menu containing the local directories. The selected choice gets copy to clipboard and we can reuse the selected value later with ctrl/cmd + V.
We just covered some basic examples here, if you want more advanced uses, check our Gallery below.
iPipeTo is the DIY kit for interactive interfaces in the command-line, plug whatever you want in, do something fun with the output!
Install it easily using npm:
$ npm install -g ipt
Keep in mind that you'll need the latest Node.js LTS installed
Showcases some useful predefined workflow scripts for using iPipeTo:
# irm: Selects files to delete from current folder (recommended to use trash instead of rm -rf)
alias irm="ls | ipt -m | xargs rm -rf"
# irebase: Interactive build a list of git commits from log and rebase from selected one
alias irebase="git --no-pager log --oneline | ipt | cut -d ' ' -f 1 | xargs -o git rebase -i"
# icheckout: Interactive git checkout a commit, similar to irebase
alias icheckout="git --no-pager log --oneline | ipt | cut -d ' ' -f 1 | xargs git checkout"
# iseek: Interactive browse folders, ctrl+c once you're done
function iseek() {
cd "$(ls -a -d */ .. | ipt)"
iseek
}
# iadd: Interactive staging of selected changed files (faster than git add --patch)
alias iadd='git status -s | sed s/^...// | ipt -m | xargs git add'
# Choose one git stash to show.
alias ishow="git stash list | ipt --unquoted | cut -d ':' -f 1 | xargs git stash show -u"
Got an awesome alias idea? Send us a PR to add it to our gallery
So do you like the previous examples but are not super confident on how to configure these commands? Although I'd really recommend you to take a look at how to do it yourself, below is a quick script for you to run in your terminal and have all of our gallery scripts at once.
Do you love all these fancy interactions from the examples above but don't quite follow all this unix jargon? Worry not, in the Awesome Gallery just above we have some common workflow scripts pre configured to be used as simple shell commands. Here's how to get them:
curl -fsSL https://raw.githubusercontent.com/ruyadorno/ipt/master/gallery.sh >> ~/.bash_profile
source ~/.bash_profile
curl -fsSL https://raw.githubusercontent.com/ruyadorno/ipt/master/gallery.sh >> ~/.bashrc
source ~/.bashrc
Usage:
ipt [options] [<path>]
Options:
-a, --autocomplete Starts in autocomplete mode [boolean]
-c, --copy Copy selected item(s) to clipboard [boolean]
-d, --debug Prints to stderr any internal error [boolean]
-e, --file-encoding Encoding for file <path>, defaults to utf8 [string]
-h, --help Shows this help message [boolean]
-m, --multiple Allows the selection of multiple items [boolean]
-s, --separator Separator to to split input into items [string]
-t, --no-trim Prevents trimming of the result strings [boolean]
-p, --extract-path Returns only a valid path for each item [boolean]
-u, --unquoted Force the output to be unquoted [boolean]
-v, --version Show version number [boolean]
iPipeTo should run just fine in any of the Inquirer.js supported terminals:
- Mac OS:
- Terminal.app
- iTerm
- Linux (Ubuntu, openSUSE, Arch Linux, etc):
- gnome-terminal (Terminal GNOME)
- konsole
- Windows*:
- cmd.exe
- Powershell
- Cygwin
* Feedback wanted to confirm which features are available on a Windows cli
Bug fixes / code changes: Please provide tests covering your changes, update docs accordingly and keep your changes to a single commit.
As in any cool idea, iPipeTo is not the only available choice, here are some other cool implementations found in the wild:
- percol (python)
- sentaku (shell script)
- pick (c)
- fzf (golang)
- PathPicker (python)
-
iPipeTo wouldn't be possible if not for the amazing Inquirer.js that provides all these sweet interactive interfaces.
-
The iPipeTo logo is a kind contribution from Bruno Magal
MIT ยฉ 2018 Ruy Adorno