从github gists更新本地和远程文件的cli
getgist的Python项目详细描述
获取要点
使用one single command从GitHub Gist轻松下载任何文件。
为什么?
由于种种原因,我没有dotfiles存储库。我更喜欢 将我的.vimrc、.gitconfig、.bash_profile等存储为 Gists。
我编写这个脚本是为了用一个 例如,命令:getmy .vimrc就完成了。
安装
$ pip install getgist
getgist与python 2.7+或3.4+一起使用。
要update只需运行$ pip install -U 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上的gist
只需运行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询问当它在 在不同的gist中使用相同的名称。
使用OAuth身份验证
为什么?
添加您的personal access token 作为允许的环境变量:
- 私人注册表的下载
- 现有GISTs 的更新
如何做到?
- 获取具有管理gists权限的个人访问令牌 从GitHub settings
- 使用 个人访问令牌
示例
$exportGETGIST_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
即使您尝试下载的文件是私有文件,也可以执行此操作 gist(当然用户名必须是GETGIST_TOKEN帐户)。
设置默认用户
为什么?
设置默认用户以避免一直键入您的github用户名
如何做到?
- 使用github设置名为GETGIST_USER的环境变量 用户名
- 使用快捷方式getmy <filename>或putmy <filename>
示例
$exportGETGIST_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
贡献
请随意使用report an issue、open a pull request或drop a line。
非常感谢@ddboline和 /u/Sean1708感谢你的贡献!
不要忘记用Black格式化代码,并编写和运行测试:
$ pip install tox $ tox