feat(functions): add open-url and repo-open browser helpers
Extract the browser-detection and launch logic out of config-help into a reusable open-url function, then build repo-open on top of it to open the current repo's origin remote in a browser. - open-url: resolve the best graphical browser (fish_help_browser -> BROWSER -> xdg-mime https handler -> known binaries -> xdg-open) and launch it backgrounded. Silent by default; -v/--verbose reports the browser, -s/--silent is accepted explicitly. Browser console chatter is discarded. - repo-open: normalize the origin URL from HTTPS and SSH/scp forms, deep-link to the current branch (falling back to the remote default) and sub-directory. Provider layout resolved via git config browse.provider, hostname heuristic (github/gitlab/gitea/bitbucket, codeberg->gitea), then github default. -p/--print emits the URL, -r/--root ignores the sub-directory. - config-help: replace the inlined browser block with an open-url call. - abbr: add open-repo and url-open abbreviations that expand to the canonical command names on space/enter. - docs: document both functions in the SSoT (fish-config.md + index) and add a repo-open row to the README doc-browsing table.
This commit is contained in:
@@ -157,6 +157,10 @@ spark=### spark
|
||||
yt-dlp=### yt-dlp
|
||||
miscfns=## 5.14 Miscellaneous
|
||||
config-help=### config-help
|
||||
open-url=### open-url
|
||||
url-open=### open-url
|
||||
repo-open=### repo-open
|
||||
open-repo=### repo-open
|
||||
config-update=### config-update
|
||||
config-settings=### config-settings
|
||||
config-toggle=### config-settings
|
||||
|
||||
@@ -1339,6 +1339,69 @@ Add -i (interactive confirmation) to destructive commands:
|
||||
|
||||
Also available as: help config [SECTION] [FLAGS]
|
||||
|
||||
### open-url
|
||||
|
||||
Synopsis: open-url [-s|--silent] [-v|--verbose] <url>
|
||||
open-url -h | --help
|
||||
|
||||
Opens a URL or file:// URI in the best available graphical web browser,
|
||||
backgrounded so it never blocks the terminal. Resolves a real browser
|
||||
binary rather than deferring to xdg-open, whose MIME dispatch can hand
|
||||
local text/html files to non-browser apps (e.g. ebook readers).
|
||||
|
||||
Silent by default: prints nothing on success (errors always go to
|
||||
stderr). Pass --verbose / -v to report which browser is launched;
|
||||
--silent / -s is accepted for explicitness.
|
||||
|
||||
Resolution order:
|
||||
1. $fish_help_browser (explicit override)
|
||||
2. $BROWSER (validated; errors if not a command)
|
||||
3. xdg-mime default handler for x-scheme-handler/https
|
||||
4. First known browser binary found in a built-in list
|
||||
5. xdg-open (last resort)
|
||||
|
||||
open-url https://git.rootiest.dev/rootiest/fish-config
|
||||
open-url "file://$HOME/.config/fish/docs/html/index.html"
|
||||
|
||||
Used internally by config-help --html.
|
||||
|
||||
Typo abbreviation: url-open (expands to open-url on space/enter).
|
||||
|
||||
### repo-open
|
||||
|
||||
Synopsis: repo-open [-p|--print] [-r|--root]
|
||||
repo-open -h | --help
|
||||
|
||||
Opens the web page for the current repository's `origin` remote in a
|
||||
browser (via open-url). Deep-links to the current branch when it exists
|
||||
on the remote — falling back to the remote's default branch (main/master)
|
||||
otherwise — and to the current sub-directory when run below the repo root.
|
||||
|
||||
The remote URL is normalized from HTTPS and SSH/scp forms
|
||||
(git@host:owner/repo.git, ssh://…, https://…). The web path layout is
|
||||
provider-specific; the provider is resolved in order:
|
||||
|
||||
1. git config browse.provider (per-repo or --global override)
|
||||
2. Hostname heuristic (github / gitlab / gitea / bitbucket;
|
||||
codeberg → gitea)
|
||||
3. Default: github-style layout
|
||||
|
||||
Self-hosted hosts the heuristic can't classify (a Gitea/GitLab instance
|
||||
on a custom domain) need a one-time override:
|
||||
|
||||
git config browse.provider gitea
|
||||
|
||||
Flags:
|
||||
--print / -p Print the resolved URL instead of opening it.
|
||||
--root / -r Ignore the current sub-directory; link to the repo root.
|
||||
--help / -h Show usage.
|
||||
|
||||
repo-open
|
||||
repo-open --print
|
||||
repo-open --root
|
||||
|
||||
Typo abbreviation: open-repo (expands to repo-open on space/enter).
|
||||
|
||||
### config-update
|
||||
|
||||
Synopsis: config-update [-h] [-n] [-f]
|
||||
|
||||
Reference in New Issue
Block a user