Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
neofetch
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Ximper Linux
neofetch
Commits
89c43b1f
Commit
89c43b1f
authored
Nov 13, 2016
by
Dylan Araps
Committed by
GitHub
Nov 13, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #436 from dylanaraps/image
Images: Rewrite image functions
parents
232ac07f
aba89c8a
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
251 additions
and
208 deletions
+251
-208
config
config/config
+2
-2
neofetch
neofetch
+249
-206
No files found.
config/config
View file @
89c43b1f
...
...
@@ -287,8 +287,8 @@ disk_display="off"
# Image Source
# --image wall
, ascii
, /path/to/img, /path/to/dir/, off
image
=
"wall
"
# --image wall
paper
, /path/to/img, /path/to/dir/, off
image
_source
=
"wallpaper
"
# Thumbnail directory
thumbnail_dir
=
"
$HOME
/.cache/thumbnails/neofetch"
...
...
neofetch
View file @
89c43b1f
...
...
@@ -1464,7 +1464,7 @@ get_term_font() {
case "
$term
" in
"
urxvt
" | "
urxvtd
" | "
xterm
")
term_font="
$(
grep
-i
-F
"
${
term
/d
}
*font"
<
<<
"
$(
xrdb
-query
)
"
)
"
term_font="
$(
grep
-i
-F
"
${
term
/d
}
*font"
<
<
(
xrdb
-query
)
)
"
term_font="
${
term_font
/*font
:
}
"
term_font="
$(
trim
"
$term_font
"
)
"
...
...
@@ -1791,69 +1791,81 @@ get_cols() {
# Add newlines to the string.
cols="
${
cols
%%
'nl'
}
"
cols="
${
cols
//nl/\\n
${
padding
}
${
zws
}}
"
cols="
${
cols
//nl/\\n
\\033[
${
text_padding
}
C
${
zws
}}
"
fi
}
# IMAGES
get_wallpaper() {
case "
$os
" in
"
Linux
" | "
BSD
")
if type -p feh >/dev/null && [[ -f "
$HOME
/.fehbg
" ]]; then
img="
$(
awk
-F
\'
'/feh/ {printf $2}'
"
$HOME
/.fehbg"
)
"
get_image_backend() {
# This function determines which image backend to use
# by checking for programs and etc.
elif type -p nitrogen >/dev/null; then
img="
$(
awk
-F
'='
'/file/ {printf $2;exit;}'
"
$XDG_CONFIG_HOME
/nitrogen/bg-saved.cfg"
)
"
# Automatically find w3m-img
get_w3m_img_path
elif type -p gsettings >/dev/null; then
# Get DE if user has disabled the function.
[[ -z "
$de
" ]] && get_de
# Fallback to ascii mode if imagemagick isn't installed.
type -p convert >/dev/null 2>&1 || image_backend="
ascii
"
case "
$de
" in
"
MATE
"*) img="
$(
gsettings get org.mate.background picture-filename
)
" ;;
*) img="
$(
gsettings get org.gnome.desktop.background picture-uri
)
" ;;
esac
case "
${
image_backend
:
=image
}
" in
"
image
")
case "
$image_source
" in
"
wall
"*) get_wallpaper 2>/dev/null ;;
"
off
") image_backend="
off
"; return ;;
*)
if [[ -d "
$image_source
" ]]; then
files=("
${
image_source
%/
}
"/*.{png,jpg,jpeg})
image="
$(
printf
"%s"
"
${
files
[RANDOM % (
${#
files
[@]
}
- 1)]
}
"
)
"
else
image="
$image_source
"
fi
;;
esac
# Strip quotes etc from the path
.
img="
${
img
/
'file://'
}
"
img="
${
img
//\
'}
"
img="${img//\%20/ }"
# Fallback to ascii mode if image isn't a file
.
if [[ ! -f "
$image
" ]]; then
to_ascii "
Image
:
'$image'
doesn
't exist, falling back to ascii mode.
"
return
fi
;;
"Mac OS X")
img="$(osascript -e '
tell
application
"System Events"
to picture of current desktop
')"
;;
get_image_program
get_term_size
"Windows")
case "$distro" in
"Windows XP")
img="/cygdrive/c/Documents and Settings/${USER}"
img+="/Local Settings/Application Data/Microsoft"
img+="/Wallpaper1.bmp"
;;
# Fallback to ascii mode if terminal size wasn'
t
found.
if [[ -z
"
$term_width
"
]] && ((term_width == 0)); then
to_ascii
"Image: Failed to find terminal window size"
return
fi
"Windows"*)
img="$APPDATA/Microsoft/Windows/Themes"
img+="/TranscodedWallpaper.jpg"
;;
esac
get_image_size
make_thumbnail
# If the backend is still set to
'image'
after
# make_thumbnail(), then display the image.
[[
"
$image_backend
"
==
"image"
]] && display_image
;;
"ascii"
) get_ascii 2>/dev/null ;;
esac
}
# If img is an xml file don'
t
use it.
[[
"
${
img
/*\./
}
"
==
"xml"
]] && img=
""
get_image_program() {
if [[ -n "
$ITERM_PROFILE
" ]]; then
image_program="
iterm2
"
elif [[ "
$(
tycat 2>/dev/null
)
" ]]; then
image_program="
tycat
"
# Error msg
[[ -z
"
$img
"
]] && err
"Image: Wallpaper detection failed, falling back to ascii mode."
else
image_program="
w3m
"
fi
}
get_ascii() {
if [[ ! -f "
$ascii
" || "
$ascii
" == "
distro
" ]]; then
# Error message
[[
"
$ascii
"
!=
"distro"
]] && \
[[ ! -f
"
$ascii
"
]] && err
"Ascii: Ascii file not found, using distro ascii
"
[[ "
$ascii
" != "
distro
" ]] &&
[[ ! -f "
$ascii
" ]] &&
\
err "
Ascii: Ascii file not found, using distro ascii.
"
# Lowercase the distro name
if (("
$version
" <= 3)); then
...
...
@@ -1880,14 +1892,13 @@ get_ascii() {
get_script_dir 2>/dev/null
# If the ascii file doesn't exist fallback to text mode.
if [[ ! -f "$script_dir/ascii/distro/${ascii/ *}" ]]; then
padding="\033[0C"
image="off"
err "Ascii: Ascii file not found, falling back to text mode."
if [[ -f "
$script_dir
/ascii/distro/
${
ascii
/ *
}
" ]]; then
ascii="
$script_dir
/ascii/distro/
${
ascii
/ *
}
"
else
to_off "
Ascii: Ascii file not found, falling back to text mode.
"
return
fi
ascii="$script_dir/ascii/distro/${ascii/ *}"
fi
fi
...
...
@@ -1916,33 +1927,99 @@ get_ascii() {
# Overwrite padding if ascii_length_force is set.
[[ "
$ascii_length_force
" ]] && ascii_length="
$ascii_length_force
"
padding="\033[$((ascii_length + gap))C
"
text_padding="
$((
ascii_length
+
gap
))
"
printf "
%b
" "
$print
"
export LC_ALL=C
}
get_
image
() {
# Fallback to ascii mode if imagemagick isn'
t
installed.
type -p convert >/dev/null 2>&1 || image=
"ascii"
get_
w3m_img_path
() {
if [[ -x "
$w3m_img_path
" ]]; then
return
case
"
$image
"
in
"wall"
) get_wallpaper 2>/dev/null ;;
"ascii"
) get_ascii; return ;;
*)
if [[ -d
"
$image
"
]]; then
files=(
"
${
image
%/
}
"
/*.{png,jpg,jpeg
}
)
img="
$(
printf
"%s"
"
${
files
[RANDOM % (
${#
files
[@]
}
- 1)]
}
"
)
"
else
img="
$image
"
elif [[ -x "
/usr/lib/w3m/w3mimgdisplay
" ]]; then
w3m_img_path="
/usr/lib/w3m/w3mimgdisplay
"
elif [[ -x "
/usr/libexec/w3m/w3mimgdisplay
" ]]; then
w3m_img_path="
/usr/libexec/w3m/w3mimgdisplay
"
elif [[ -x "
/usr/lib64/w3m/w3mimgdisplay
" ]]; then
w3m_img_path="
/usr/lib64/w3m/w3mimgdisplay
"
elif [[ -x "
/usr/libexec64/w3m/w3mimgdisplay
" ]]; then
w3m_img_path="
/usr/libexec64/w3m/w3mimgdisplay
"
else
image_backend="
ascii
"
err "
Image: w3m-img wasn
't found on your system, falling back to ascii mode."
fi
}
get_wallpaper() {
case "$os" in
"Linux" | "BSD")
if type -p feh >/dev/null && [[ -f "$HOME/.fehbg" ]]; then
image="$(awk -F\'
'/feh/ {printf $2}'
"
$HOME
/.fehbg"
)
"
elif type -p nitrogen >/dev/null; then
image="
$(
awk
-F
'='
'/file/ {printf $2;exit;}'
"
$XDG_CONFIG_HOME
/nitrogen/bg-saved.cfg"
)
"
elif type -p gsettings >/dev/null; then
# Get DE if user has disabled the function.
[[ -z "
$de
" ]] && get_de
case "
$de
" in
"
MATE
"*) image="
$(
gsettings get org.mate.background picture-filename
)
" ;;
*) image="
$(
gsettings get org.gnome.desktop.background picture-uri
)
" ;;
esac
# Strip quotes etc from the path.
image="
${
image
/
'file://'
}
"
image="
${
image
//\
'}"
image="${image//\%20/ }"
fi
;;
"Mac OS X")
image="$(osascript -e '
tell
application
"System Events"
to picture of current desktop
')"
;;
"Windows")
case "$distro" in
"Windows XP")
image="/cygdrive/c/Documents and Settings/${USER}"
image+="/Local Settings/Application Data/Microsoft"
image+="/Wallpaper1.bmp"
;;
"Windows"*)
image="$APPDATA/Microsoft/Windows/Themes"
image+="/TranscodedWallpaper.jpg"
;;
esac
;;
esac
# If image is an xml file, don'
t
use it.
[[
"
${
image
/*\./
}
"
==
"xml"
]] && image=
""
}
get_term_size
()
{
# This functions gets the current window size in
# pixels.
#
# We first try to use the escape sequence '\044[14t'
# to get the terminal window size in pixels. If this
# fails we then fallback to using 'xdotool' or other
# programs.
# Tmux has a special way of reading escape sequences
# so we have to use a slightly different sequence to
# get the terminal size.
if
[[
-n
"
$TMUX
"
]]
;
then
printf
"%b"
"
\0
33Ptmux;
\0
33
\0
33[14t
\0
33
\0
33[c
\0
33
\\
"
read_flags
=
"-d c"
elif [[ "
$image_
backend
" == "
tycat
" ]]; then
elif
[[
"
$image_
program
"
==
"tycat"
]]
;
then
printf
"%b"
"
\0
33}qs
\0
00"
else
...
...
@@ -1950,11 +2027,13 @@ get_image() {
read_flags
=
"-d c"
fi
# The escape code above prints the output AFTER the prompt so this
# The escape codes above print the desired output as
# user input so we have to use read to store the out
# -put as a variable.
builtin read
-s
-t
1
${
read_flags
}
-r
term_size
# Split the string
if [[ "
$image_
backend
" == "
tycat
" ]]; then
# Split the string
into height/width.
if
[[
"
$image_
program
"
==
"tycat"
]]
;
then
term_size
=(
${
term_size
//;/
}
)
term_width
=
"
$((
term_size[2]
*
term_size[0]
))
"
term_height
=
"
$((
term_size[3]
*
term_size[1]
))
"
...
...
@@ -1969,46 +2048,44 @@ get_image() {
fi
# Get terminal width and height if \033[14t is unsupported.
if (("
${#
term_size
}
" <= 5)) && [[ "
$image_backend
" != "
tycat
" ]]; then
if type -p xdotool >/dev/null 2>&1 &&
\
[[ "
$image_backend
" != "
iterm2
" ]]; then
if
((
"
${#
term_size
}
"
<
=
5
))
&&
[[
"
$image_program
"
==
"w3m"
]]
;
then
if
type
-p
xdotool
>
/dev/null 2>&1
;
then
current_window
=
"
$(
xdotool getactivewindow
)
"
source
<
(
xdotool getwindowgeometry
--shell
"
$current_window
"
)
term_height
=
"
$HEIGHT
"
term_width
=
"
$WIDTH
"
elif type -p xwininfo >/dev/null 2>&1 &&
\
type -p xdpyinfo >/dev/null 2>&1 ||
\
type -p xprop >/dev/null 2>&1 &&
\
[[ "
$image_backend
" != "
iterm2
" ]]; then
elif
type
-p
xwininfo
>
/dev/null 2>&1
;
then
# Get the focused window's ID.
if
type
-p
xdpyinfo
>
/dev/null 2>&1
;
then
current_window
=
"
$(
xdpyinfo |
grep
-F
"focus"
|
grep
-E
-o
"0x[0-9a-f]+"
)
"
elif
type
-p
xprop
>
/dev/null 2>&1
;
then
current_window
=
"
$(
xprop
-root
|
awk
'/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}'
)
"
fi
term_size="
$(
xwininfo
-id
"
$current_window
"
|
awk
-F
': '
'/Width|Height/ {printf $2 " "}'
)
"
term_width="
${
term_size
/ *
}
"
term_height="
${
term_size
/
${
term_width
}}
"
# If the ID was found get the window size.
if
[[
"
$current_window
"
]]
;
then
term_size
=
"
$(
xwininfo
-id
"
$current_window
"
|
awk
-F
': '
'/Width|Height/ {printf $2 " "}'
)
"
term_width
=
"
${
term_size
/ *
}
"
term_height
=
"
${
term_size
/
${
term_width
}}
"
else
term_width
=
"0"
fi
else
term_width
=
"0"
fi
fi
# If
$img
isn't a file fallback to ascii mode.
if [[ ! -f "
$img
" || -z "
$term_width
" ]] || (("
$term_width
" <= 10)); then
image="
ascii
"
get_ascii
# Error messages
[[ ! -f "
$img
" ]] && err "
Image:
\$
img, isn
't a file, falling back to ascii mode."
(("${#term_size}" <= 5)) && err "Image: Your terminal doesn'
t support
\\\0
33[14t, falling back to ascii mode.
"
return
else
# If the terminal size was found correctly
if
[[
"
$term_width
"
]]
&&
((
term_width
>
0
))
;
then
clear
zws
=
" "
fi
}
get_image_size
()
{
# This functions determines the size to make
# the thumbnail image.
# Get terminal lines and columns
term_blocks
=
"
$(
stty
size
)
"
...
...
@@ -2019,7 +2096,6 @@ get_image() {
font_width
=
"
$((
term_width
/
columns
))
"
font_height
=
"
$((
term_height
/
lines
))
"
# Image size is half of the terminal
case
"
$image_size
"
in
"auto"
)
image_size
=
"
$((
columns
*
font_width
/
2
))
"
...
...
@@ -2039,7 +2115,7 @@ get_image() {
"none"
)
# Get image size so that we can do a better crop
size="
$(
identify
-format
"%w %h"
"
$im
g
"
)
"
size
=
"
$(
identify
-format
"%w %h"
"
$im
age
"
)
"
width
=
"
${
size
%% *
}
"
height
=
"
${
size
##*
}
"
crop_mode
=
"none"
...
...
@@ -2048,28 +2124,32 @@ get_image() {
*
)
image_size
=
"
${
image_size
/px
}
"
;;
esac
# Fallback if width / height are empty.
width
=
"
${
width
:-
$image_size
}
"
height
=
"
${
height
:-
$image_size
}
"
# Padding is half the terminal width + gap
padding="
\0
33[
$((
width
/
font_width
+
gap
+
xoffset/font_width
))
C
"
text_padding
=
"
$((
width
/
font_width
+
gap
+
xoffset/font_width
))
"
}
# Make the directory if it doesn't exist
mkdir -p "
$thumbnail_dir
"
make_thumbnail
()
{
# Name the thumbnail using variables so we can
# use it later.
image_name
=
"
$crop_mode
-
$crop_offset
-
$width
-
$height
"
# Check to see if the image has a file extension,
if it doesn't
# then add one.
case "
${
im
g
##*/
}
" in
*"
.
"*) im
gname="
$crop_mode
-
$crop_offset
-
$width
-
$height
-
${
img
##*/
}
" ;;
*) im
gname="
$crop_mode
-
$crop_offset
-
$width
-
$height
-
${
img
##*/
}
.jpg
" ;;
# Check to see if the image has a file extension,
#
if it doesn't
then add one.
case
"
${
im
age
##*/
}
"
in
*
"."
*
)
im
age_name
=
"
${
image_name
}
-
${
image
##*/
}
"
;;
*
)
im
age_name
=
"
${
image_name
}
-
${
image
##*/
}
.jpg"
;;
esac
# Check to see if the thumbnail exists before we do any cropping.
if [[ ! -f "
$thumbnail_dir
/
$imgname
" ]]; then
if
[[
!
-f
"
$thumbnail_dir
/
$image_name
"
]]
;
then
# Create the thumbnail dir if it doesn't exist.
mkdir
-p
"
$thumbnail_dir
"
# Get image size so that we can do a better crop
if
[[
-z
"
$size
"
]]
;
then
size="
$(
identify
-format
"%w %h"
"
$im
g
"
)
"
size
=
"
$(
identify
-format
"%w %h"
"
$im
age
"
)
"
og_width
=
"
${
size
%% *
}
"
og_height
=
"
${
size
##*
}
"
...
...
@@ -2080,101 +2160,79 @@ get_image() {
fi
case
"
$crop_mode
"
in
fit
)
c="
$(
convert
"
$im
g
"
\
"fit"
)
c
=
"
$(
convert
"
$im
age
"
\
-colorspace
srgb
\
-format
"%[pixel:p{0,0}]"
info:
)
"
convert
\
"
$im
g
"
\
"
$im
age
"
\
-trim
+repage
\
-gravity
south
\
-background
"
$c
"
\
-extent
"
$size
"
x
"
$size
"
\
-scale
"
$width
"
x
"
$height
"
\
"
$thumbnail_dir
/
$im
g
name
"
"
$thumbnail_dir
/
$im
age_
name
"
;;
fill
)
"fill"
)
convert
\
"
$im
g
"
\
"
$im
age
"
\
-trim
+repage
\
-scale
"
$width
"
x
"
$height
"
^
\
-extent
"
$width
"
x
"
$height
"
\
"
$thumbnail_dir
/
$im
g
name
"
"
$thumbnail_dir
/
$im
age_
name
"
;;
none) cp "
$img
" "
$thumbnail_dir
/
$img
name
" ;;
"none"
)
cp
"
$image
"
"
$thumbnail_dir
/
$image_
name
"
;;
*
)
convert
\
"
$im
g
"
\
"
$im
age
"
\
-gravity
"
$crop_offset
"
\
-crop
"
$size
"
x
"
$size
"
+0+0
\
-quality
95
\
-scale
"
$width
"
x
"
$height
"
\
"
$thumbnail_dir
/
$im
g
name
"
"
$thumbnail_dir
/
$im
age_
name
"
;;
esac
fi
# The final image
im
g="
$thumbnail_dir
/
$img
name
"
im
age
=
"
$thumbnail_dir
/
$image_
name
"
}
get_w3m_img_path() {
if [[ -x "
$w3m_img_path
" ]]; then
return
elif [[ -x "
/usr/lib/w3m/w3mimgdisplay
" ]]; then
w3m_img_path="
/usr/lib/w3m/w3mimgdisplay
"
elif [[ -x "
/usr/libexec/w3m/w3mimgdisplay
" ]]; then
w3m_img_path="
/usr/libexec/w3m/w3mimgdisplay
"
elif [[ -x "
/usr/lib64/w3m/w3mimgdisplay
" ]]; then
w3m_img_path="
/usr/lib64/w3m/w3mimgdisplay
"
display_image
()
{
case
"
$image_program
"
in
"w3m"
)
# Add a tiny delay to fix issues with images not
# appearing in specific terminal emulators.
sleep
0.05
printf
"%b
\n
"
"0;1;
$xoffset
;
$yoffset
;
$width
;
$height
;;;;;
$image
\n
4;
\n
3;"
|
\
"
$w3m_img_path
"
-bg
"
$background_color
"
>
/dev/null & 2>&1
||
to_off
"Images: w3m-img failed to display the image."
;;
elif [[ -x "
/usr/libexec64/w3m/w3mimgdisplay
" ]]; then
w3m_img_path="
/usr/libexec64/w3m/w3mimgdisplay
"
"iterm2"
)
printf
"%b
\a\n
"
"
\0
33]1337;File=width=
${
width
}
px;height=
${
height
}
px;inline=1:
$(
base64
<
"
$image
"
)
"
;;
else
image="
ascii
"
err "
Image: w3m-img wasn
't found on your system, falling back to ascii mode."
fi
"tycat"
)
tycat
"
$image
"
;;
esac
}
get_image_backend() {
if [[ -n "$ITERM_PROFILE" ]]; then
image_backend="iterm2"
elif [[ "$(tycat 2>/dev/null)" ]]; then
image_backend="tycat"
else
image_backend="w3m"
fi
to_ascii
()
{
# This function makes neofetch fallback to ascii mode.
image_backend
=
"ascii"
get_ascii 2>/dev/null
err
"
$1
"
}
display_image() {
if [[ "$image" != "ascii" ]]; then
case "$image_backend" in
"w3m")
# Add a tiny delay to fix issues with images not
# appearing in specific terminal emulators.
sleep 0.05
printf "%b\n" "0;1;$xoffset;$yoffset;$width;$height;;;;;$img\n4;\n3;" |\
"$w3m_img_path" -bg "$background_color" >/dev/null & 2>&1 || padding="\033[0C"
;;
"iterm2")
printf "%b\a\n" "\033]1337;File=width=${width}px;height=${height}px;inline=1:$(base64 < "$img")"
;;
"tycat")
tycat "$img"
;;
esac
fi
to_off
()
{
# This function makes neofetch fallback to off mode.
text_padding
=
"0"
image_backend
=
"off"
err
"
$1
"
}
# SCREENSHOT
...
...
@@ -2239,7 +2297,7 @@ info() {
# If the output is empty, don't print anything.
[[ -z "
${
output
//
}
" ]] &&
\
err
"Info: Couldn't detect
$subtitle
"
&&
return
err "
Info
:
Couldn
't detect $subtitle
.
" && return
case "$1" in
title)
...
...
@@ -2261,7 +2319,7 @@ info() {
[[ -z "$2" ]] && string="${string/*: }"
# Print the string
printf
"%b
\n
"
"
${
padding
}
${
zws
}${
string
}${
reset
}
"
printf "%b\n" "
\033[${text_padding}C
${zws}${string}${reset} "
# Calculate info height
info_height="$((info_height+=1))"
...
...
@@ -2269,10 +2327,8 @@ info() {
# Fix rendering issues with w3m and lines that
# wrap to the next line by adding a max line
# length.
if
[[
"
$image
"
!=
"off"
&&
"
$image
"
!=
"ascii"
&&
"
$1
"
!=
"cols"
]]
;
then
padding_num
=
"
${
padding
/\\033\[
}
"
output
=
"
$(
printf
"%.
$((
columns
-
${
padding_num
/C
}
-
gap
-
${#
subtitle
}))
s"
"
$output
"
)
"
fi
[[ "$image_backend" == "image" ]] && \
string="$(printf "%.$((columns - text_padding - gap))s" "$string")"
}
prin() {
...
...
@@ -2289,7 +2345,7 @@ prin() {
string=
"
$(
trim
"
$string
"
)
"
# Print the info
printf
"%b
\n
"
"
${
padding
}
${
zws
}${
string
}${
reset
}
"
printf
"%b
\n
"
"
\0
33[
${
text_padding
}
C
${
zws
}${
string
}${
reset
}
"
# Calculate info height
info_height=
"
$((
info_height+
=
1
))
"
...
...
@@ -2297,10 +2353,8 @@ prin() {
# Fix rendering issues with w3m and lines that
# wrap to the next line by adding a max line
# length.
if
[[
"
$image
"
!=
"off"
&&
"
$image
"
!=
"ascii"
]]
;
then
padding_num
=
"
${
padding
/\\033\[
}
"
string
=
"
$(
printf
"%.
$((
columns
-
${
padding_num
/C
}
-
gap
))
s"
"
$string
"
)
"
fi
[[
"
$image_backend
"
==
"image"
]] && \
string=
"
$(
printf
"%.
$((
columns
-
text_padding
-
gap
))
s"
"
$string
"
)
"
# Tell info() that prin() was used.
prin=1
...
...
@@ -2593,13 +2647,6 @@ err() {
"
}
check_old_flags
()
{
[[
-n
"
$osx_buildversion
"
]]
&&
err
"Config:
\$
osx_buildversion is deprecated, use
\$
distro_shorthand instead."
[[
-n
"
$osx_codename
"
]]
&&
err
"Config:
\$
osx_codename is deprecated, use
\$
distro_shorthand instead."
[[
-n
"
$progress_char
"
]]
&&
err
"Config:
\$
progress_char is deprecated, use
\$
progress_char_elapsed and
\$
progress_char_total instead."
[[
"
$cpu_cores
"
==
"on"
]]
&&
err
"Config:
\$
cpu_cores='on' is deprecated, use
\$
cpu_cores='logical|physical|off' instead."
}
get_script_dir() {
[[ "
$script_dir
" ]] && return
...
...
@@ -2635,7 +2682,7 @@ get_default_config() {
fi
if source "
$default_config
"; then
err
"Config: Sourced default config (
$default_config
)"
err "
Config: Sourced default config
.
(
$default_config
)
"
else
err "
Config
:
Default config not found, continuing...
"
fi
...
...
@@ -2645,12 +2692,12 @@ get_user_config() {
# Check
$config_file
if [[ -f "
$config_file
" ]]; then
source "
$config_file
"
err
"Config: Sourced user config (
$config_file
)"
err "
Config
:
Sourced user config
.
(
$config_file
)
"
return
elif [[ "
$config_file
" == "
travis
" ]]; then
source "
$travis_config
"
err
"Config: Sourced user config (
$travis_config
)"
err "
Config
:
Sourced user config
.
(
$travis_config
)
"
return
fi
mkdir -p "
$XDG_CONFIG_HOME
/neofetch/
"
...
...
@@ -2676,7 +2723,7 @@ get_user_config() {
fi
source "
$config_file
"
err
"Config: Sourced user config (
$config_file
)"
err "
Config
:
Sourced user config
.
(
$config_file
)
"
}
bar() {
...
...
@@ -2746,7 +2793,7 @@ get_term_padding() {
dynamic_prompt() {
# Calculate image height in terminal cells.
if
[[
"
$image
"
!=
"ascii"
]]
;
then
if [[ "
$image
_backend
" != "
ascii
" ]]; then
get_term_padding 2>/dev/null
lines="
$((
(
height
+
(
${
border
:-
0
}
*
2
)
+
${
yoffset
:-
0
}
)
/
font_height
))
"
fi
...
...
@@ -2786,6 +2833,14 @@ old_functions() {
fi
}
old_flags() {
[[ -n "
$osx_buildversion
" ]] && err "
Config:
\$
osx_buildversion is deprecated, use
\$
distro_shorthand instead.
"
[[ -n "
$osx_codename
" ]] && err "
Config:
\$
osx_codename is deprecated, use
\$
distro_shorthand instead.
"
[[ -n "
$progress_char
" ]] && err "
Config:
\$
progress_char is deprecated, use
\$
progress_char_elapsed and
\$
progress_char_total instead.
"
[[ "
$cpu_cores
" == "
on
" ]] && err "
Config:
\$
cpu_cores
=
'on'
is deprecated, use
\$
cpu_cores
=
'logical|physical|off'
instead.
"
[[ -n "
$image
" ]] && { err "
Config:
\$
image is deprecated, use
\$
image_source instead.
"; image_source="
$image
"; }
}
cache_uname() {
# Cache the output of uname so we don't
# have to spawn it multiple times.
...
...
@@ -3011,8 +3066,8 @@ get_args() {
# Image
--image
)
image
=
"
$2
"
case
"
$2
"
in
"-"
*
|
""
)
image
=
"ascii"
;;
esac
image
_source
=
"
$2
"
case
"
$2
"
in
"-"
*
|
""
)
image
_backend
=
"ascii"
;;
esac
;;
--image_size
|
--size
)
image_size
=
"
$2
"
;;
...
...
@@ -3031,7 +3086,7 @@ get_args() {
# Ascii
--ascii
)
image
=
"ascii"
image
_backend
=
"ascii"
ascii
=
"
$2
"
case
"
$2
"
in
"-"
*
|
""
)
ascii
=
"distro"
;;
esac
;;
...
...
@@ -3048,7 +3103,7 @@ get_args() {
;;
--ascii_distro
)
image
=
"ascii"
image
_backend
=
"ascii"
ascii_distro
=
"
$2
"
case
"
$2
"
in
"-"
*
|
""
)
ascii_distro
=
"
$distro
"
;;
esac
;;
...
...
@@ -3056,7 +3111,7 @@ get_args() {
--ascii_logo_size
)
ascii_logo_size
=
"
$2
"
;;
--ascii_bold
)
ascii_bold
=
"
$2
"
;;
--logo
|
-L
)
image
=
"ascii"
image
_backend
=
"ascii"
print_info
()
{
info line_break
;
}
;;
...
...
@@ -3094,7 +3149,7 @@ main() {
cache_uname
get_os
get_default_config 2>/dev/null
check_
old_flags
old_flags
get_args
"
$@
"
get_distro
bold
...
...
@@ -3109,21 +3164,9 @@ main() {
# Hide the cursor and disable line wrap
printf
"
\0
33[?25l
\0
33[?7l"
# Display the image
if
[[
"
$image
"
!=
"off"
]]
;
then
get_image_backend
# Find w3mimgdisplay
[[
"
$image_backend
"
==
"w3m"
]]
&&
\
[[
"
$image
"
!=
"ascii"
]]
&&
\
get_w3m_img_path
# Get the image src
get_image
# Display the image if enabled
display_image
get_image_backend
if
[[
"
$image_backend
"
!=
"off"
]]
;
then
# Set cursor position next to ascii art
printf
"%b"
"
\0
33[
$((${
lines
:-
0
}
-
${
prompt_loc
:-
0
}))
A"
...
...
@@ -3136,12 +3179,12 @@ main() {
print_info 2>/dev/null
# Prompt calculation
if
[[
"
$image
"
!=
"off"
]]
;
then
if
[[
"
$image
_backend
"
!=
"off"
]]
;
then
dynamic_prompt
# w3m-img: Draw the image a second time to fix
# rendering issues in specific terminal emulators.
[[
"
$image_backend
"
==
"w3m"
]]
&&
display_image
[[
"
$image_backend
"
==
"
image"
&&
"
$image_program
"
==
"
w3m"
]]
&&
display_image
fi
# Re-enable line wrap
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment