Last active
July 15, 2019 17:14
-
-
Save marczych/0f2c85fdf4fee4b698375e65f744bf4f to your computer and use it in GitHub Desktop.
Bash script to open a file or URL in a pager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
if [[ $# == 0 || $1 == "-h" || $1 == "--help" ]]; then | |
echo "Usage: $0 file" | |
exit 0 | |
fi | |
file="$1" | |
if [[ $file =~ ^http(s)?:// ]]; then | |
temp_file=$(mktemp) | |
wget --quiet "$file" --output-document "$temp_file" | |
file=$temp_file | |
fi | |
if hash pager 2>/dev/null; then | |
pager "$file" | |
else | |
less "$file" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment