Skip to content

Instantly share code, notes, and snippets.

@marczych
Last active July 15, 2019 17:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marczych/0f2c85fdf4fee4b698375e65f744bf4f to your computer and use it in GitHub Desktop.
Save marczych/0f2c85fdf4fee4b698375e65f744bf4f to your computer and use it in GitHub Desktop.
Bash script to open a file or URL in a pager
#!/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