If imagemagick or w3m aren't installed disable images instead of continuing anyway

This commit is contained in:
Dylan 2016-01-28 08:57:25 +11:00
parent 2ed270b4da
commit e9cf6b7182
2 changed files with 13 additions and 5 deletions

View File

@ -76,8 +76,8 @@ https://github.com/dylanaraps/fetch/wiki/Customizing-Info
- Displaying Images: `w3m` - Displaying Images: `w3m`
- You may also need `w3m-img` - You may also need `w3m-img`
- **Note:** The script can now also use iTerm2's builtin image rendering instead of w3m! - **Note:** The script can now also use iTerm2's builtin image rendering instead of w3m!<br \>
- Enable it by changing `$image_backend` to `iterm2` or by using the launch flag `--image_backend`. Enable it by changing `$image_backend` to `iterm2` or by using the launch flag `--image_backend`.
- Image Cropping, Resizing etc: `ImageMagick` - Image Cropping, Resizing etc: `ImageMagick`
- More accurate window manager detection: `wmctrl` - More accurate window manager detection: `wmctrl`

14
fetch
View File

@ -1284,6 +1284,14 @@ getimage () {
# Check to see if the thumbnail exists before we do any cropping. # Check to see if the thumbnail exists before we do any cropping.
if [ ! -f "$imgtempdir/$imgname" ]; then if [ ! -f "$imgtempdir/$imgname" ]; then
# Check to see that imagemagick is installed
# if not then disable images
if ! type -p convert >/dev/null 2>&1; then
image="off"
padding="\033[0C"
return
fi
# Get image size so that we can do a better crop # Get image size so that we can do a better crop
size=$(identify -format "%w %h" "$img") size=$(identify -format "%w %h" "$img")
width=${size%% *} width=${size%% *}
@ -1641,18 +1649,18 @@ columns=$(tput cols)
clear clear
printf "\033[?25l" printf "\033[?25l"
# Get image # Get the image
[ "$image" != "off" ] && getimage [ "$image" != "off" ] && getimage
# Disable line wrap # Disable line wrap
[ "$line_wrap" == "off" ] && printf "\033[?7l" [ "$line_wrap" == "off" ] && printf "\033[?7l"
# Display the image # Display the image if enabled
if [ "$image" != "off" ] && [ "$image" != "ascii" ]; then if [ "$image" != "off" ] && [ "$image" != "ascii" ]; then
case "$image_backend" in case "$image_backend" in
"w3m") "w3m")
printf "%b%s\n" "0;1;$xoffset;$yoffset;$imgsize;$imgsize;;;;;$img\n4;\n3;" |\ printf "%b%s\n" "0;1;$xoffset;$yoffset;$imgsize;$imgsize;;;;;$img\n4;\n3;" |\
$w3m_img_path $w3m_img_path 2>/dev/null || padding="\033[0C"
;; ;;
"iterm2") "iterm2")