跳转到主要内容

从GitHub Gists更新本地和远程文件的命令行工具。

项目描述

Travis CI Coveralls PyPI Version Python Version

GetGist

通过一条简单的命令轻松下载任何GitHub Gist中的文件。

为什么?

因为我没有dotfiles仓库。我更喜欢将我的init.vim.gitconfig.bashrc等存储为Gists

我编写了这个CLI,这样我就可以通过一条简单的命令更新我的dotfiles:例如getmy vim.init,然后它就完成了。

安装

$ pip install getgist

GetGist与Python 3.6+兼容。

要更新它,只需运行$ pip install --upgrade getgist

用法

从GitHub获取Gists

只需运行getgist <username> <filename>。例如

$ getgist cuducos .vimrc
  Fetching https://api.github.com/users/cuducos/gists
  Reading https://gist.githubusercontent.com/cuducos/409fac6ac23bf515f495/raw/666d7d01a0058e4fd898ff752db66160f10a60bb/.vimrc
  Saving .vimrc
  Done!

GetGist会在本地文件(同名)存在时询问您要做什么。如果您决定不删除您的本地文件副本,它将被重命名为类似.bkp.bkp1.bkp2等的扩展名。

更新GitHub上的Gists

只需运行putgist <username> <filename>,即可使用本地文件的內容更新远程Gist。它需要一个OAuth令牌(见下文使用OAuth身份验证)。例如

$ putgist cuducos .vimrc
  User cuducos authenticated
  Fetching https://api.github.com/gists
  Sending contents of .vimrc to https://api.github.com/gists/409fac6ac23bf515f495
  Done!
  The URL to this Gist is: https://gist.github.com/cuducos/409fac6ac23bf515f495

GetGist会在找到不同Gists中不同名称的文件时询问您要做什么。

列出GitHub上的Gist文件

只需运行lsgists <username>。例如

$ lsgists cuducos
  Gist           File               URL
  -------------  ------------------ -------------------------
  First Gist     file.md            https://gist.github.com/…
  My Gist #2     another_file.md    https://gist.github.com/…
  My Gist #2     README.md          https://gist.github.com/…

已认证用户的秘密Gists(当用户认证时)会在名称旁边带有[Secret Gist]标签。

使用OAuth身份验证

为什么?

将您的个人访问令牌作为环境变量添加,以允许

  1. 下载私有gists
  2. 更新现有gists
  3. 列出私有gists

如何操作?

  1. GitHub设置获取具有管理您gists权限的个人访问令牌
  2. 设置名为GETGIST_TOKEN的环境变量,并使用您的个人访问令牌

这篇文章可能有助于您在基于Unix的操作系统中使用Bash创建环境变量,但对于其他系统和shell,您也可以自由搜索其他替代方案。

示例

$ export GETGIST_TOKEN=whatever1234
$ getgist cuducos .vimrc
  User cuducos authenticated
  Fetching https://api.github.com/gists
  Reading https://gist.githubusercontent.com/cuducos/409fac6ac23bf515f495/raw/666d7d01a0058e4fd898ff752db66160f10a60bb/.vimrc
  Saving .vimrc
  Done!
  The URL to this Gist is: https://gist.github.com/cuducos/409fac6ac23bf515f495

即使您要下载的文件是私有gists,这也会正常工作(当然,用户名必须与GETGIST_TOKEN账户匹配)。

设置默认用户

为什么?

设置默认用户,以避免每次都输入您的GitHub用户名。

如何操作?

  1. 设置名为GETGIST_USER的环境变量,并使用您的GitHub用户名
  2. 使用快捷键getmy <filename>putmy <filename>mygists

示例

$ export GETGIST_USER=cuducos
$ getmy .vimrc
  Fetching https://api.github.com/users/cuducos/gists
  Reading https://gist.githubusercontent.com/cuducos/409fac6ac23bf515f495/raw/666d7d01a0058e4fd898ff752db66160f10a60bb/.vimrc
  Saving .vimrc
  Done!
  The URL to this Gist is: https://gist.github.com/cuducos/409fac6ac23bf515f495

贡献

我们使用Poetry来管理我们的开发环境

  1. poetry install将为您获取包含所有依赖项的虚拟环境
  2. poetry shell将激活此虚拟环境
  3. exit将取消激活此虚拟环境

请随意报告问题发起拉取请求留言

不要忘记使用Black格式化您的代码,并编写和运行测试

$ tox

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪一个,请了解更多关于安装包的信息。

源分布

getgist-0.2.2.tar.gz (12.3 kB 查看哈希值)

上传时间

构建分布

getgist-0.2.2-py3-none-any.whl (11.7 kB 查看哈希值)

上传时间 Python 3

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面