1
1
mirror of https://github.com/walles/moar.git synced 2024-11-22 03:14:56 +03:00
moar/scripts/test-path-help.sh
Johan Walles fc59adefd0 Show Fish / Powershell specific help
On `moar --help`, if `moar` is not the default pager, try identifying
the user's shell and print instructions for setting `PAGER` in that
shell.

Identifies fish or Powershell, then falls back on bash / zsh
instructions (since I failed to come up with a sensible way of
identifying those).

Before this change, we always printed bash / zsh instructions.

Fixes: https://github.com/walles/moar/issues/251
2024-10-27 09:59:13 +01:00

30 lines
745 B
Bash
Executable File

#!/bin/bash
# Verify the PAGER= suggestion is correct in "moar --help" output.
#
# Ref: https://github.com/walles/moar/issues/88
set -e -o pipefail
MOAR="$(realpath "$1")"
if ! [ -x "$MOAR" ]; then
echo ERROR: Not executable: "$MOAR"
exit 1
fi
echo Testing PAGER= suggestion in moar --help output...
WORKDIR="$(mktemp -d -t moar-path-help-test.XXXXXXXX)"
# Put a symlink to $MOAR first in the $PATH
ln -s "$MOAR" "$WORKDIR/moar"
echo "moar" >"$WORKDIR/expected"
# Extract suggested PAGER value from moar --help
unset PAGER
PATH="$WORKDIR" PAGER="" moar --help | grep "PAGER" | grep -v "is empty" | sed -E 's/.*PAGER[= ]//' >"$WORKDIR/actual"
# Ensure it matches the symlink we have in $PATH
cd "$WORKDIR"
diff -u actual expected