Skip to content

Commit dd2eae4

Browse files
authored
Merge pull request #1 from xsh-lib/feature/zsh-support
feat: zsh support — port hub/account-for-org + test/CI under zsh
2 parents 97a20fb + 83345b4 commit dd2eae4

4 files changed

Lines changed: 30 additions & 4 deletions

File tree

.github/workflows/ci-unittest.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,22 @@ on: [push, pull_request]
55
jobs:
66
test:
77
runs-on: ${{ matrix.os }}
8+
name: ${{ matrix.os }} / ${{ matrix.shell }}
89
strategy:
910
fail-fast: false
1011
matrix:
1112
os: [ubuntu-latest, macos-latest]
13+
# bash is the historical target; zsh is the macOS default login shell.
14+
# Utilities run under zsh's ksh emulation (provided by xsh).
15+
shell: [bash, zsh]
1216

1317
steps:
1418
- uses: actions/checkout@v4
1519

20+
- name: Install zsh (Linux)
21+
if: matrix.shell == 'zsh' && runner.os == 'Linux'
22+
run: sudo apt-get update && sudo apt-get install -y zsh
23+
1624
- name: Install xsh
1725
run: |
1826
git clone --depth=50 https://github.com/alexzhangs/xsh.git xsh-source
@@ -30,10 +38,13 @@ jobs:
3038
BRANCH="${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}}"
3139
xsh load -b "$BRANCH" xsh-lib/git || xsh load xsh-lib/git
3240
33-
- name: Run tests
41+
- name: Run tests (${{ matrix.shell }})
3442
run: |
3543
# shellcheck disable=SC1090
3644
source ~/.xshrc
3745
xsh version
3846
xsh list
39-
bash test.sh
47+
# test.sh self-sources ~/.xshrc, so running it under the matrix shell
48+
# makes the utilities execute under that shell (bash, or zsh's ksh
49+
# emulation).
50+
${{ matrix.shell }} test.sh

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ Tested with bash:
2323
* 5.x and 4.x on Linux (ubuntu-latest in CI)
2424
* 3.2.57 on macOS (macos-latest in CI)
2525

26+
The utilities also run under **zsh** (the default shell on modern macOS); xsh
27+
executes them under zsh's ksh emulation. Tested with zsh 5.x.
28+
2629
This project is still at version `0.x` and should be considered immature.
2730

2831

functions/hub/account-for-org.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,11 @@ function account-for-org () {
3535
for record in $XSH_GIT_HUB_ACCOUNTS; do
3636
IFS=':' read -r r_account _ r_orgs_csv <<< "$record"
3737
[[ -z $r_orgs_csv ]] && continue
38-
IFS=',' read -ra r_orgs <<< "$r_orgs_csv"
39-
for o in "${r_orgs[@]}"; do
38+
# split the CSV on comma. `read -a` is bash-only (zsh's read has no -a,
39+
# and -A differs); org names never contain spaces, so replacing commas
40+
# with spaces and word-splitting is portable across bash and zsh.
41+
# shellcheck disable=SC2086
42+
for o in ${r_orgs_csv//,/ }; do
4043
if [[ $o == "$org" ]]; then
4144
printf '%s\n' "$r_account"
4245
return 0

test.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@
1515
# unless XSH_GIT_TEST_NETWORK=1 is set explicitly.
1616
#
1717

18+
# Make the `xsh` function available when run as a child process. Under bash it
19+
# is inherited as an exported function (no-op here); zsh cannot export functions,
20+
# so a child `zsh test.sh` sources ~/.xshrc to define xsh as a real zsh function
21+
# (otherwise it would only see the bin/xsh shim, which runs bash).
22+
if ! type xsh 2>/dev/null | grep -q 'function'; then
23+
# shellcheck source=/dev/null
24+
. ~/.xshrc
25+
fi
26+
1827
set -e -o pipefail
1928

2029
# xsh's __xsh_clean unsets XSH_DEV on every RETURN trap, so a script that makes

0 commit comments

Comments
 (0)