summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlouie <lshprung@yahoo.com>2021-02-23 19:27:51 -0800
committerlouie <lshprung@yahoo.com>2021-02-23 19:27:51 -0800
commit0f7c20ac391142fbbcc7048447d172cbdb7369d7 (patch)
tree5347de1a9b48822405917bc231ce3af23dd74fb2
parent2ef8fc717cb2954461be5a8274f962ad3a98d0a0 (diff)
Various bug fixes
-rwxr-xr-xpkg-screenshot.sh46
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