| 1 | #!/bin/sh |
| 2 | # Copyright 2007 Jari Aalto; Released under GNU GPL v2 or any later version |
| 3 | |
| 4 | # Prevent recursive loops, where environment variables are set to this script |
| 5 | [ -n "$__SENSIBLE_PAGER" ] && exit 126 |
| 6 | __SENSIBLE_PAGER="$0" |
| 7 | export __SENSIBLE_PAGER |
| 8 | |
| 9 | Try() |
| 10 | { |
| 11 | [ -z "$__sensible_candidate" ] && return |
| 12 | eval "$__sensible_candidate \"\$@\""; ret=$? |
| 13 | # 127=ENOENT, 126=couldn't exec for another reason |
| 14 | [ "$ret" -ne 126 ] && [ "$ret" -ne 127 ] && exit "$ret" |
| 15 | unset ret |
| 16 | } |
| 17 | |
| 18 | # shellcheck disable=SC2153 |
| 19 | for __sensible_candidate in "$PAGER" "$SENSIBLE_PAGER" pager more; do |
| 20 | Try "$@" |
| 21 | done |
| 22 | |
| 23 | |
| 24 | command -v gettext > /dev/null || alias gettext='printf %s' |
| 25 | # shellcheck disable=SC2016 |
| 26 | TEXTDOMAIN=sensible-utils gettext 'Couldn'\''t find a pager! |
| 27 | Set the $PAGER environment variable to your desired pager. |
| 28 | ' >&2 |
| 29 | exit 1 |