From 3a826e16ccc30b06c501d7c06c4c064aed1b05f2 Mon Sep 17 00:00:00 2001 From: Dylan Date: Wed, 2 Mar 2016 17:56:28 +1100 Subject: [PATCH 1/3] Made the separator in stdout mode configurable with '--stdout_separator' and '$stdout_separator' --- config/config | 8 ++++++++ neofetch | 22 ++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/config/config b/config/config index 71b2f723..e9373e92 100644 --- a/config/config +++ b/config/config @@ -321,6 +321,14 @@ scrot_dir="$HOME/Pictures" scrot_name="neofetch-%Y-%m-%d-%H:%M.png" +# }}} + +# Stdout options {{{ + +# Separator for stdout mode +# --stdout_separator string +stdout_separator=" " + # }}} # Config Options {{{ diff --git a/neofetch b/neofetch index c1e36516..0ddb9397 100755 --- a/neofetch +++ b/neofetch @@ -342,6 +342,14 @@ scrot_dir="$HOME/Pictures" scrot_name="neofetch-%Y-%m-%d-%H:%M.png" +# }}} + +# Stdout options {{{ + +# Separator for stdout mode +# --stdout_separator string +stdout_separator=" " + # }}} # Config Options {{{ @@ -1955,15 +1963,25 @@ prin () { # Stdout {{{ stdout () { + stdout_separator_flag="$(awk -F '--stdout_separator ' '{printf $2}' <<< "${args[@]}")" + stdout_separator_flag=${stdout_separator_flag/ '--'*} + + [ ! -z "$stdout_separator_flag" ] && \ + stdout_separator="$stdout_separator_flag" + + index=0 for func in "${args[@]}"; do case "$func" in "--"*) break ;; + *) "get$func" 2>/dev/null eval output="\$$func" - printf "%s" "$output " + case "${args[$((index + 1))]}" in "--"*) unset stdout_separator ;; esac + printf "%s" "${output}${stdout_separator}" ;; esac + index=$((index + 1)) done exit } @@ -2447,7 +2465,7 @@ while [ "$1" ]; do unset info_color colors case "$2" in "--"* | "") echo "--stdout requires at least one argument"; exit ;; - *) shift; args=("$@"); config="off" stdout ;; + *) shift; args=("$@"); config="off"; stdout ;; esac ;; From c9157fbd676d675cd2e7afb5cedfd1e705293fc2 Mon Sep 17 00:00:00 2001 From: Dylan Date: Wed, 2 Mar 2016 17:58:48 +1100 Subject: [PATCH 2/3] Remove whitespace --- neofetch | 1 - 1 file changed, 1 deletion(-) diff --git a/neofetch b/neofetch index 0ddb9397..98974f78 100755 --- a/neofetch +++ b/neofetch @@ -1973,7 +1973,6 @@ stdout () { for func in "${args[@]}"; do case "$func" in "--"*) break ;; - *) "get$func" 2>/dev/null eval output="\$$func" From 670fb2238ec479d51a28da6fa5b63ad2393722f6 Mon Sep 17 00:00:00 2001 From: Dylan Date: Thu, 3 Mar 2016 16:35:24 +1100 Subject: [PATCH 3/3] Simplified sdtout function --- neofetch | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/neofetch b/neofetch index 98974f78..6e3071f6 100755 --- a/neofetch +++ b/neofetch @@ -1963,25 +1963,25 @@ prin () { # Stdout {{{ stdout () { + # Read args early for the separator stdout_separator_flag="$(awk -F '--stdout_separator ' '{printf $2}' <<< "${args[@]}")" stdout_separator_flag=${stdout_separator_flag/ '--'*} [ ! -z "$stdout_separator_flag" ] && \ stdout_separator="$stdout_separator_flag" - index=0 for func in "${args[@]}"; do case "$func" in "--"*) break ;; *) "get$func" 2>/dev/null eval output="\$$func" - case "${args[$((index + 1))]}" in "--"*) unset stdout_separator ;; esac - printf "%s" "${output}${stdout_separator}" + stdout+="${output}${stdout_separator}" ;; esac - index=$((index + 1)) done + + printf "%s" "${stdout%%${stdout_separator}}" exit }