From 95c1b74e6dd1f4f787114fc8af0e15a8c5b5a261 Mon Sep 17 00:00:00 2001 From: Dylan Date: Sat, 20 Feb 2016 13:35:07 +1100 Subject: [PATCH] --size now takes a percentage --- README.md | 2 +- fetch | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 9005216e..168d240a 100644 --- a/README.md +++ b/README.md @@ -277,7 +277,7 @@ alias fetch2="fetch \ --image type Image source. Where and what image we display. Possible values: wall, shuffle, ascii, /path/to/img, off - --size px Size in pixels to make the image. + --size 20 | --size 20% Size to make the image, takes pixels or a percentage. --image_backend w3m/iterm2 Which program to use to draw images. --shuffle_dir path/to/dir Which directory to shuffle for an image. --image_position left/right Where to display the image: (Left/Right) diff --git a/fetch b/fetch index 5002df95..2e6f5aab 100755 --- a/fetch +++ b/fetch @@ -1864,12 +1864,22 @@ getimage () { font_height=$((term_height / lines)) # Image size is half of the terminal - if [ "$image_size" == "auto" ]; then - image_size=$((columns * font_width / 2)) + case "$image_size" in + "auto") + image_size=$((columns * font_width / 2)) - [ "$((term_height - term_height / 4))" -lt "$image_size" ] && \ - image_size=$((term_height - term_height / 4)) - fi + [ "$((term_height - term_height / 4))" -lt "$image_size" ] && \ + image_size=$((term_height - term_height / 4)) + ;; + + *"%") + percent=${image_size/\%} + image_size=$((percent * term_width / 100)) + + [ "$((percent * term_height / 50))" -lt "$image_size" ] && \ + image_size=$((percent * term_height / 100)) + ;; + esac # Where to draw the image case "$image_position" in @@ -2265,7 +2275,7 @@ usage () { cat << EOF --image type Image source. Where and what image we display. Possible values: wall, shuffle, ascii, /path/to/img, off - --size px Size in pixels to make the image. + --size 20 | --size 20% Size to make the image, takes pixels or a percentage. --image_backend w3m/iterm2 Which program to use to draw images. --shuffle_dir path/to/dir Which directory to shuffle for an image. --image_position left/right Where to display the image: (Left/Right)