From ff6d59ef0c790648973708fe595ae64a9bb7eb0d Mon Sep 17 00:00:00 2001 From: Crestwave Date: Thu, 16 Apr 2020 08:01:16 +0800 Subject: [PATCH 1/6] neofetch: add support for OSH --- neofetch | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/neofetch b/neofetch index 5cbfdd4d..4c12b86c 100755 --- a/neofetch +++ b/neofetch @@ -30,7 +30,14 @@ version=7.0.0 -bash_version=${BASH_VERSION/.*} +if [[ "$BASH_VERSION" ]]; then + bash_version=${BASH_VERSION/.*} +else + BASH_VERSION=$(bash -c "printf %s \"\$BASH_VERSION\"") + bash_version=5 + shopt -s eval_unsafe_arith +fi + sys_locale=${LANG:-C} XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-${HOME}/.config} PATH=$PATH:/usr/xpg4/bin:/usr/sbin:/sbin:/usr/etc:/usr/libexec @@ -1593,6 +1600,10 @@ get_shell() { shell=${shell/version} ;; + osh) + shell+=$("$SHELL" -c "printf %s \"\$OIL_VERSION\"") + ;; + tcsh) shell+=$("$SHELL" -c "printf %s \$tcsh") ;; @@ -2338,7 +2349,7 @@ get_gpu() { { unset -v gpu; continue; } case $gpu in - *"advanced"*) + *"Advanced"*) brand="${gpu/*AMD*ATI*/AMD ATI}" brand="${brand:-${gpu/*AMD*/AMD}}" brand="${brand:-${gpu/*ATI*/ATi}}" @@ -2352,13 +2363,13 @@ get_gpu() { gpu="$brand $gpu" ;; - *"nvidia"*) + *"NVIDIA"*) gpu="${gpu/*\[}" gpu="${gpu/\]*}" gpu="NVIDIA $gpu" ;; - *"intel"*) + *"Intel"*) gpu="${gpu/*Intel/Intel}" gpu="${gpu/\(R\)}" gpu="${gpu/Corporation}" @@ -2369,7 +2380,7 @@ get_gpu() { [[ -z "$(trim "$gpu")" ]] && gpu="Intel Integrated Graphics" ;; - *"virtualbox"*) + *"VirtualBox"*) gpu="VirtualBox Graphics Adapter" ;; @@ -4261,7 +4272,11 @@ info() { [[ "$prin" ]] && return # Update the variable. - output="$(trim "${!2:-${!1}}")" + if [[ "$2" ]]; then + output="$(trim "${!2}")" + else + output="$(trim "${!1}")" + fi if [[ "$2" && "${output// }" ]]; then prin "$1" "$output" From c2fcf35ab1a103065c0804b0bd9874f5052932eb Mon Sep 17 00:00:00 2001 From: Crestwave Date: Thu, 16 Apr 2020 09:52:25 +0800 Subject: [PATCH 2/6] neofetch: only fork for {BASH,OIL}_VERSION when necessary --- neofetch | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/neofetch b/neofetch index 4c12b86c..234a7907 100755 --- a/neofetch +++ b/neofetch @@ -33,7 +33,6 @@ version=7.0.0 if [[ "$BASH_VERSION" ]]; then bash_version=${BASH_VERSION/.*} else - BASH_VERSION=$(bash -c "printf %s \"\$BASH_VERSION\"") bash_version=5 shopt -s eval_unsafe_arith fi @@ -1590,7 +1589,11 @@ get_shell() { [[ $shell_version != on ]] && return case ${shell_name:=${SHELL##*/}} in - bash) shell+=${BASH_VERSION/-*} ;; + bash) + [[ $BASH_VERSION ]] || + BASH_VERSION=$("$SHELL" -c "printf %s \"\$BASH_VERSION\"") + shell+=${BASH_VERSION/-*} + ;; sh|ash|dash) ;; @@ -1601,7 +1604,11 @@ get_shell() { ;; osh) - shell+=$("$SHELL" -c "printf %s \"\$OIL_VERSION\"") + if [[ $OIL_VERSION ]]; then + shell+=$OIL_VERSION + else + shell+=$("$SHELL" -c "printf %s \"\$OIL_VERSION\"") + fi ;; tcsh) From 8e56495da8fa3557de47be60facddc670a41947a Mon Sep 17 00:00:00 2001 From: Crestwave Date: Thu, 16 Apr 2020 09:57:39 +0800 Subject: [PATCH 3/6] neofetch: remove unnecessary(?) parameter expansion and BASH_VERSINFO --- neofetch | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/neofetch b/neofetch index 234a7907..9d92964e 100755 --- a/neofetch +++ b/neofetch @@ -30,8 +30,8 @@ version=7.0.0 -if [[ "$BASH_VERSION" ]]; then - bash_version=${BASH_VERSION/.*} +if [[ "${BASH_VERSINFO[0]}" ]]; then + bash_version=${BASH_VERSINFO[0]} else bash_version=5 shopt -s eval_unsafe_arith @@ -3992,7 +3992,7 @@ get_window_size() { # # False positive. # shellcheck disable=2141 - case ${BASH_VERSINFO[0]} in + case $bash_version in 4|5) IFS=';t' read -d t -t 0.05 -sra term_size ;; *) IFS=';t' read -d t -t 1 -sra term_size ;; esac @@ -4240,7 +4240,7 @@ display_image() { # Add a tiny delay to fix issues with images not # appearing in specific terminal emulators. - ((BASH_VERSINFO[0]>3)) && sleep 0.05 + ((bash_version>3)) && sleep 0.05 printf '%b\n%s;\n%s\n' "0;1;$xoffset;$yoffset;$width;$height;;;;;$image" 3 4 |\ "${w3m_img_path:-false}" -bg "$background_color" &>/dev/null ;; From 2943116dd552783f51303d5d08ab92b95f9ef806 Mon Sep 17 00:00:00 2001 From: Crestwave Date: Thu, 16 Apr 2020 14:47:13 +0800 Subject: [PATCH 4/6] neofetch: clean up --- neofetch | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/neofetch b/neofetch index 9d92964e..5b3362d1 100755 --- a/neofetch +++ b/neofetch @@ -30,13 +30,8 @@ version=7.0.0 -if [[ "${BASH_VERSINFO[0]}" ]]; then - bash_version=${BASH_VERSINFO[0]} -else - bash_version=5 - shopt -s eval_unsafe_arith -fi - +bash_version=${BASH_VERSINFO[0]:-5} +shopt -s eval_unsafe_arith &>/dev/null sys_locale=${LANG:-C} XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-${HOME}/.config} PATH=$PATH:/usr/xpg4/bin:/usr/sbin:/sbin:/usr/etc:/usr/libexec From b441c57aeac0359ad9fe9fa4c35fe2020a317466 Mon Sep 17 00:00:00 2001 From: Crestwave Date: Thu, 16 Apr 2020 14:56:45 +0800 Subject: [PATCH 5/6] neofetch: add comments --- neofetch | 2 ++ 1 file changed, 2 insertions(+) diff --git a/neofetch b/neofetch index 5b3362d1..fcd2d219 100755 --- a/neofetch +++ b/neofetch @@ -30,6 +30,8 @@ version=7.0.0 +# Fallback to a value of '5' for shells which support bash +# but do not set the 'BASH_' shell variables (osh). bash_version=${BASH_VERSINFO[0]:-5} shopt -s eval_unsafe_arith &>/dev/null sys_locale=${LANG:-C} From d0d6d208b0cc4b0000d3045108d56b8af7ad16bb Mon Sep 17 00:00:00 2001 From: Crestwave Date: Thu, 16 Apr 2020 15:00:12 +0800 Subject: [PATCH 6/6] neofetch: clean up --- neofetch | 2 ++ 1 file changed, 2 insertions(+) diff --git a/neofetch b/neofetch index fcd2d219..050eb60d 100755 --- a/neofetch +++ b/neofetch @@ -34,6 +34,7 @@ version=7.0.0 # but do not set the 'BASH_' shell variables (osh). bash_version=${BASH_VERSINFO[0]:-5} shopt -s eval_unsafe_arith &>/dev/null + sys_locale=${LANG:-C} XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-${HOME}/.config} PATH=$PATH:/usr/xpg4/bin:/usr/sbin:/sbin:/usr/etc:/usr/libexec @@ -1589,6 +1590,7 @@ get_shell() { bash) [[ $BASH_VERSION ]] || BASH_VERSION=$("$SHELL" -c "printf %s \"\$BASH_VERSION\"") + shell+=${BASH_VERSION/-*} ;;