From b28020cfad7af98080047d8fc19d03988dd4b790 Mon Sep 17 00:00:00 2001 From: niry1 Date: Sun, 14 Jun 2026 08:47:31 +0300 Subject: [PATCH] Issue #431 - Add autocomplete in installation --- .github/packaging/postinstall_macos | 30 +++++++++++++++++++++++++++++ .github/workflows/release.yml | 9 +++++++++ specs/src/setup.py | 2 ++ 3 files changed, 41 insertions(+) create mode 100755 .github/packaging/postinstall_macos diff --git a/.github/packaging/postinstall_macos b/.github/packaging/postinstall_macos new file mode 100755 index 0000000..31f45d2 --- /dev/null +++ b/.github/packaging/postinstall_macos @@ -0,0 +1,30 @@ +#!/bin/bash +# Enable zsh completion for specs by making sure /etc/zshrc loads the +# completion functions installed under /usr/local/share/zsh/site-functions. +# +# This script is used both by the macOS .pkg installer (as its postinstall +# script) and by the local "make install" target, so the behaviour stays +# identical between the two installation paths. +# +# It is idempotent: the whole block is wrapped in sentinel markers and is only +# appended when those markers are not already present, so running it any number +# of times never produces duplicate fpath entries or duplicate compinit calls. +set -e + +ZSHRC="/etc/zshrc" +MARKER="# >>> specs completion >>>" + +if ! grep -qF "$MARKER" "$ZSHRC" 2>/dev/null; then + cat >> "$ZSHRC" <<'EOF' + +# >>> specs completion >>> +typeset -U fpath +fpath=(/usr/local/share/zsh/site-functions $fpath) + +autoload -Uz compinit +compinit +# <<< specs completion <<< +EOF +fi + +exit 0 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 08b2a64..e87c2e8 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -149,16 +149,25 @@ jobs: run: | mkdir -p pkg-root/usr/local/bin mkdir -p pkg-root/usr/local/share/man/man1 + mkdir -p pkg-root/usr/local/share/zsh/site-functions cp specs/exe/specs pkg-root/usr/local/bin/ cp specs/exe/specs-autocomplete pkg-root/usr/local/bin/ chmod 755 pkg-root/usr/local/bin/specs chmod 755 pkg-root/usr/local/bin/specs-autocomplete cp specs.1.gz pkg-root/usr/local/share/man/man1/ + cp .github/packaging/specs-completion.zsh pkg-root/usr/local/share/zsh/site-functions/_specs + + - name: Prepare pkg scripts + run: | + mkdir -p pkg-scripts + cp .github/packaging/postinstall_macos pkg-scripts/postinstall + chmod 755 pkg-scripts/postinstall - name: Build .pkg run: | pkgbuild \ --root pkg-root \ + --scripts pkg-scripts \ --identifier com.github.yoavnir.specs \ --version "${SPECS_VERSION#v}" \ --install-location / \ diff --git a/specs/src/setup.py b/specs/src/setup.py index 77c9cff..7bab222 100644 --- a/specs/src/setup.py +++ b/specs/src/setup.py @@ -247,7 +247,9 @@ def python_search(arg): $(MKDIR_C) /usr/local/share/man/man1 cp specs.1.gz /usr/local/share/man/man1/ /bin/rm specs.1.gz + $(MKDIR_C) /usr/local/share/zsh/site-functions cp ../../.github/packaging/specs-completion.zsh /usr/local/share/zsh/site-functions/_specs + /bin/bash ../../.github/packaging/postinstall_macos install_linux: $(EXE_DIR)/specs specs.1.gz cp $(EXE_DIR)/specs /usr/local/bin/