33

我需要从原始 gist 加载 shell 脚本,但我找不到获取原始 URL 的方法。

curl -L address-to-raw-gist.sh | bash
4

4 回答 4

54

然而,寻找raw按钮(在源代码的右上角)。

原始 URL 应如下所示:

https://gist.githubusercontent.com/{user}/{gist_hash}/raw/{commit_hash}/{file}

注意:省略{commit_hash}部分可以获取最新版本,如下图:

https://gist.githubusercontent.com/{user}/{gist_hash}/raw/{file}
于 2013-05-16T14:05:39.147 回答
31

2014 年 2 月:原始网址刚刚更改。
请参阅“ Gist 原始文件 URI 更改”:

所有 Gist 文件的原始主机都会立即更改。
进行此更改是为了进一步将用户内容与受信任的 GitHub 应用程序隔离开来。

新主机是

 https://gist.githubusercontent.com. 

现有的 URI 将重定向到新主机。

之前https://gist.github.com/<username>/<gist-id>/raw/...

现在它是https://gist.githubusercontent.com/<username>/<gist-id>/raw/...

例如:

https://gist.githubusercontent.com/VonC/9184693/raw/30d74d258442c7c65512eafab474568dd706c430/testNewGist

KrisWebDev在评论中添加:

如果您想要 Gist 文档的最新版本,只需删除<commit>/from URL

https://gist.githubusercontent.com/VonC/9184693/raw/testNewGist

于 2014-02-24T09:48:41.977 回答
3

可以简单地使用 github api。

https://api.github.com/gists/$GIST_ID

参考:https ://miguelpiedrafita.com/github-gists

于 2021-06-26T11:49:03.317 回答
2

Gitlab 片段提供了简短的 url,易于创建并且与命令行配合得很好。

示例:通过修补 /etc/bash.bashrc 启用 bash 完成

sudo su -
(curl -s https://gitlab.com/snippets/21846/raw && echo) | patch -s /etc/bash.bashrc
于 2016-07-02T02:06:26.277 回答