From 49e7673f0d657f2810c4b317fefc99a2e0dcb7c1 Mon Sep 17 00:00:00 2001 From: Dylan Date: Fri, 5 Feb 2016 16:29:11 +1100 Subject: [PATCH] Added '--stdout' to print the output in a lemonbar compatible format --- config/config | 16 ++++++++++++++++ fetch | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 1 deletion(-) diff --git a/config/config b/config/config index 5e22fc4b..7ea5e023 100644 --- a/config/config +++ b/config/config @@ -326,4 +326,20 @@ config="on" config_file="$HOME/.config/fetch/config" +# }}} + +# Other Options {{{ + +# Seperator to use in stdout mode. +# --stdout_seperator string +stdout_seperator=" " + +# Hide/Show the title in stdout mode. +# --stdout_title on/off +stdout_title="off" + +# Hide/Show each info's subtitle in stdout mode. +# --stdout_subtitles on/off +stdout_subtitles="on" + # }}} diff --git a/fetch b/fetch index c2ec6e45..5a8c0dfa 100755 --- a/fetch +++ b/fetch @@ -346,6 +346,22 @@ config="on" config_file="$HOME/.config/fetch/config" +# }}} + +# Other Options {{{ + +# Seperator to use in stdout mode. +# --stdout_seperator string +stdout_seperator=" " + +# Hide/Show the title in stdout mode. +# --stdout_title on/off +stdout_title="off" + +# Hide/Show each info's subtitle in stdout mode. +# --stdout_subtitles on/off +stdout_subtitles="on" + # }}} @@ -1778,10 +1794,12 @@ info () { string="${bold}${title_color}${output}" string="${string/@/${at_color}@${title_color}}" length=${#output} + [ "$stdout_title" == "off" ] && string="" ;; underline) string="${underline_color}${output}" + [ "$stdout" == "on" ] && string="" ;; linebreak | cols) @@ -1795,8 +1813,23 @@ info () { ;; esac + # If there's no subtitle don't print one + [ -z "$2" ] && string=${string/*: } + # Print the string - printf "%b%s\n" "${padding}${string}${clear}" + if [ "$stdout" == "on" ]; then + # Unset the vars containg escape codes as lemonbar doesn't + # support them. + unset subtitle bold subtitle_color clear colon_color info_color \ + underline_color title_color at_color + + # Remove subtitles from output. + [ "$stdout_subtitles" == "off" ] && string=${string/*: } + + [ ! -z "$string" ] && printf "%s" "${string}${stdout_seperator}" + else + printf "%b%s\n" "${padding}${string}${clear}" + fi } # }}} @@ -2140,6 +2173,12 @@ while [ "$1" ]; do --scrot | -s) scrot="on"; [ "$2" ] && scrot_path="$2" ;; --scrot_cmd) scrot_cmd="$2" ;; + # Stdout + --stdout) stdout="on"; image="off"; color_blocks="off" ;; + --stdout_title) stdout_title="$2" ;; + --stdout_seperator) stdout_seperator="$2" ;; + --stdout_subtitles) stdout_subtitles="$2" ;; + # Other --config) case "$2" in