diff --git a/.github/packaging/postinstall_macos b/.github/packaging/postinstall_macos index 31f45d2..c8a7650 100755 --- a/.github/packaging/postinstall_macos +++ b/.github/packaging/postinstall_macos @@ -25,6 +25,7 @@ autoload -Uz compinit compinit # <<< specs completion <<< EOF + echo "Enabling auto-complete on this machine. Restarting the terminal many be required." fi exit 0 diff --git a/.github/packaging/postuninstall_macos b/.github/packaging/postuninstall_macos new file mode 100755 index 0000000..99a6a40 --- /dev/null +++ b/.github/packaging/postuninstall_macos @@ -0,0 +1,33 @@ +#!/bin/bash +# Disable the zsh completion for specs that was enabled by postinstall_macos. +# +# This script is the counterpart of postinstall_macos. It is used by the local +# "make uninstall" target to undo the change postinstall_macos made to +# /etc/zshrc, so the behaviour stays symmetric with installation. +# +# It is idempotent: the sentinel-wrapped block is only removed when the markers +# are present, so running it any number of times never fails or touches an +# /etc/zshrc that we never modified. +set -e + +ZSHRC="/etc/zshrc" +MARKER="# >>> specs completion >>>" +END_MARKER="# <<< specs completion <<<" + +if grep -qF "$MARKER" "$ZSHRC" 2>/dev/null; then + tmp="$(mktemp)" + # Drop the sentinel-wrapped block as well as any blank line(s) that + # immediately precede it (postinstall_macos inserts one before the block). + awk -v start="$MARKER" -v end="$END_MARKER" ' + $0 == start { blanks = ""; inblock = 1; next } + inblock { if ($0 == end) inblock = 0; next } + /^[[:space:]]*$/ { blanks = blanks $0 "\n"; next } + { printf "%s", blanks; blanks = ""; print } + END { printf "%s", blanks } + ' "$ZSHRC" > "$tmp" + cat "$tmp" > "$ZSHRC" + /bin/rm -f "$tmp" + echo "Disabling auto-complete on this machine" +fi + +exit 0 diff --git a/specs/src/setup.py b/specs/src/setup.py index 7bab222..ba61c93 100644 --- a/specs/src/setup.py +++ b/specs/src/setup.py @@ -263,6 +263,22 @@ def python_search(arg): install_win: $(EXE_DIR)/specs.exe echo "Please copy the file specs.exe in the EXE dir to a location on the PATH" + +uninstall_mac: + /bin/rm -f /usr/local/bin/specs + /bin/rm -f /usr/local/bin/specs-autocomplete + /bin/rm -f /usr/local/share/man/man1/specs.1.gz + /bin/rm -f /usr/local/share/zsh/site-functions/_specs + /bin/bash ../../.github/packaging/postuninstall_macos + +uninstall_linux: + /bin/rm -f /usr/local/bin/specs + /bin/rm -f /usr/local/bin/specs-autocomplete + /bin/rm -f /usr/local/share/man/man1/specs.1.gz + /bin/rm -f /etc/bash_completion.d/specs + +uninstall_win: + echo "Installation on Windows only copies specs.exe to the PATH; nothing to uninstall. Please manually remove specs.exe if desired." """ clear_clean_posix = \ @@ -816,10 +832,10 @@ def python_search(arg): makefile.write("{}\n".format(clear_clean_part)) if sys.platform=="darwin": - makefile.write("{}\n\ninstall: install_mac\n".format(manpart)) + makefile.write("{}\n\ninstall: install_mac\n\nuninstall: uninstall_mac\n".format(manpart)) elif platform=="NT": - makefile.write("install: install_win\n") + makefile.write("install: install_win\n\nuninstall: uninstall_win\n") else: - makefile.write("{}\n\ninstall: install_linux\n".format(manpart)) + makefile.write("{}\n\ninstall: install_linux\n\nuninstall: uninstall_linux\n".format(manpart)) sys.stderr.write("Makefile created.\n")