How do I pipe something from the command line to a

2020-05-14 19:09发布

I don't know if this exists yet, but I'd love to be able to do:

$ cat mygist.js | gh new gist

And have it return the URL (and possibly copy it to the clipboard / open it in the browser).

6条回答
Lonely孤独者°
2楼-- · 2020-05-14 19:26

Try this gem: https://github.com/defunkt/gist

Worked for me ^_^

查看更多
▲ chillily
3楼-- · 2020-05-14 19:26

A super simple command I like to use for making gists out of diffs is:

git diff origin master -U15 | gist -t diff

Where 15 is the line spacing you can have before and after the change (So it's easier to see differences in larger files.)

-t is the type flag.

查看更多
Explosion°爆炸
4楼-- · 2020-05-14 19:35

Have the same desire I found https://www.npmjs.com/package/gistup and fork the repository to https://github.com/CrandellWS/mkg because the developer did not want to support Windows which was the operating system being used at the time. So I reworked the npm package to work on windows as well as linux and apple...

Full source is available on GitHub: https://github.com/CrandellWS/mkg

Installation is simple with npm

npm install -g mkg

Use is discribed on the npmjs package page: https://www.npmjs.com/package/gistup

Once installed simply cd to which every directory you want to make a gist from...(remeber there are no subfolders with Gists)

and run the command:

mkg

and it will open your new gist in a broswer...additionally you will be able to control it like a normal git from there... just no subfolders...

https://stackoverflow.com/a/41233970/1815624

查看更多
趁早两清
5楼-- · 2020-05-14 19:37

Seems like GitHub has a simple REST API, including methods for creating Gists. Just for fun:

$ curl -X POST \
    --data-binary '{"files": {"file1.txt": {"content": "Hello, SO"}}}' \
    https://api.github.com/gists

This successfully created this Gist. I guess it's enough to get you started.

查看更多
小情绪 Triste *
6楼-- · 2020-05-14 19:40

As Ronie said above, there is a gist gem which provides a gist command that you can use from your terminal to upload content to https://gist.github.com/

To upload the contents of a.rb just:

gist a.rb

More info http://defunkt.io/gist/

查看更多
唯我独甜
7楼-- · 2020-05-14 19:47

Here's a simple bash script that takes a filename and makes it a gist.

function msg() {
  echo -n '{"description":"","public":"false","files":{"file1.txt":{"content":"'
  awk '{gsub(/"/,"\\\""); printf "%s\\n",$0}' "$1"
  echo '"}}'
}

[ "$#" -ne 1 ] && echo "Syntax: gist.sh filename" && exit 1
[ ! -r "$1" ] && echo "Error: unable to read $1" && exit 2

msg "$1" | curl -v -d '@-' https://api.github.com/gists

FYI: gist replies with the post body, so if the file is big, perhaps grep just the relevant parts of the reply.

查看更多
登录 后发表回答