
在命令行里面经常需要在浏览器里面打开 github 上的 repo ,这个对外来说非常高频,我希望像操作系统里面的 open 命令一样简单。
使用过各种小工具都不方便,比如官方的 gh, 都不方便。就自己开发了一个,分享给有需要的同学吧 https://github.com/libratiger/gopen
你可以通过 Homebrew 安装 gopen:
brew tap libratiger/homebrew-tap brew install gopen 在当前 Git 仓库目录中运行 gopen,它会自动打开第一个远程 URL 。
gopen 在指定目录下查找并打开远程 URL 。
gopen /path/to/git-repo 使用 -i 参数进入交互模式,用户可以选择要打开的远程 URL 。
gopen -i 或在指定目录下使用交互模式:
gopen /path/to/git-repo -i 1 GPT6 2024-07-12 11:54:31 +08:00 powershell # 打开当前仓库 Function gopen { # 获取所有远程仓库的名称和地址 $remoteRepositories = git remote -v | ForEach-Object { $remote = $_ -split '\s+' [PSCustomObject]@{ Name = $remote[0] Url = $remote[1] } } # 去重远程仓库地址 $uniqueRemoteRepositories = $remoteRepositories | Select-Object -Property Url -Unique # 输出所有远程仓库的名称和地址 $uniqueRemoteRepositories | ForEach-Object { Write-Host "Remote repository URL: $($_.Url)" Start-Process $_.Url } } ![]() |
3 dHenryDong 2024-07-12 12:12:42 +08:00 用 omz 配个插件就完事儿了 https://github.com/paulirish/git-open.git |
4 noahlias 2024-07-12 12:19:35 +08:00 gh repo view --web 直接用 github 官方 cli 就好了 |
5 xingheng 2024-07-12 13:16:00 +08:00 |
7 DjvuLee OP @dHenryDong 和这个差不多,但是我希望提供一点交互式的界面 |
9 noahlias 2024-07-12 14:23:56 +08:00 @DjvuLee 这个还难用啊? 说实话这种其实有很多其他的方式代替 感觉都很方便 1:选择一个好的终端模拟器支持 URL 鼠标点击 比如 kitty 直接 git remote -v 点击打开就行 2: 用 tmux-fzf-url 直接当前 buffer 选择打开 或者编辑当前 buffer 用 vim/neovim gx 打开 3: 一个管道命令 `git remote -v | awk '{print $2}' | sort -u | fzf | xargs open` 用 git+fzf+open(其他系统换成不同的) 命令就解决了 |
10 DjvuLee OP 我之前是选择的方法 1 ,我今天终于忍受不了 |
12 noahlias 2024-07-12 14:34:04 +08:00 @DjvuLee gh 有 completion 啊 gh completion 不就是吗 有 zsh/bash/fish 看看官方文档或者 help |
13 Donaldo 2024-07-12 14:55:25 +08:00 确实是个高频需求,我有个小建议,名字改成 gg ,哈哈。 |
14 Wxh16144 2024-07-12 15:10:33 +08:00 感觉还是 GitHub 官方的 CLI 香啊, 我设置了一个别名 gh ob(erver) 的意思。 GitHub CLI: https://cli.github.com/  |
17 bxb100 2024-07-12 19:09:17 +08:00 啊, 原来还有 gh 可以用=.=, 我也是受不了然后写了个 shell function `openg` https://github.com/bxb100/dotfiles/blob/69c5190e741c8b97b666d3fd294972ec5e6bb9f8/.functions#L225-L257 |
19 datadump 2024-07-12 20:29:50 +08:00 brew install libratiger/tap/gopen 省一条指令 |
20 jqtmviyu 2024-07-13 00:32:03 +08:00 改成 zsh 函数 ```sh # 定义 gopen 函数 function gopen() { # 获取所有远程仓库的名称和地址 remoteRepositories=$(git remote -v | awk '{print $2}' | sort | uniq) # 输出所有远程仓库的名称和地址,并在浏览器中打开 for url in $remoteRepositories; do echo "Remote repository URL: $url" if command -v xdg-open &> /dev/null; then xdg-open "$url" elif command -v open &> /dev/null; then open "$url" else echo "Cannot find a way to open the URL in the browser." fi done } ``` |