Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

neofetch: add support for OSH #1442

Merged
merged 6 commits into from
Apr 16, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 30 additions & 9 deletions neofetch
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,11 @@

version=7.0.0

bash_version=${BASH_VERSION/.*}
# 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
Comment on lines +35 to +36
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# 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

Copy link
Contributor Author

@Crestwave Crestwave Apr 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that I actually set BASH_VERSION later on. I could probably use shell+=$BASH_VERSION; shell=${shell/-*} instead

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind, that doesn't make sense. At all.

Copy link
Contributor Author

@Crestwave Crestwave Apr 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I think what I was going for was:

if [[ $BASH_VERSION ]]; then
    shell+=$("$SHELL" -c "printf %s \"\$BASH_VERSION\"")
else
    shell+=$BASH_VERSION
fi
shell=${shell/-*}

Copy link
Contributor Author

@Crestwave Crestwave Apr 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or actually, something like:

shell+=${BASH_VERSION:-$("$SHELL" -c "printf %s \"\$BASH_VERSION\"")}
shell=${shell/-*}

But if you're fine with that, then cool

Crestwave marked this conversation as resolved.
Show resolved Hide resolved

sys_locale=${LANG:-C}
XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-${HOME}/.config}
PATH=$PATH:/usr/xpg4/bin:/usr/sbin:/sbin:/usr/etc:/usr/libexec
Expand Down Expand Up @@ -1583,7 +1587,12 @@ 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\"")
Crestwave marked this conversation as resolved.
Show resolved Hide resolved

shell+=${BASH_VERSION/-*}
;;

sh|ash|dash) ;;

Expand All @@ -1593,6 +1602,14 @@ get_shell() {
shell=${shell/version}
;;

osh)
if [[ $OIL_VERSION ]]; then
shell+=$OIL_VERSION
else
shell+=$("$SHELL" -c "printf %s \"\$OIL_VERSION\"")
fi
;;

tcsh)
shell+=$("$SHELL" -c "printf %s \$tcsh")
;;
Expand Down Expand Up @@ -2338,7 +2355,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}}"
Expand All @@ -2352,13 +2369,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}"
Expand All @@ -2369,7 +2386,7 @@ get_gpu() {
[[ -z "$(trim "$gpu")" ]] && gpu="Intel Integrated Graphics"
;;

*"virtualbox"*)
*"VirtualBox"*)
gpu="VirtualBox Graphics Adapter"
;;

Expand Down Expand Up @@ -3974,7 +3991,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
Expand Down Expand Up @@ -4222,7 +4239,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
;;
Expand Down Expand Up @@ -4261,7 +4278,11 @@ info() {
[[ "$prin" ]] && return

# Update the variable.
output="$(trim "${!2:-${!1}}")"
if [[ "$2" ]]; then
output="$(trim "${!2}")"
else
output="$(trim "${!1}")"
fi
Crestwave marked this conversation as resolved.
Show resolved Hide resolved

if [[ "$2" && "${output// }" ]]; then
prin "$1" "$output"
Expand Down