Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions .github/workflows/ci-unittest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,22 @@ on: [push, pull_request]
jobs:
test:
runs-on: ${{ matrix.os }}
name: ${{ matrix.os }} / ${{ matrix.shell }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
# bash is the historical target; zsh is the macOS default login shell.
# Utilities run under zsh's ksh emulation (provided by xsh).
shell: [bash, zsh]

steps:
- uses: actions/checkout@v4

- name: Install zsh (Linux)
if: matrix.shell == 'zsh' && runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install -y zsh

- name: Install xsh
run: |
git clone --depth=50 https://github.com/alexzhangs/xsh.git xsh-source
Expand All @@ -30,10 +38,13 @@ jobs:
BRANCH="${GITHUB_HEAD_REF:-${GITHUB_REF_NAME}}"
xsh load -b "$BRANCH" xsh-lib/git || xsh load xsh-lib/git

- name: Run tests
- name: Run tests (${{ matrix.shell }})
run: |
# shellcheck disable=SC1090
source ~/.xshrc
xsh version
xsh list
bash test.sh
# test.sh self-sources ~/.xshrc, so running it under the matrix shell
# makes the utilities execute under that shell (bash, or zsh's ksh
# emulation).
${{ matrix.shell }} test.sh
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Tested with bash:
* 5.x and 4.x on Linux (ubuntu-latest in CI)
* 3.2.57 on macOS (macos-latest in CI)

The utilities also run under **zsh** (the default shell on modern macOS); xsh
executes them under zsh's ksh emulation. Tested with zsh 5.x.

This project is still at version `0.x` and should be considered immature.


Expand Down
7 changes: 5 additions & 2 deletions functions/hub/account-for-org.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ function account-for-org () {
for record in $XSH_GIT_HUB_ACCOUNTS; do
IFS=':' read -r r_account _ r_orgs_csv <<< "$record"
[[ -z $r_orgs_csv ]] && continue
IFS=',' read -ra r_orgs <<< "$r_orgs_csv"
for o in "${r_orgs[@]}"; do
# split the CSV on comma. `read -a` is bash-only (zsh's read has no -a,
# and -A differs); org names never contain spaces, so replacing commas
# with spaces and word-splitting is portable across bash and zsh.
# shellcheck disable=SC2086
for o in ${r_orgs_csv//,/ }; do
if [[ $o == "$org" ]]; then
printf '%s\n' "$r_account"
return 0
Expand Down
9 changes: 9 additions & 0 deletions test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@
# unless XSH_GIT_TEST_NETWORK=1 is set explicitly.
#

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

set -e -o pipefail

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