diff options
Diffstat (limited to 'pkg-screenshot.sh')
-rwxr-xr-x | pkg-screenshot.sh | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/pkg-screenshot.sh b/pkg-screenshot.sh index 6095898..a10fd05 100755 --- a/pkg-screenshot.sh +++ b/pkg-screenshot.sh @@ -1,30 +1,44 @@ #!/bin/sh -if [ -z $1 ]; then - echo "Error: Missing package name" +print_usage(){ echo "Usage: pkg-screenshot.sh [options] package" -fi + echo "" + echo " -h, --help give this help list" + echo " --no-download Open the image URL instead of saving an image file in /tmp/" +} case $1 in -#if [[ $1 == "-h" || $1 == "--help" ]]; then -h|--help) - echo "Usage: pkg-screenshot.sh [options] package" - echo "" - echo " -h, --help give this help list" - echo " --no-download Open the image URL instead of saving an image file in /tmp/" + print_usage ;; -#elif [ $1 != "--no-download" ]; then --no-download) - URL=`wget -qO- https://screenshots.debian.net/json/package/$2 | jq '.screenshots[0].large_image_url' | tr -d \"` - xdg-open $URL + if [ -z $2 ]; then + echo "Error: Missing package name" + print_usage + else + URL=`wget -qO- https://screenshots.debian.net/json/package/$2 | jq '.screenshots[0].large_image_url' | tr -d \"` + if [ -z $URL ]; then + echo "Error: Package \"$2\" does not exist" + else + xdg-open $URL + fi + fi ;; -#else *) - URL=`wget -qO- https://screenshots.debian.net/json/package/$1 | jq '.screenshots[0].large_image_url' | tr -d \"` - EXTENSION=`echo $URL | rev | cut -d . -f 1 | rev` - wget -qO /tmp/pkg-screenshot.$EXTENSION $URL - xdg-open /tmp/pkg-screenshot.$EXTENSION + if [ -z $1 ]; then + echo "Error: Missing package name" + print_usage + else + URL=`wget -qO- https://screenshots.debian.net/json/package/$1 | jq '.screenshots[0].large_image_url' | tr -d \"` + if [ -z $URL ]; then + echo "Error: Package \"$1\" does not exist" + else + EXTENSION=`echo $URL | rev | cut -d . -f 1 | rev` + wget -qO /tmp/pkg-screenshot.$EXTENSION $URL + xdg-open /tmp/pkg-screenshot.$EXTENSION + fi + fi ;; esac |