【发布时间】:2021-06-26 19:49:03
【问题描述】:
我需要从原始 gist 加载 shell 脚本,但我找不到获取原始 URL 的方法。
curl -L address-to-raw-gist.sh | bash
【问题讨论】:
-
注意:gist raw url 刚刚更改(2014 年 2 月)。见my answer below
标签: gist
我需要从原始 gist 加载 shell 脚本,但我找不到获取原始 URL 的方法。
curl -L address-to-raw-gist.sh | bash
【问题讨论】:
标签: gist
还有,寻找raw 按钮(在源代码的右上角)。
原始 URL 应如下所示:
https://gist.githubusercontent.com/{user}/{gist_hash}/raw/{commit_hash}/{file}
注意:省略{commit_hash}部分可以获取最新版本,如下图:
https://gist.githubusercontent.com/{user}/{gist_hash}/raw/{file}
【讨论】:
2014 年 2 月:原始网址刚刚更改。
见“Gist raw file URI change”:
所有 Gist 文件的原始主机正在立即更改。
进行此更改是为了进一步将用户内容与受信任的 GitHub 应用程序隔离开来。新主机是
https://gist.githubusercontent.com.
现有的 URI 将重定向到新主机。
之前是https://gist.github.com/<username>/<gist-id>/raw/...
现在是https://gist.githubusercontent.com/<username>/<gist-id>/raw/...
例如:
如果您想要 Gist 文档的最新版本,只需从 URL 中删除
<commit>/https://gist.githubusercontent.com/VonC/9184693/raw/testNewGist
【讨论】:
The raw host for all Gist files is changing immediately. 但我没有立即找到
可以简单地使用 github api。
https://api.github.com/gists/$GIST_ID
【讨论】:
url = json_data["files"][filename]["raw_url"] 其中filename 是 gist 中特定文件的名称。
Gitlab sn-ps 提供简洁的 url,易于创建并且与命令行配合良好。
示例:通过修补 /etc/bash.bashrc 启用 bash 完成
sudo su -
(curl -s https://gitlab.com/snippets/21846/raw && echo) | patch -s /etc/bash.bashrc
【讨论】: