Skip to content

Instantly share code, notes, and snippets.

@kmaglione

kmaglione/stdin.sh

Created Sep 22, 2011
Embed
What would you like to do?
#!/bin/rc
. 9.rc
. rclib $*
getflags 'g,p,r,e expire,n nick,d desc,l lang'
ext=''
if (~ $flage '') flage = N
if (! ~ $flagl '') ext=.$flagl
name=stdin
if (! ~ $#argv 0)
name = $argv(0)
ifs=''
js -e '
let data = {
public: !environment.flagp,
description: environment.flagd,
files: {}
};
let { ext } = environment;
if (!scriptArgs.length) {
let line, lines = [];
while ((line = readline()) != null)
lines.push(line);
data.files["stdin" + ext] = { content: lines.join("\n") };
}
else for each (let arg in scriptArgs)
data.files[arg + ext] = { content: read(arg) };
print(JSON.stringify(data));
' /dev/null $argv |
curl -nd '@-' https://api.github.com/gists |
js -e '
let line, lines = [];
while ((line = readline()) != null)
lines.push(line);
let json = JSON.parse(lines.join("\n"));
if (environment.flagg)
print(json.git_pull_url);
else if (environment.flagr)
print([f.raw_url for each (file in json.files)].join(" "));
else
print(json.html_url);
' |
tee >{tr -d $newline | xsel -i}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.