从GitHub Gists更新本地和远程文件的命令行工具。
项目描述
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身份验证
为什么?
将您的个人访问令牌作为环境变量添加,以允许
- 下载私有gists
- 更新现有gists
- 列出私有gists
如何操作?
- 从GitHub设置获取具有管理您gists权限的个人访问令牌
- 设置名为
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用户名。
如何操作?
- 设置名为
GETGIST_USER
的环境变量,并使用您的GitHub用户名 - 使用快捷键
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来管理我们的开发环境
poetry install
将为您获取包含所有依赖项的虚拟环境poetry shell
将激活此虚拟环境exit
将取消激活此虚拟环境
不要忘记使用Black格式化您的代码,并编写和运行测试
$ tox
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪一个,请了解更多关于安装包的信息。