From aa1272ffa9ec6e41eab437d97ff45eda7fdf30be Mon Sep 17 00:00:00 2001 From: Dylan Date: Sun, 21 Feb 2016 14:37:17 +1100 Subject: [PATCH] Reduce the amount of stuff we do in the image size while loop. --- fetch | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/fetch b/fetch index 86260060..1101790f 100755 --- a/fetch +++ b/fetch @@ -1794,6 +1794,10 @@ getimage () { # Get terminal lines lines=$(tput lines) + # If we're in a screen session, fallback to + # ascii mode. + [ -n "$STY" ] && image="ascii" + # Call function based on $image case "$image" in "wall") getwallpaper ;; @@ -1811,23 +1815,26 @@ getimage () { # The ascape code above prints the output AFTER the prompt so this # loop below reads it as input. wtf xterm - index=0 while IFS= read -s -r -n 1 -t 0.25 char; do - case "$index" in - "0") [ "$char" == ";" ] && index=$((index + 1)) ;; - "1") [ "$char" == ";" ] && index=$((index + 1)) || term_height="${term_height}${char}" ;; - "2") [ "$char" == "t" ] && break || term_width="${term_width}${char}" - esac + [ "$char" == "t" ] && break + term_size+=$char done # If $img isn't a file or the terminal doesn't support xterm escape sequences, # fallback to ascii mode. - if [ ! -f "$img" ] || [ -z "$term_height" ]; then + if [ ! -f "$img" ] || [ -z "$term_size" ]; then image="ascii" getascii return fi + # Split the string + term_size=${term_size//'['} + term_size=${term_size/';'} + term_size=${term_size/$'\E4'} + term_height=${term_size/';'*} + term_width=${term_size/*';'} + # Get terminal columns columns=$(tput cols)