Skip to content

Commit 96bd33c

Browse files
committed
misc: cleanup
1 parent ab01e65 commit 96bd33c

File tree

1 file changed

+58
-56
lines changed

1 file changed

+58
-56
lines changed

neofetch

Lines changed: 58 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2698,38 +2698,42 @@ get_term() {
26982698
# Workaround for macOS systems that
26992699
# don't support the block below.
27002700
case "$TERM_PROGRAM" in
2701-
"iTerm.app") term="iTerm2" ;;
2701+
"iTerm.app") term="iTerm2" ;;
27022702
"Terminal.app") term="Apple Terminal" ;;
2703-
"Hyper") term="HyperTerm" ;;
2704-
*) term="${TERM_PROGRAM/\.app}" ;;
2703+
"Hyper") term="HyperTerm" ;;
2704+
*) term="${TERM_PROGRAM/\.app}" ;;
27052705
esac
27062706

27072707
# Most likely TosWin2 on FreeMiNT - quick check
27082708
[[ "$TERM" == "tw52" || "$TERM" == "tw100" ]] && \
27092709
term="TosWin2"
27102710

2711+
[[ "$SSH_CONNECTION" ]] && \
2712+
term="$SSH_TTY"
2713+
27112714
# Check $PPID for terminal emulator.
27122715
while [[ -z "$term" ]]; do
2713-
if [[ "$SSH_CONNECTION" ]]; then
2714-
term="$SSH_TTY"; break
2715-
else
2716-
parent="$(get_ppid "$parent")"
2717-
[[ -z "$parent" ]] && break
2718-
name="$(get_process_name "$parent")"
2719-
case "${name// }" in
2720-
"${SHELL/*\/}" | *"sh" | "screen" | "su"*) ;;
2721-
"login"* | *"Login"* | "init" | "(init)") term="$(tty)" ;;
2722-
"ruby" | "1" | "systemd" | "sshd"* | "python"* |\
2723-
"USER"*"PID"* | "kdeinit"* | "launchd"*)
2724-
break
2725-
;;
2726-
"gnome-terminal-") term="gnome-terminal" ;;
2727-
*"nvim") term="Neovim Terminal" ;;
2728-
*"NeoVimServer"*) term="VimR Terminal" ;;
2729-
*"tmux"*) term="tmux" ;;
2730-
*) term="${name##*/}" ;;
2731-
esac
2732-
fi
2716+
parent="$(get_ppid "$parent")"
2717+
[[ -z "$parent" ]] && break
2718+
name="$(get_process_name "$parent")"
2719+
2720+
case "${name// }" in
2721+
"${SHELL/*\/}"|*"sh"|"screen"|"su"*) ;;
2722+
2723+
"login"*|*"Login"*|"init"|"(init)")
2724+
term="$(tty)"
2725+
;;
2726+
2727+
"ruby"|"1"|"systemd"|"sshd"*|"python"*|"USER"*"PID"*|"kdeinit"*|"launchd"*)
2728+
break
2729+
;;
2730+
2731+
"gnome-terminal-") term="gnome-terminal" ;;
2732+
*"nvim") term="Neovim Terminal" ;;
2733+
*"NeoVimServer"*) term="VimR Terminal" ;;
2734+
*"tmux"*) term="tmux" ;;
2735+
*) term="${name##*/}" ;;
2736+
esac
27332737
done
27342738

27352739
# Log that the function was run.
@@ -3351,7 +3355,7 @@ image_backend() {
33513355
printf '\e[2J\e[H'
33523356
get_image_size
33533357
make_thumbnail
3354-
display_image
3358+
display_image || to_off "Image: $image_backend failed to display the image."
33553359
;;
33563360

33573361
*)
@@ -3708,54 +3712,52 @@ make_thumbnail() {
37083712
display_image() {
37093713
case "$image_backend" in
37103714
"caca")
3711-
img2txt -W "$((width / font_width)))" \
3712-
-H "$((height / font_height))" \
3713-
--gamma=0.6 "$image" ||\
3714-
to_off "Image: libcaca failed to display the image."
3715+
img2txt \
3716+
-W "$((width / font_width)))" \
3717+
-H "$((height / font_height))" \
3718+
--gamma=0.6 \
3719+
"$image"
37153720
;;
37163721

37173722
"jp2a")
3718-
jp2a --width="$((width / font_width))" \
3719-
--height="$((height / font_height))" \
3720-
--colors "$image" ||\
3721-
to_off "Image: jp2a failed to display the image."
3723+
jp2a \
3724+
--width="$((width / font_width))" \
3725+
--height="$((height / font_height))" \
3726+
--colors \
3727+
"$image"
37223728
;;
37233729

37243730
"kitty")
37253731
kitty icat \
3726-
--align left \
3727-
--place "$((width / font_width))x$((height / font_height))\
3728-
@${xoffset}x${yoffset}" \
3729-
"$image" ||\
3730-
to_off "Image: kitty failed to display the image."
3732+
--align left \
3733+
--place "$((width/font_width))x$((height/font_height))@${xoffset}x${yoffset}" \
3734+
"$image"
37313735
;;
37323736

37333737
"pixterm")
3734-
pixterm -tc "$((width / font_width))" \
3735-
-tr "$((height / font_height))" \
3736-
"$image" ||\
3737-
to_off "Image: pixterm failed to display the image."
3738+
pixterm \
3739+
-tc "$((width / font_width))" \
3740+
-tr "$((height / font_height))" \
3741+
"$image"
37383742
;;
37393743

37403744
"sixel")
3741-
img2sixel -w "$width" \
3742-
-h "$height" \
3743-
"$image" ||\
3744-
to_off "Image: libsixel failed to display the image."
3745+
img2sixel \
3746+
-w "$width" \
3747+
-h "$height" \
3748+
"$image"
37453749
;;
37463750

37473751
"termpix")
3748-
termpix --width "$((width / font_width))" \
3749-
--height "$((height / font_height))" \
3750-
"$image" ||\
3751-
to_off "Image: termpix failed to display the image."
3752+
termpix \
3753+
--width "$((width / font_width))" \
3754+
--height "$((height / font_height))" \
3755+
"$image"
37523756
;;
37533757

37543758
"iterm2")
3755-
image="$(base64 < "$image")"
3756-
37573759
printf -v iterm_cmd '\e]1337;File=width=%spx;height=%spx;inline=1:%s' \
3758-
"$width" "$height" "$image"
3760+
"$width" "$height" "$(base64 < "$image")"
37593761

37603762
# Tmux requires an additional escape sequence for this to work.
37613763
[[ -n "$TMUX" ]] && printf -v iterm_cmd '\ePtmux;\e%b\e'\\ "$iterm_cmd"
@@ -3764,8 +3766,9 @@ display_image() {
37643766
;;
37653767

37663768
"tycat")
3767-
tycat -g "${width}x${height}" "$image" ||\
3768-
to_off "Image: tycat failed to display the image."
3769+
tycat \
3770+
-g "${width}x${height}" \
3771+
"$image"
37693772
;;
37703773

37713774
"w3m")
@@ -3776,8 +3779,7 @@ display_image() {
37763779
# appearing in specific terminal emulators.
37773780
sleep 0.05
37783781
printf '%b\n%s;\n%s\n' "0;1;$xoffset;$yoffset;$width;$height;;;;;$image" 3 4 |\
3779-
"${w3m_img_path:-false}" -bg "$background_color" &>/dev/null ||\
3780-
to_off "Image: w3m-img failed to display the image."
3782+
"${w3m_img_path:-false}" -bg "$background_color" &>/dev/null
37813783
;;
37823784
esac
37833785
}

0 commit comments

Comments
 (0)