Move the commands near the bottom of the script to a function called main
This commit is contained in:
parent
2511511174
commit
7a774dd48d
1 changed files with 92 additions and 85 deletions
177
neofetch
177
neofetch
|
@ -2532,14 +2532,11 @@ getdefaultconfig () {
|
|||
fi
|
||||
}
|
||||
|
||||
# Source config file
|
||||
getdefaultconfig 2>/dev/null
|
||||
|
||||
# }}}
|
||||
|
||||
# Source Config {{{
|
||||
|
||||
getconfig () {
|
||||
getuserconfig () {
|
||||
# Check $config_file
|
||||
if [ -f "$config_file" ]; then
|
||||
source "$config_file"
|
||||
|
@ -2579,7 +2576,9 @@ case "$@" in
|
|||
config="off"
|
||||
;;
|
||||
esac
|
||||
[ "${config:-on}" == "on" ] && getconfig 2>/dev/null
|
||||
|
||||
getdefaultconfig 2>/dev/null
|
||||
[ "${config:-on}" == "on" ] && getuserconfig 2>/dev/null
|
||||
|
||||
|
||||
# }}}
|
||||
|
@ -2925,7 +2924,7 @@ while [ "$1" ]; do
|
|||
--config)
|
||||
case "$2" in
|
||||
"none" | "off") config="off" ;;
|
||||
*) config_file="$2"; config="on"; getconfig 2>/dev/null ;;
|
||||
*) config_file="$2"; config="on"; getuserconfig 2>/dev/null ;;
|
||||
esac
|
||||
;;
|
||||
--test)
|
||||
|
@ -2973,106 +2972,114 @@ done
|
|||
|
||||
# Call Functions and Finish Up {{{
|
||||
|
||||
# Restore cursor and clear screen on ctrl+c
|
||||
trap 'printf "\033[?25h"; clear; exit' 2
|
||||
main () {
|
||||
# Restore cursor and clear screen on ctrl+c
|
||||
trap 'printf "\033[?25h"; clear; exit' 2
|
||||
|
||||
# Distro detection
|
||||
getdistro
|
||||
case "${ascii_distro:-auto}" in
|
||||
"auto") ascii_distro="$(trim "$distro")" ;;
|
||||
esac
|
||||
# If the script exits for any reason, unhide the cursor.
|
||||
trap 'printf "\033[?25h"' EXIT
|
||||
|
||||
# Get colors and bold
|
||||
bold
|
||||
colors
|
||||
# Distro detection
|
||||
getdistro
|
||||
case "${ascii_distro:-auto}" in
|
||||
"auto") ascii_distro="$(trim "$distro")" ;;
|
||||
esac
|
||||
|
||||
# If the script exits for any reason, unhide the cursor.
|
||||
trap 'printf "\033[?25h"' EXIT
|
||||
# Get colors and bold
|
||||
bold
|
||||
colors
|
||||
|
||||
# Clear the scren
|
||||
clear
|
||||
# Clear the scren
|
||||
clear
|
||||
|
||||
# Hide the cursor
|
||||
printf "\033[?25l"
|
||||
# Hide the cursor
|
||||
printf "\033[?25l"
|
||||
|
||||
if [ "$image" != "off" ]; then
|
||||
# If iterm2 is detected use iterm2 backend.
|
||||
if [ -n "$ITERM_PROFILE" ]; then
|
||||
image_backend="iterm2"
|
||||
# Images {{{
|
||||
|
||||
elif [ "$(tycat 2>/dev/null)" ]; then
|
||||
image_backend="tycat"
|
||||
# Get the image src
|
||||
if [ "$image" != "off" ]; then
|
||||
# Set the image backend
|
||||
if [ -n "$ITERM_PROFILE" ]; then
|
||||
image_backend="iterm2"
|
||||
|
||||
else
|
||||
image_backend="w3m"
|
||||
elif [ "$(tycat 2>/dev/null)" ]; then
|
||||
image_backend="tycat"
|
||||
|
||||
else
|
||||
image_backend="w3m"
|
||||
fi
|
||||
|
||||
# Find w3mimgdisplay
|
||||
[ "$image_backend" == "w3m" ] && \
|
||||
[ "$image" != "ascii" ] && \
|
||||
getw3m_img_path
|
||||
|
||||
# Get the image
|
||||
getimage
|
||||
fi
|
||||
|
||||
# Find w3mimgdisplay
|
||||
[ "$image_backend" == "w3m" ] && \
|
||||
[ "$image" != "ascii" ] && \
|
||||
getw3m_img_path
|
||||
# Display the image if enabled
|
||||
if [ "$image" != "off" ] && [ "$image" != "ascii" ]; then
|
||||
case "$image_backend" in
|
||||
"w3m")
|
||||
printf "%b%s\n" "0;1;$xoffset;$yoffset;$width;$height;;;;;$img\n4;\n3;" |\
|
||||
$w3m_img_path 2>/dev/null || padding="\033[0C"
|
||||
;;
|
||||
|
||||
# Get the image
|
||||
getimage
|
||||
fi
|
||||
"iterm2")
|
||||
printf "%b%s\a\n" "\033]1337;File=width=${width}px;height=${height}px;inline=1:$(base64 < "$img")"
|
||||
;;
|
||||
|
||||
# Display the image if enabled
|
||||
if [ "$image" != "off" ] && [ "$image" != "ascii" ]; then
|
||||
case "$image_backend" in
|
||||
"w3m")
|
||||
printf "%b%s\n" "0;1;$xoffset;$yoffset;$width;$height;;;;;$img\n4;\n3;" |\
|
||||
$w3m_img_path 2>/dev/null || padding="\033[0C"
|
||||
;;
|
||||
"tycat")
|
||||
tycat "$img"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
"iterm2")
|
||||
printf "%b%s\a\n" "\033]1337;File=width=${width}px;height=${height}px;inline=1:$(base64 < "$img")"
|
||||
;;
|
||||
# }}}
|
||||
|
||||
"tycat")
|
||||
tycat "$img"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
# Disable line wrap
|
||||
printf "\033[?7l"
|
||||
|
||||
# Disable line wrap
|
||||
printf "\033[?7l"
|
||||
# Move cursor to the top
|
||||
[ "$image" != "off" ] && printf "\033[0H"
|
||||
|
||||
# Move cursor to the top
|
||||
[ "$image" != "off" ] && printf "\033[0H"
|
||||
# Print the info
|
||||
printinfo
|
||||
|
||||
# Print the info
|
||||
printinfo
|
||||
# Dynamic prompt location {{{
|
||||
|
||||
# Dynamic prompt location {{{
|
||||
# Get cursor position
|
||||
info_height="$(stty -echo; IFS=';' read -rdR -t 1 -d c -p $'\033[6n\033[c' ROW COL; printf "%s" "${ROW#*[}"; stty echo)"
|
||||
|
||||
# Get cursor position
|
||||
info_height="$(stty -echo; IFS=';' read -rdR -t 1 -d c -p $'\033[6n\033[c' ROW COL; printf "%s" "${ROW#*[}"; stty echo)"
|
||||
# Calculate image height in terminal cells.
|
||||
# The '+ 3' adds a gap between the prompt and the content.
|
||||
[ "$image" != "ascii" ] && [ "$image" != "off" ] && \
|
||||
lines="$((${height:-1} / ${font_height:-1} + 3))"
|
||||
|
||||
# Calculate image height in terminal cells.
|
||||
# The '+ 3' adds a gap between the prompt and the content.
|
||||
[ "$image" != "ascii" ] && [ "$image" != "off" ] && \
|
||||
lines="$((${height:-1} / ${font_height:-1} + 3))"
|
||||
# If the info is higher than the ascii/image place the prompt
|
||||
# based on the info height instead of the ascii/image height.
|
||||
[ "${lines:-0}" -lt "${info_height:-0}" ] && lines="$info_height"
|
||||
|
||||
# If the info is higher than the ascii/image place the prompt
|
||||
# based on the info height instead of the ascii/image height.
|
||||
[ "${lines:-0}" -lt "${info_height:-0}" ] && lines="$info_height"
|
||||
# Set the prompt location
|
||||
[ "$image" != "off" ] && printf "%b%s" "\033[${lines:-0}H"
|
||||
|
||||
# Set the prompt location
|
||||
[ "$image" != "off" ] && printf "%b%s" "\033[${lines:-0}H"
|
||||
|
||||
# }}}
|
||||
|
||||
# Re-enable line wrap
|
||||
printf "%b%s" "\033[?7h"
|
||||
|
||||
# If enabled take a screenshot
|
||||
if [ "$scrot" == "on" ]; then
|
||||
takescrot
|
||||
fi
|
||||
|
||||
# Show error messages
|
||||
if [ "$verbose" == "on" ]; then
|
||||
printf "%s" "$err"
|
||||
fi
|
||||
# }}}
|
||||
|
||||
# Re-enable line wrap
|
||||
printf "%b%s" "\033[?7h"
|
||||
|
||||
# If enabled take a screenshot
|
||||
[ "$scrot" == "on" ] && takescrot
|
||||
|
||||
# Show error messages
|
||||
[ "$verbose" == "on" ] && printf "%s" "$err"
|
||||
|
||||
# Reset exit status of the tests above.
|
||||
printf "%s"
|
||||
}
|
||||
|
||||
main
|
||||
|
||||
# }}}
|
||||
|
|
Loading…
Reference in a new issue