From 74b94e1769dc08465933df84a3b1d54d4dade771 Mon Sep 17 00:00:00 2001 From: Dylan Date: Wed, 27 Jan 2016 22:33:22 +1100 Subject: [PATCH] Add ascii support to fetch --- README.md | 9 ++++++++- fetch | 51 +++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ca43a13c..88b26113 100644 --- a/README.md +++ b/README.md @@ -208,7 +208,8 @@ alias fetch2="fetch \ Image: --image Image source. Where and what image we display. - Possible values: wall, shuffle, /path/to/img, off + Possible values: wall, shuffle, ascii, + /path/to/img, off --image_backend Which program to use to draw images. --shuffle_dir Which directory to shuffle for an image. --font_width px Used to automatically size the image @@ -234,6 +235,12 @@ alias fetch2="fetch \ move the text closer to the left side. --clean Remove all cropped images + + Ascii: + --ascii path/to/ascii File to get ascii from + --ascii_color Color to print the ascii art + + Screenshot: --scrot /path/to/img Take a screenshot, if path is left empty the screenshot function will use diff --git a/fetch b/fetch index b3179fe1..e78fa4fc 100755 --- a/fetch +++ b/fetch @@ -204,7 +204,7 @@ prompt_height=1 # Image Source -# --image wall, shuffle, /path/to/img, off +# --image wall, shuffle, ascii, /path/to/img, off image="wall" # Thumbnail directory @@ -261,6 +261,20 @@ yoffset=0 xoffset=0 +# }}} + +# Ascii Options {{{ + + +# Default ascii image to use +# --ascii path/to/ascii.txt +ascii="$HOME/hi.txt" + +# Ascii color +# --ascii_color +ascii_color="4" + + # }}} # Other Options {{{ @@ -1184,6 +1198,23 @@ getshuffle () { shuf -n1 -z) } +# }}} + +# Ascii {{{ + +getascii () { + # Get length of longest line + length="$(wc -L "$ascii")" + length=${length/ *} + + # Set the text padding + padding="\e[$((length + gap))C" + + # Print the ascii + printf "%s" "$(color $ascii_color)$(<$ascii)" +} + + # }}} # Image {{{ @@ -1218,6 +1249,11 @@ getimage () { getshuffle ;; + "ascii") + getascii + return + ;; + *) img="$image" ;; @@ -1465,7 +1501,8 @@ usage () { cat << EOF Image: --image Image source. Where and what image we display. - Possible values: wall, shuffle, /path/to/img, off + Possible values: wall, shuffle, ascii, + /path/to/img, off --image_backend Which program to use to draw images. --shuffle_dir Which directory to shuffle for an image. --font_width px Used to automatically size the image @@ -1491,6 +1528,12 @@ usage () { cat << EOF move the text closer to the left side. --clean Remove all cropped images + + Ascii: + --ascii path/to/ascii File to get ascii from + --ascii_color Color to print the ascii art + + Screenshot: --scrot /path/to/img Take a screenshot, if path is left empty the screenshot function will use @@ -1561,6 +1604,10 @@ while [ "$1" ]; do --gap) gap="$2" ;; --clean) rm -rf "$imgtempdir" || exit ;; + # Ascii + --ascii) image="ascii"; ascii="$2" ;; + --ascii_color) ascii_color="$2" ;; + # Screenshot --scrot | -s) scrot="on"; \ [ "$2" ] && scrot_path="$2" ;;