尧图网站设计 尧图网站设计YAOTU DESIGN
ARTICLE DETAIL

资讯详情

深耕网站设计与一线实操的经验洞察。

gitsome 完全指南:基于 xonsh 的 Git/GitHub 超强命令行界面与 29 个集成命令实战

gitsome 完全指南:基于 xonsh 的 Git/GitHub 超强命令行界面与 29 个集成命令实战 开发工具版本控制【免费下载链接】gitsomeA supercharged Git/GitHub command line interface (CLI). An official integration for GitHub and GitHub Enterprise: https://github.com/works-with/category/desktop-tools项目地址https://gitcode.com/gh_mirrors/gi/gitsome点击查看免费下载导读本文以 gitsome 项目 README 为核心脉络系统讲解这款 Supercharged Git/GitHub CLI 的定位、29 个gh集成命令的完整语法与实战用法、基于 xonsh 的可选增强 Shell自动补全、交互式帮助、Fish 风格自动建议、Python REPL、命令历史以及 Pip、virtualenv、Docker 三种安装方式和 Bash/Zsh 补全配置。读完你将能在任意终端里完成 Feed 查看、Issue/PR 过滤、仓库搜索、模板生成、评论创建等完整 GitHub 工作流并理解其背后的 CLI 实现原理githubcli.py、config.py 等。为什么需要 gitsomeGit 命令行的痛点原生 Git 命令行是管理仓库的利器但存在两个明显的使用门槛记忆负担重需要记住 150 条 porcelain 与 plumbing 命令、数不清的命令特定选项以及 tags、branches 等资源相关的用法与 GitHub 脱节Git 命令行本身不集成 GitHub用户被迫在终端与浏览器之间来回切换。gitsome的目标正是针对这两点提升易用性Improving ease-of-use与提升生产力Increasing productivity为标准的 git/shell 界面增压。它也是 GitHub 官方桌面工具分类Official Integration for GitHub and GitHub Enterprise中的一员。两大核心能力概览gitsome 提供两套互补的使用方式能力入口说明29 个 GitHub 集成命令$ gh command [param] [options]在所有 Shell 中可用无需进入 gitsome 交互 Shell可选增强 Shell$ gitsome提供自动补全、交互式帮助、Fish 风格建议、Python REPL、命令历史运行gh命令的同时还可以搭配 [Git-Extras] 和 [hub] 命令解锁更多 GitHub 集成能力。Git 与 GitHub 自动补全 交互式帮助运行可选 Shell$ gitsome后可对以下内容启用自动补全autocompletion与交互式帮助interactive helpGit 命令Git 选项Git 分支、标签等资源Git-Extras 命令GitHub 集成命令29 个gh命令通用自动补全除 Git/GitHub 相关补全外gitsome 还能补全以下内容Shell 命令文件与目录环境变量Man 手册页Python如需启用额外的 bash 补全参考下文 Enabling Bash Completions 一节。gitsome 默认从 xonsh/environ.py 中列出的位置加载 bash 补全。Fish 风格自动建议与 Python REPLFish 风格自动建议gitsome 支持 Fish-style auto-suggestions按right arrow右方向键即可完成一条建议。Python REPLgitsome 由 [xonsh] 驱动天然支持 Python REPL可以在 Shell 命令旁直接运行 Python 语句。命令历史gitsome 会记录你输入的命令并保存到~/.xonsh_history.json通过上下方向键即可循环浏览命令历史。可定制的高亮配色你可以通过编辑~/.gitsomeconfig文件控制高亮使用的 ANSI 颜色。可用颜色选项为black, red, green, yellow, blue, magenta, cyan, white若想取消某类高亮颜色将对应值设为None注意white在某些终端上可能显示为浅灰色。从源码看config.py 为各 UI 元素预设了默认颜色例如clr_secondary默认为green、clr_tertiary默认为cyan、clr_error默认为red、clr_header/clr_time默认为yellow、clr_link默认为green、clr_view_link默认为magenta而clr_primary等默认即为None无色。配置文件实际支持的主键包括clr_primary、clr_secondary、clr_tertiary、clr_quaternary、clr_bold、clr_code、clr_error、clr_header、clr_link、clr_list、clr_message、clr_num_comments、clr_num_points、clr_tag、clr_time、clr_title、clr_tooltip、clr_user、clr_view_link、clr_view_index见 config.py可对照默认值按需覆盖。GitHub 集成命令语法与完整清单命令语法$ gh command [param] [options]29 个命令一览命令功能configure配置 gitsomecreate-comment在指定 issue 上创建评论create-issue创建 issuecreate-repo创建仓库emails列出用户所有已注册邮箱emojis列出 GitHub 支持的所有 emojifeed列出指定用户或仓库的全部动态followers列出所有关注者及总数following列出所有已关注用户及总数gitignore-template输出指定语言的 gitignore 模板gitignore-templates输出所有支持的 gitignore 模板issue输出指定 issue 的详细信息issues按过滤器列出 issuelicense输出指定许可证的模板licenses输出所有支持的许可证模板me列出当前登录用户信息notifications列出所有通知octo输出 Octocat 彩蛋或指定消息pull-request输出指定 pull request 的详细信息pull-requests列出所有 pull requestrate-limit输出速率限制Enterprise 不可用repo输出指定仓库的详细信息repos按过滤器列出仓库search-issues按查询搜索所有 issuesearch-repos按查询搜索所有仓库starred输出已加星标的仓库trending列出指定语言的 trending 仓库user列出指定用户信息view在终端或浏览器中查看指定索引内容所有命令的参数、选项与示例的详细参考见 COMMANDS.md。命令实现原理从源码看全部gh命令由 githubcli.py 中的GitHubCli类通过 [click] 构建click.group()定义根命令组每条命令用cli.command()注册click.option声明参数与选项最后通过pass_github装饰器把 github.py 中的GitHub实例注入命令函数。例如configure命令定义-e/--enterprise标志位调用github.configure(enterprise)githubcli.pycreate-comment要求位置参数user_repo_number并接受-t/--text选项githubcli.pyfeed的位置参数user_or_repo可选默认空字符串并支持-pr/--private与-p/--pager标志githubcli.py。命令入口由 main_cli.py 的cli()实例化GitHubCli并调用其cli()方法完成。每个命令底层经由authenticate装饰器github.py先完成凭据认证、保存配置并校验授权再执行对应逻辑。命令快速参考Quick Reference配置 gitsome要与 GitHub 正确集成必须先配置 gitsome$ gh configureGitHub Enterprise 用户需加-e/--enterprise标志$ gh configure -egh configure会引导用户输入登录名、选择密码或 personal access token 认证方式必要时还会处理两步验证two-factor。从 config.py 看普通 GitHub 登录会用密码换取带user、reposcope 的 token 并写入配置Enterprise 模式则额外要求输入 Enterprise URL并询问是否校验 SSL 证书verify_ssl选项认证凭据与enterprise_url、user_feed等一并保存在~/.gitsomeconfig中。查看 Feed动态流查看自己的 News Feed$ gh feed查看某用户的动态可通过-p/--pager分页查看该选项对很多命令都适用$ gh feed donnemartin -p查看某仓库的动态$ gh feed donnemartin/gitsome -p查看通知$ gh notifications查看 Pull Requests$ gh pull-requests过滤 Issues查看所有提到过你的 open issues$ gh issues --issue_state open --issue_filter mentioned查看所有分配给你的 issues不限状态open、closed$ gh issues --issue_state all --issue_filter assigned--issue_state与--issue_filter的更多取值见 COMMANDS.md 中gh issues的参考说明。过滤 Starred 仓库$ gh starred repo filter搜索 Issues 与仓库搜索 1 最多的 issue$ gh search-issues is:open is:issue sort:reactions-1-desc -p搜索评论最多的 issue$ gh search-issues is:open is:issue sort:comments-desc -p搜索带 help wanted 标签的 issue$ gh search-issues is:open is:issue label:\help wanted\ -p搜索 donnemartin 被 提及的 issue$ gh search-issues is:issue donnemartin is:open -p搜索自己所有开放的私有 issue$ gh search-issues is:open is:issue is:private -p搜索 2015 年及以后创建、star 数 1000 的 Python 仓库$ gh search-repos created:2015-01-01 stars:1000 language:python --sort stars -p查看 Trending 仓库与开发者$ gh trending [language] [-w/--weekly] [-m/--monthly] [-d/--devs] [-b/--browser]trending devs 目前仅在浏览器中支持$ gh trending [language] --devs --browsertrending 数据由 rss_feed.py 中的语言→RSS 订阅映射配合feedparser解析见 github.py。查看内容view命令以 HTML 适配终端的排版或可选在浏览器中查看之前列出的通知、PR、issue、仓库、用户等内容$ gh view [#] [-b/--browser]从源码看gh view依赖~/.gitsomeconfigurl配置config.py中urlsection 的url_list记录最近浏览过的一组 URL通过索引快速回看。issue命令查看某个 issue$ gh issue donnemartin/saws/1pull-request命令查看某个 PR$ gh pull-request donnemartin/awesome-aws/2设置.gitignore与LICENSE列出所有可用模板$ gh gitignore-templates $ gh licenses直接生成模板并写入文件$ gh gitignore-template Python .gitignore $ gh license MIT LICENSE召唤 Octocat让 Octocat 说出指定消息或输出彩蛋$ gh octo [say]查看用户资料查看指定用户资料$ gh user octocat查看自己的资料快捷方式$ gh me创建评论、Issue 与仓库$ gh create-comment donnemartin/gitsome/1 -t hello world $ gh create-issue donnemartin/gitsome -t title -b body $ gh create-repo gitsome对应实现上create-issue接受-t/--issue_title与可选的-d/--issue_desc选项create-repo接受-d/--repo_desc与-pr/--private标志githubcli.py底层通过 github3.py 调用 GitHub API 完成。两个通用选项分页器与浏览器许多gh命令支持-p/--pager选项在可用时将结果输出到分页器$ gh command [param] [options] -p $ gh command [param] [options] --pager许多gh命令支持-b/--browser选项在默认浏览器而非终端中显示结果$ gh command [param] [options] -b $ gh command [param] [options] --browser记不住命令gitsome 的自动补全器自带交互式帮助会引导你逐个命令使用。同时可以将 gitsome 与 Git-Extras 等工具组合使用。安装指南Pip 安装gitsome 托管于 PyPI执行$ pip3 install gitsome也可以从 GitHub 源码安装可能尚未推送到 PyPI 的最新版本$ pip3 install githttps://github.com/donnemartin/gitsome.git若未安装于 virtualenv 中可能需要sudo$ sudo pip3 install gitsome $ sudo -H pip3 install gitsome大多数 Linux 用户可通过python3-pip包安装pip3例如 Ubuntu$ sudo apt-get install python3-pip注意从 setup.py 看安装脚本会检查sys.version_info (3, 5)并直接报错退出即gitsome 要求至少 Python 3.5对应 README 声明的 Python 3.4–3.7 支持范围中以源码实际检查为准。virtualenv 安装先安装 virtualenv 与 virtualenvwrapper$ pip3 install virtualenv $ pip3 install virtualenvwrapper $ export WORKON_HOME~/.virtualenvs $ source /usr/local/bin/virtualenvwrapper.sh创建并激活 gitsome 虚拟环境$ mkvirtualenv gitsome $ pip3 install gitsome如果 pip 安装失败可能是默认运行 Python 2。检查版本并定位 Python 3$ python --version $ which python3必要时显式指定 Python 3 创建虚拟环境$ mkvirtualenv --python [Python 3 path] gitsome $ pip3 install gitsome后续重新激活 / 退出$ workon gitsome $ deactivate以 Docker 容器运行无需本地安装 Python 与 pip3直接运行$ docker run -ti --rm mariolet/gitsome用 Docker volumes 挂载工作目录与本地配置$ docker run -ti --rm -v $(pwd):/src/ \ -v ${HOME}/.gitsomeconfig:/root/.gitsomeconfig \ -v ${HOME}/.gitconfig:/root/.gitconfig \ mariolet/gitsome常用场景建议定义别名$ alias gitsomedocker run -ti --rm -v $(pwd):/src/ \ -v ${HOME}/.gitsomeconfig:/root/.gitsomeconfig \ -v ${HOME}/.gitconfig:/root/.gitconfig \ mariolet/gitsome从源码构建镜像仓库根目录已含 Dockerfile$ git clone https://github.com/donnemartin/gitsome.git $ cd gitsome $ docker build -t gitsome .启动 gitsome Shell安装完成后运行可选 Shell$ gitsome它会提供自动补全、交互式帮助、Fish 风格建议、Python REPL 等能力。运行 gh 命令$ gh command [param] [options]注意运行 gh 命令不需要进入 gitsome Shell——安装 gitsome 后即可在任何 Shell 中执行。补全配置进阶启用 Bash Completions默认情况下gitsome 从 xonsh/environ.py 列出的位置加载 bash 补全。若要添加额外补全在~/.xonshrc中追加 bash 补全文件路径$ touch ~/.xonshrc例如额外补全位于/usr/local/etc/my_bash_completion.d/completion.bash在~/.xonshrc中添加$BASH_COMPLETIONS.append(/usr/local/etc/my_bash_completion.d/completion.bash)修改后需重启 gitsome 生效。在 gitsome 之外启用 gh 的 Tab 补全将 scripts/gh_complete.sh 复制到本地。在当前会话中让 bash 知道 gh 命令可用补全$ source /path/to/gh_complete.sh为所有终端会话启用把下面一行加入bashrc并重载source /path/to/gh_complete.sh $ source ~/.bashrc提示.是source的简写也可执行. ~/.bashrc。从源码看scripts/gh_complete.sh 定义_gh_completion函数借助 click 生成的_GH_COMPLETEcomplete环境变量机制填充COMPREPLY再通过complete -F _gh_completion -o default gh注册到gh命令上。Zsh 用户zsh 包含一个兼容 bash 补全的模块。下载gh_complete.sh后在.zshrc中追加autoload bashcompinit bashcompinit source /path/to/gh_complete.sh然后重载$ source ~/.zshrc可选安装 PIL 或 Pillowgh me与gh user命令显示头像需要可选的PIL/Pillow依赖$ pip3 install PillowWindows 下头像显示有限制见下文 Windows Support。环境与平台支持支持的 Python 版本README 声明支持 Python 3.4 / 3.5 / 3.6 / 3.7同时 setup.py 的安装检查明确要求Python 3.5。gitsome 由 xonsh 驱动而 xonsh 目前不支持 Python 2.x。支持的平台Mac OS X在 OS X 10.10 上测试Linux / Unix在 Ubuntu 14.04 LTS 上测试Windows在 Windows 10 上测试Windows 支持gitsome 已在 Windows 10 上配合cmd与cmder测试。标准命令提示符可用但 cmder 或 ConEmu 体验更佳。纯文本头像由于img2txt不支持 Windows 上的 ANSI 头像gh user与gh me命令在 Windows 上始终启用-t/--text_avatar标志。配置文件位置Windows 上.gitsomeconfig位于%userprofile%例如C:\Users\dmartin\.gitsomeconfig。开发者安装与测试对 gitsome 源码开发感兴趣时$ git clone https://github.com/donnemartin/gitsome.git $ cd gitsome $ pip3 install -e . $ pip3 install -r requirements-dev.txt $ gitsome $ gh command [param] [options]若报错提示需要 Python 3.4可能是pip指向旧版 Python建议安装pip3sudo apt-get install python3-pip。单元测试与代码覆盖率在当前 Python 环境运行单元测试$ python tests/run_tests.py使用 [tox] 在多个 Python 环境运行$ tox测试覆盖了 CLI 与配置等核心模块例如 tests/test_github_cli.py、tests/test_config.py并可借助 tests/mock_github_api.py 模拟 GitHub API 进行离线验证。文档构建文档$ scripts/update_docs.sh源码级文档可直接阅读 gitsome/githubcli.py 中的 docstring每个命令的用法与示例都有详尽注释。常见配置速查~/.gitsomeconfig中与认证相关的核心键见 config.py配置键说明user_loginGitHub 用户名user_pass密码仅 Enterprise 模式存储token 方式下不适用user_tokenPersonal access tokenuser_feed登录后 https://github.com 首页 feed 的预签名 URLenterprise_urlGitHub Enterprise 地址verify_ssl是否校验 SSL 证书默认 Trueenable_avatar是否请求头像图片默认 True当verify_ssl设为 False 时config.py 会关闭 urllib3 的InsecureRequestWarning警告。普通 GitHub 登录会用密码换取 tokenscope 为user、repo并缓存到配置中若遇到 Error creating token 提示可按提示访问 token 设置页检查是否存在名为gitsome的重复 token或手动在~/.gitsomeconfig中写入user_token TOKEN。结语gitsome 的核心价值在于把 GitHub 的高频工作流Feed、Issues、PR、搜索、通知、模板、仓库管理收敛到一条命令上同时用基于 xonsh 的增强 Shell 抹平 Git 命令的记忆负担。29 个gh命令在任何 Shell 中即可使用gitsomeShell 则进一步提供补全、建议与 Python REPL结合 COMMANDS.md 的详细参数参考、githubcli.py 与 github.py 的源码实现以及 tests 下的测试用例你可以在终端中完成完整的 GitHub 工作流闭环。本文基于当前仓库的 README.md 及对应源码整理命令行为与配置说明以仓库实际内容为准。赞分享开发工具版本控制【免费下载链接】gitsomeA supercharged Git/GitHub command line interface (CLI). An official integration for GitHub and GitHub Enterprise: https://github.com/works-with/category/desktop-tools项目地址https://gitcode.com/gh_mirrors/gi/gitsome点击查看免费下载相关推荐Nanite vs 传统分布式框架为什么自组装架构更适合Ruby开发Nanite vs 传统分布式框架为什么自组装架构更适合Ruby开发 在Ruby开发领域构建分布式系统往往面临复杂配置与扩展性挑战。Nanite作为一款自组Gitsome 项目使用教程超级Git/GitHub命令行工具完全指南Gitsome 项目使用教程超级Git/GitHub命令行工具完全指南 引言告别繁琐的GitHub工作流 你是否曾经在终端和浏览器之间频繁切换只为查看Gi开发工具版本控制caffe-windows高级配置启用cuDNN加速与多GPU训练全攻略caffe windows高级配置启用cuDNN加速与多GPU训练全攻略 caffe windows是一个专为Windows用户设计的深度学习框架通过简单配上一篇Auto PY to EXE常见问题解决方案10个打包错误及修复方法下一篇FastAPI WebSocket 接口测试指南用 TestClient 连接、收发与断言创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表