├── .gitignore ├── Makefile ├── Readme.md ├── package.json ├── vipe-demo.gif ├── vipe.js └── vipe.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | BIN ?= vipe 3 | PREFIX ?= /usr/local 4 | 5 | $(BIN): install 6 | 7 | install: 8 | install vipe.sh $(PREFIX)/bin/$(BIN) 9 | 10 | uninstall: 11 | rm -f $(PREFIX)/bin/$(BIN) 12 | -------------------------------------------------------------------------------- /Readme.md: -------------------------------------------------------------------------------- 1 | 2 | # vipe 3 | 4 | Pipe in and out of `$EDITOR`. 5 | 6 | Finally your editor is a real unix fellow, even if it doesn't support pipes at all. 7 | 8 | See also https://github.com/juliangruber/go-vipe. 9 | 10 | ## Example 11 | 12 | ```bash 13 | # This will open an editor with the text "change me" loaded 14 | $ echo change me | vipe | tr '[:upper:]' '[:lower:]' 15 | CHANGED 16 | ``` 17 | 18 | ![demo](vipe-demo.gif) 19 | 20 | ## Installation 21 | 22 | ```bash 23 | $ npm install -g juliangruber/vipe 24 | ``` 25 | 26 | ## Origin 27 | 28 | This is a lightweight bash only version. For the original impementation in 29 | Perl, check https://github.com/madx/moreutils/blob/master/vipe. 30 | 31 | ## Power combo with [gist](https://github.com/defunkt/gist) and [cipherhub](https://github.com/substack/cipherhub) 32 | 33 | With those functions in your `~/.bash_profile` (change username): 34 | 35 | ```bash 36 | cipherup(){ 37 | cipherhub juliangruber | gist -pR | cut -d/ -f1-5 38 | } 39 | 40 | cipheredit(){ 41 | curl -sL $1/raw | cipherhub | vipe | cipherhub juliangruber | gist -u $1 42 | } 43 | ``` 44 | 45 | Store some secret data in a gist: 46 | 47 | ```bash 48 | $ echo some secrets | cipherup 49 | 50 | ``` 51 | 52 | And edit it again: 53 | 54 | ```bash 55 | $ cipheredit 56 | ``` 57 | 58 | ## License 59 | 60 | MIT 61 | 62 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vipe", 3 | "version": "0.0.0", 4 | "description": "Pipe in and out of $EDITOR", 5 | "repository": "juliangruber/vipe", 6 | "global": true, 7 | "bin": { 8 | "vipe": "vipe.sh" 9 | }, 10 | "license": "MIT" 11 | } 12 | -------------------------------------------------------------------------------- /vipe-demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/juliangruber/vipe/b2e4e4a4b3ede41cec984cbac409dc314281500d/vipe-demo.gif -------------------------------------------------------------------------------- /vipe.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | /** 4 | * This is a node implementation of the shell script, 5 | * just for fun :) vipe.sh is what's being used. 6 | */ 7 | 8 | var fs = require('fs'); 9 | var exec = require('child_process').exec; 10 | var concat = require('concat-stream'); 11 | var run = require('comandante'); 12 | 13 | var tmp = '/tmp/vipe.' + Math.random() + '.txt'; 14 | 15 | process.stdin.isTTY() 16 | ? start('') 17 | : process.stdin.pipe(concat(start)); 18 | 19 | function start(stdin){ 20 | fs.writeFileSync(tmp, stdin); 21 | var ed = process.env.EDITOR || 'vi'; 22 | run(ed, [tmp], { stdio: 'pipe' }) 23 | .on('exit', function(){ 24 | process.stdout.write(fs.readFileSync(tmp)); 25 | fs.unlinkSync(tmp); 26 | }); 27 | } 28 | 29 | -------------------------------------------------------------------------------- /vipe.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # vipe(1) - Pipe in and out of $EDITOR 5 | # 6 | # (c) 2014 Julian Gruber . 7 | # MIT licensed. 8 | # 9 | # Example: 10 | # 11 | # $ echo foo | vipe | gist 12 | # $ vipe | gist 13 | # 14 | # This is a lightweight shell only version. For the original impementation in 15 | # python, check https://github.com/madx/moreutils/blob/master/vipe 16 | # 17 | 18 | # version 19 | 20 | VERSION="0.1.1" 21 | 22 | # usage 23 | 24 | if [ "${1}" ]; then 25 | case "${1}" in 26 | "-h") 27 | echo "usage: vipe [-hV]" 28 | exit 0 ;; 29 | "-V") 30 | echo "$VERSION" 31 | exit 0 ;; 32 | *) 33 | echo "unknown option: \"${1}\"" 34 | echo "usage: vipe [-hV]" 35 | exit 1 36 | esac 37 | fi 38 | 39 | # temp file 40 | 41 | t=/tmp/vipe.$$.txt 42 | touch $t 43 | 44 | # read from stdin 45 | 46 | if [ ! -t 0 ]; then 47 | cat > $t 48 | fi 49 | 50 | # spawn editor with stdio connected 51 | 52 | ${EDITOR} $t < /dev/tty > /dev/tty || exit $? 53 | 54 | # write to stdout 55 | 56 | cat $t 57 | 58 | # cleanup 59 | 60 | rm $t 61 | 62 | --------------------------------------------------------------------------------