From 6f6b67f3871c26da3c3c940fe2bd546e3e6d9c5b Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 7 Jan 2019 16:10:53 +0200 Subject: [PATCH 1/6] general: Added new simple mode for script usage --- neofetch | 46 +++++++++++++++++++++++++++++++++------------- neofetch.1 | 14 +++++++++++--- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/neofetch b/neofetch index e3786a2e..6c29c6f1 100755 --- a/neofetch +++ b/neofetch @@ -4033,18 +4033,8 @@ color() { stdout() { image_backend="off" - unset subtitle_color - unset colon_color - unset info_color - unset underline_color - unset bold - unset title_color - unset at_color - unset text_padding - unset zws - unset reset - unset color_blocks - unset get_line_break + unset subtitle_color colon_color info_color underline_color bold title_color at_color \ + text_padding zws reset color_blocks get_line_break bar_color_elapsed bar_color_total } err() { @@ -4242,7 +4232,7 @@ decode_url() { # FINISH UP usage() { printf "%s" "\ -Usage: neofetch --option \"value\" --option \"value\" +Usage: neofetch func_name --option \"value\" --option \"value\" Neofetch is a CLI system information tool written in BASH. Neofetch displays information about your system next to an image, your OS logo, @@ -4253,6 +4243,22 @@ NOTE: Every launch flag has a config option. Options: INFO: + func_name Specify a function name (second part of info() from config) to + quickly display only that function's information. + + Example: neofetch uptime --uptime_shorthand tiny + + Example: neofetch uptime disk wm memory + + This can be used in bars and scripts like so: + + memory=\"\$(neofetch memory)\"; memory=\"\${memory##*: }\" + + For multiple outputs at once (each line of info in an array): + + IFS=\$'\\n' read -d \"\" -ra info < <(neofetch memory uptime wm) + info=(\"\${info[@]##*: }\") + --disable infoname Allows you to disable an info line from appearing in the output. 'infoname' is the function name from the 'print_info()' function inside the config file. @@ -4696,6 +4702,19 @@ get_args() { done } +get_simple() { + while [[ "$1" ]]; do + [[ $(type -t "get_$1") == function ]] && { + get_distro + stdout + simple=1 + info "$1" "$1" + } + shift + done + ((simple)) && exit +} + get_distro_ascii() { # This function gets the distro ascii art and colors. # @@ -8666,6 +8685,7 @@ main() { eval "$config" get_args "$@" + get_simple "$@" [[ "$verbose" != "on" ]] && exec 2>/dev/null get_distro get_bold diff --git a/neofetch.1 b/neofetch.1 index ae57b426..1e328c40 100644 --- a/neofetch.1 +++ b/neofetch.1 @@ -1,10 +1,10 @@ -.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.7. -.TH NEOFETCH "1" "October 2018" "Neofetch 5.0.1" "User Commands" +.\" DO NOT MODIFY THIS FILE! It was generated by help2man 1.47.8. +.TH NEOFETCH "1" "January 2019" "Neofetch 5.0.1" "User Commands" .SH NAME Neofetch \- A fast, highly customizable system info script .SH SYNOPSIS .B neofetch -\fI\,--option "value" --option "value"\/\fR +\fI\,func_name --option "value" --option "value"\/\fR .SH DESCRIPTION Neofetch is a CLI system information tool written in BASH. Neofetch displays information about your system next to an image, your OS logo, @@ -14,6 +14,14 @@ NOTE: Every launch flag has a config option. .SH OPTIONS .SS "INFO:" .TP +func_name +Specify a function name (second part of info() from config) to +quickly display only that function's information. +.IP +Example: neofetch uptime \fB\-\-uptime_shorthand\fR tiny +.IP +Example: neofetch uptime disk wm memory +.TP \fB\-\-disable\fR infoname Allows you to disable an info line from appearing in the output. 'infoname' is the function name from the From c29ecc3faef82df7f7abb31828b16f52764e06dd Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 7 Jan 2019 16:11:00 +0200 Subject: [PATCH 2/6] general: Added new simple mode for script usage --- neofetch.1 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/neofetch.1 b/neofetch.1 index 1e328c40..bfb861c2 100644 --- a/neofetch.1 +++ b/neofetch.1 @@ -21,6 +21,15 @@ quickly display only that function's information. Example: neofetch uptime \fB\-\-uptime_shorthand\fR tiny .IP Example: neofetch uptime disk wm memory +.IP +This can be used in bars and scripts like so: +.IP +memory="$(neofetch memory)"; memory="${memory##*: }" +.IP +For multiple outputs at once (each line of info in an array): +.TP +IFS=$'\en' read \fB\-d\fR "" \fB\-ra\fR info < <(neofetch memory uptime wm) +info=("${info[@]##*: }") .TP \fB\-\-disable\fR infoname Allows you to disable an info line from appearing From 9b2796e168c15b049f0ba12f0295e78eca708acd Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 7 Jan 2019 16:13:59 +0200 Subject: [PATCH 3/6] general: Added new simple mode for script usage --- neofetch | 1 + neofetch.1 | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/neofetch b/neofetch index 6c29c6f1..23c80a63 100755 --- a/neofetch +++ b/neofetch @@ -4257,6 +4257,7 @@ INFO: For multiple outputs at once (each line of info in an array): IFS=\$'\\n' read -d \"\" -ra info < <(neofetch memory uptime wm) + info=(\"\${info[@]##*: }\") --disable infoname Allows you to disable an info line from appearing diff --git a/neofetch.1 b/neofetch.1 index bfb861c2..5cde4afb 100644 --- a/neofetch.1 +++ b/neofetch.1 @@ -27,8 +27,9 @@ This can be used in bars and scripts like so: memory="$(neofetch memory)"; memory="${memory##*: }" .IP For multiple outputs at once (each line of info in an array): -.TP +.IP IFS=$'\en' read \fB\-d\fR "" \fB\-ra\fR info < <(neofetch memory uptime wm) +.IP info=("${info[@]##*: }") .TP \fB\-\-disable\fR infoname From 981b2da634f9b46df3ceb3aba6f607c8005c6797 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 7 Jan 2019 18:56:09 +0200 Subject: [PATCH 4/6] general: Fix issues when printing ascii --- neofetch | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/neofetch b/neofetch index 23c80a63..b410844c 100755 --- a/neofetch +++ b/neofetch @@ -4034,7 +4034,8 @@ color() { stdout() { image_backend="off" unset subtitle_color colon_color info_color underline_color bold title_color at_color \ - text_padding zws reset color_blocks get_line_break bar_color_elapsed bar_color_total + text_padding zws reset color_blocks get_line_break bar_color_elapsed bar_color_total \ + c1 c2 c3 c4 c5 c6 c7 c8 } err() { From ea44816a3c91507958d025474f51895f44b44e95 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 7 Jan 2019 19:36:14 +0200 Subject: [PATCH 5/6] simple mode: expose window size and terminal size --- neofetch | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/neofetch b/neofetch index b410844c..93021048 100755 --- a/neofetch +++ b/neofetch @@ -3581,19 +3581,19 @@ get_window_size() { # -put as a variable. # The 1 second timeout is required for older bash case "${BASH_VERSINFO[0]}" in - 4|5) IFS=';t' read -d t -t 0.05 -sra term_size ;; - *) IFS=';t' read -d t -t 1 -sra term_size ;; + 4|5) IFS=';t' read -d t -t 0.05 -sra win_size ;; + *) IFS=';t' read -d t -t 1 -sra win_size ;; esac unset IFS # Split the string into height/width. if [[ "$image_backend" == "tycat" ]]; then - term_width="$((term_size[2] * term_size[0]))" - term_height="$((term_size[3] * term_size[1]))" + term_width="$((win_size[2] * win_size[0]))" + term_height="$((win_size[3] * win_size[1]))" else - term_height="${term_size[1]}" - term_width="${term_size[2]}" + term_height="${win_size[1]}" + term_width="${win_size[2]}" fi [[ "$image_backend" == "kitty" ]] && \ @@ -3623,16 +3623,16 @@ get_window_size() { # If the ID was found get the window size. if [[ "$current_window" ]]; then - term_size="$(xwininfo -id "$current_window")" - term_width="${term_size#*Width: }" + win_size="$(xwininfo -id "$current_window")" + term_width="${win_size#*Width: }" term_width="${term_width/$'\n'*}" - term_height="${term_size/*Height: }" + term_height="${win_size/*Height: }" term_height="${term_height/$'\n'*}" fi fi fi - term_width="${term_width:-0}" + window_size="${term_width:=0}x${term_height:=0}" } @@ -3643,6 +3643,7 @@ get_term_size() { # Calculate font size. font_width="$((term_width / columns))" font_height="$((term_height / lines))" + term_size="${lines}x${columns}" } get_image_size() { @@ -4696,7 +4697,7 @@ get_args() { # Known implicit unused variables. mpc_args=() - printf '%s\n' "$kernel $icons $font $battery $locale ${mpc_args[*]}" + : "$term_size $window_size $kernel $icons $font $battery $locale ${mpc_args[*]}" ;; esac From 7e96b428606b63b65acd59eb00e94165f960da97 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Mon, 7 Jan 2019 19:40:37 +0200 Subject: [PATCH 6/6] simple mode: expose window size and terminal size --- neofetch | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/neofetch b/neofetch index 93021048..b410844c 100755 --- a/neofetch +++ b/neofetch @@ -3581,19 +3581,19 @@ get_window_size() { # -put as a variable. # The 1 second timeout is required for older bash case "${BASH_VERSINFO[0]}" in - 4|5) IFS=';t' read -d t -t 0.05 -sra win_size ;; - *) IFS=';t' read -d t -t 1 -sra win_size ;; + 4|5) IFS=';t' read -d t -t 0.05 -sra term_size ;; + *) IFS=';t' read -d t -t 1 -sra term_size ;; esac unset IFS # Split the string into height/width. if [[ "$image_backend" == "tycat" ]]; then - term_width="$((win_size[2] * win_size[0]))" - term_height="$((win_size[3] * win_size[1]))" + term_width="$((term_size[2] * term_size[0]))" + term_height="$((term_size[3] * term_size[1]))" else - term_height="${win_size[1]}" - term_width="${win_size[2]}" + term_height="${term_size[1]}" + term_width="${term_size[2]}" fi [[ "$image_backend" == "kitty" ]] && \ @@ -3623,16 +3623,16 @@ get_window_size() { # If the ID was found get the window size. if [[ "$current_window" ]]; then - win_size="$(xwininfo -id "$current_window")" - term_width="${win_size#*Width: }" + term_size="$(xwininfo -id "$current_window")" + term_width="${term_size#*Width: }" term_width="${term_width/$'\n'*}" - term_height="${win_size/*Height: }" + term_height="${term_size/*Height: }" term_height="${term_height/$'\n'*}" fi fi fi - window_size="${term_width:=0}x${term_height:=0}" + term_width="${term_width:-0}" } @@ -3643,7 +3643,6 @@ get_term_size() { # Calculate font size. font_width="$((term_width / columns))" font_height="$((term_height / lines))" - term_size="${lines}x${columns}" } get_image_size() { @@ -4697,7 +4696,7 @@ get_args() { # Known implicit unused variables. mpc_args=() - : "$term_size $window_size $kernel $icons $font $battery $locale ${mpc_args[*]}" + printf '%s\n' "$kernel $icons $font $battery $locale ${mpc_args[*]}" ;; esac