Automatically find w3m-img path

This commit is contained in:
Dylan 2016-01-30 17:44:52 +11:00
parent d683593c2d
commit bca479ecf3
1 changed files with 37 additions and 11 deletions

48
fetch
View File

@ -1479,11 +1479,6 @@ getimage () {
image="ascii" image="ascii"
fi fi
# Fallback to ascii mode if image mode is 'w3m' and 'w3m' isn't installed.
if [ "$image_backend" == "w3m" ] && ! type -p $w3m_img_path >/dev/null 2>&1; then
image="ascii"
fi
# Make the directory if it doesn't exist # Make the directory if it doesn't exist
mkdir -p "$imgtempdir" mkdir -p "$imgtempdir"
@ -1609,6 +1604,32 @@ takescrot () {
# }}} # }}}
# Find w3m-img {{{
# Find w3mimgdisplay automatically
getw3m_img_path () {
if [ -x "$w3m_img_path" ]; then
return
elif [ -x "/usr/lib/w3m/w3mimgdisplay" ]; then
w3m_img_path="/usr/lib/w3m/w3mimgdisplay"
elif [ -x "/usr/libexec/w3m/w3mimgdisplay" ]; then
w3m_img_path="/usr/libexec/w3m/w3mimgdisplay"
elif [ -x "/usr/lib64/w3m/w3mimgdisplay" ]; then
w3m_img_path="/usr/lib64/w3m/w3mimgdisplay"
elif [ -x "/usr/libexec64/w3m/w3mimgdisplay" ]; then
w3m_img_path="/usr/libexec64/w3m/w3mimgdisplay"
else
image="ascii"
fi
}
# }}}
# }}} # }}}
@ -2012,12 +2033,18 @@ trap 'printf "\033[?25h"; clear; exit' 2
# Get columns # Get columns
columns=$(tput cols) columns=$(tput cols)
# Clear the terminal and hide the cursor # Hide the cursor
[ "$image" != "off" ] && clear
printf "\033[?25l" printf "\033[?25l"
# Get the image if [ "$image" != "off" ]; then
[ "$image" != "off" ] && getimage clear
# Find w3mimgdisplay
[ "$image_backend" == "w3m" ] && getw3m_img_path
# Get the image
getimage
fi
# Disable line wrap # Disable line wrap
[ "$line_wrap" == "off" ] && printf "\033[?7l" [ "$line_wrap" == "off" ] && printf "\033[?7l"
@ -2044,9 +2071,8 @@ bold
[ "$image" != "off" ] && printf "\033[0H" [ "$image" != "off" ] && printf "\033[0H"
printinfo printinfo
# Move the cursor to the bottom and Show the cursor # Set cursor position dynamically based on height of ascii/text.
if [ "$image" != "off" ]; then if [ "$image" != "off" ]; then
# Set cursor position dynamically based on height of ascii/text.
info_height="$(IFS=';' read -srdR -p $'\E[6n' ROW COL; printf "%s" "${ROW#*[}")" info_height="$(IFS=';' read -srdR -p $'\E[6n' ROW COL; printf "%s" "${ROW#*[}")"
[ "$lines" -lt "$info_height" ] && lines="$info_height" [ "$lines" -lt "$info_height" ] && lines="$info_height"