Skip to content

Commit 4020b6f

Browse files
alexzhangsclaude
andcommitted
Update README: badges, utility table, multi-account walkthrough
Adds GH Actions CI badge (replacing the dead Travis), license/issues/PRs badges, a table of the available utilities, a focused walkthrough of the git/hub/* multi-account flow, and a Development section covering test.sh plus the XSH_DEV local-iteration pattern. Also notes the LPUR convention: the leading slash form (xsh /pkg/util) is reserved for xsh-lib/core; this lib is addressed as xsh git/<pkg>/<util>. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 91befca commit 4020b6f

1 file changed

Lines changed: 111 additions & 14 deletions

File tree

README.md

Lines changed: 111 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,140 @@
1+
[![GitHub tag](https://img.shields.io/github/v/tag/xsh-lib/git?sort=date)](https://github.com/xsh-lib/git/tags)
2+
[![GitHub](https://img.shields.io/github/license/xsh-lib/git.svg?style=flat-square)](https://github.com/xsh-lib/git/)
3+
[![GitHub last commit](https://img.shields.io/github/last-commit/xsh-lib/git.svg?style=flat-square)](https://github.com/xsh-lib/git/commits/main)
4+
5+
[![ci-unittest](https://github.com/xsh-lib/git/actions/workflows/ci-unittest.yml/badge.svg)](https://github.com/xsh-lib/git/actions/workflows/ci-unittest.yml)
6+
[![GitHub issues](https://img.shields.io/github/issues/xsh-lib/git.svg?style=flat-square)](https://github.com/xsh-lib/git/issues)
7+
[![GitHub pull requests](https://img.shields.io/github/issues-pr/xsh-lib/git.svg?style=flat-square)](https://github.com/xsh-lib/git/pulls)
8+
19
# xsh-lib/git
210

311
xsh Library - git.
412

5-
About xsh and its libraries, check out [xsh document](https://github.com/alexzhangs/xsh)
13+
Utilities for working with `git` and GitHub from the shell, packaged as an
14+
[xsh](https://github.com/alexzhangs/xsh) library.
15+
16+
About xsh and its libraries, check out the [xsh document](https://github.com/alexzhangs/xsh).
17+
618

719
## Requirements
820

9-
1. bash
21+
Tested with bash:
22+
23+
* 5.x and 4.x on Linux (ubuntu-latest in CI)
24+
* 3.2.57 on macOS (macos-latest in CI)
25+
26+
This project is still at version `0.x` and should be considered immature.
1027

11-
Tested with bash:
12-
* 4.3.48 on Linux
13-
* 3.2.57 on macOS
1428

1529
## Dependency
1630

17-
1. xsh-lib/core
31+
1. [xsh-lib/core](https://github.com/xsh-lib/core) — should be loaded before
32+
this library.
33+
34+
```bash
35+
xsh load xsh-lib/core
36+
```
1837

19-
This library depends on [xsh-lib/core](https://github.com/xsh-lib/core) which should be loaded first before to use this library.
38+
2. Some utilities have additional dependencies (e.g. `gh`, `w3m`,
39+
`collaborator`). See the per-utility help for details.
2040

21-
```bash
22-
xsh load xsh-lib/core
23-
```
2441

2542
## Installation
2643

27-
Assume [xsh](https://github.com/alexzhangs/xsh) is already installed at your local.
44+
Assume [xsh](https://github.com/alexzhangs/xsh) is already installed.
2845

29-
To load this library into `xsh` issue below command:
46+
To load this library into `xsh`:
3047

3148
```bash
3249
xsh load xsh-lib/git
3350
```
3451

35-
The loaded library can be referred as name `git`.
52+
The loaded library is referenced by the name `git`.
53+
54+
> The leading slash in an LPUR (e.g. `xsh /string/upper`) is reserved for the
55+
> default library `xsh-lib/core`. For this library, write the lib name
56+
> explicitly: `xsh git/<package>/<util>`.
57+
3658

3759
## Usage
3860

39-
List available utilities for this library:
61+
List the utilities exposed by this library:
4062

4163
```bash
4264
xsh list git
4365
```
66+
67+
Get help on any utility:
68+
69+
```bash
70+
xsh help git/<package>/<util>
71+
```
72+
73+
74+
### Available utilities
75+
76+
| Utility | Kind | Purpose |
77+
|-------------------------------|----------|------------------------------------------------------------------------------------------------------------------|
78+
| `git/hub/account-for-email` | function | Look up a `gh` account name for an email via `XSH_GIT_HUB_ACCOUNT_MAP`. |
79+
| `git/hub/account-for-repo` | function | Derive the `gh` account for the current repo from `git config user.email`, using the same mapping. |
80+
| `git/hub/run` | function | Run a command with a chosen `gh` account active, isolated from concurrent shell sessions via per-call `GH_CONFIG_DIR`. |
81+
| `git/hub/collaborator` | function | Add, remove, or list collaborators of the current GitHub repo. Requires `collaborator` and `w3m`. |
82+
| `git/rebase-i-in-dumb-term` | script | Helper for running `git rebase -i` in dumb terminals. |
83+
84+
85+
### Multi-`gh`-account workflow
86+
87+
If you operate multiple GitHub accounts simultaneously (e.g. personal +
88+
work) and rely on `~/.gitconfig`'s `includeIf "gitdir:..."` rules to switch
89+
identities per directory tree, the `git/hub/*` utilities make it transparent
90+
to push/PR/etc. against the right account without ever mutating the global
91+
active account in `~/.config/gh`.
92+
93+
1. Map your emails to `gh` account names via an env var:
94+
95+
```bash
96+
export XSH_GIT_HUB_ACCOUNT_MAP="alice@personal.com=alice alice@corp.io=alice-corp"
97+
```
98+
99+
2. Use `git/hub/run` as a transparent wrapper around any `git` or `gh`
100+
command. The account is auto-derived from the current repo's
101+
`user.email`:
102+
103+
```bash
104+
xsh git/hub/run -- git push origin main
105+
xsh git/hub/run -- gh pr create --fill
106+
xsh git/hub/run -u alice-corp -- gh pr list # explicit override
107+
```
108+
109+
Each call snapshots `~/.config/gh` to a private mode-700 tempdir,
110+
`gh auth switch -u <account>` runs against the **copy**, and
111+
`GH_CONFIG_DIR` is exported only for the wrapped command. The real
112+
config is never mutated, so other shell sessions and credential-helper
113+
invocations are unaffected — even when several `git/hub/run` calls are
114+
in flight at the same time.
115+
116+
117+
## Development
118+
119+
Run the test suite:
120+
121+
```bash
122+
xsh load xsh-lib/git
123+
bash test.sh
124+
```
125+
126+
For local iteration against a working copy that hasn't been pushed yet, link
127+
the workspace as a development library and re-run with `XSH_DEV=1`:
128+
129+
```bash
130+
xsh lib-dev-manager link xsh-lib/git /path/to/parent-of-this-repo
131+
XSH_DEV=1 bash test.sh
132+
```
133+
134+
Network-dependent tests (real `gh` round-trips) are skipped by default.
135+
Enable them with `XSH_GIT_TEST_NETWORK=1` once you have a logged-in `gh`
136+
account available.
137+
138+
CI runs the same `test.sh` on `ubuntu-latest` and `macos-latest` for every
139+
push and PR. See the
140+
[ci-unittest workflow](.github/workflows/ci-unittest.yml).

0 commit comments

Comments
 (0)