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
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
238 additions
and
195 deletions
+238
-195
config
config/config
+2
-2
neofetch
neofetch
+236
-193
No files found.
config/config
View file @
89c43b1f
...
@@ -287,8 +287,8 @@ disk_display="off"
...
@@ -287,8 +287,8 @@ disk_display="off"
# Image Source
# Image Source
# --image wall
, ascii
, /path/to/img, /path/to/dir/, off
# --image wall
paper
, /path/to/img, /path/to/dir/, off
image
=
"wall
"
image
_source
=
"wallpaper
"
# Thumbnail directory
# Thumbnail directory
thumbnail_dir
=
"
$HOME
/.cache/thumbnails/neofetch"
thumbnail_dir
=
"
$HOME
/.cache/thumbnails/neofetch"
...
...
neofetch
View file @
89c43b1f
...
@@ -1464,7 +1464,7 @@ get_term_font() {
...
@@ -1464,7 +1464,7 @@ get_term_font() {
case "
$term
" in
case "
$term
" in
"
urxvt
" | "
urxvtd
" | "
xterm
")
"
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="
${
term_font
/*font
:
}
"
term_font="
$(
trim
"
$term_font
"
)
"
term_font="
$(
trim
"
$term_font
"
)
"
...
@@ -1791,69 +1791,81 @@ get_cols() {
...
@@ -1791,69 +1791,81 @@ get_cols() {
# Add newlines to the string.
# Add newlines to the string.
cols="
${
cols
%%
'nl'
}
"
cols="
${
cols
%%
'nl'
}
"
cols="
${
cols
//nl/\\n
${
padding
}
${
zws
}}
"
cols="
${
cols
//nl/\\n
\\033[
${
text_padding
}
C
${
zws
}}
"
fi
fi
}
}
# IMAGES
# IMAGES
get_wallpaper() {
get_image_backend() {
case "
$os
" in
# This function determines which image backend to use
"
Linux
" | "
BSD
")
# by checking for programs and etc.
if type -p feh >/dev/null && [[ -f "
$HOME
/.fehbg
" ]]; then
img="
$(
awk
-F
\'
'/feh/ {printf $2}'
"
$HOME
/.fehbg"
)
"
elif type -p nitrogen >/dev/null; then
# Automatically find w3m-img
img="
$(
awk
-F
'='
'/file/ {printf $2;exit;}'
"
$XDG_CONFIG_HOME
/nitrogen/bg-saved.cfg"
)
"
get_w3m_img_path
elif type -p gsettings >/dev/null; then
# Fallback to ascii mode if imagemagick isn't installed.
# Get DE if user has disabled the function.
type -p convert >/dev/null 2>&1 || image_backend="
ascii
"
[[ -z "
$de
" ]] && get_de
case "
$de
" in
case "
${
image_backend
:
=image
}
" in
"
MATE
"*) img="
$(
gsettings get org.mate.background picture-filename
)
" ;;
"
image
")
*) img="
$(
gsettings get org.gnome.desktop.background picture-uri
)
" ;;
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
esac
# Strip quotes etc from the path
.
# Fallback to ascii mode if image isn't a file
.
img="
${
img
/
'file://'
}
"
if [[ ! -f "
$image
" ]]; then
img="
${
img
//\
'}
"
to_ascii "
Image
:
'$image'
doesn
't exist, falling back to ascii mode.
"
img="${img//\%20/ }"
return
fi
fi
;;
"Mac OS X")
get_image_program
img="$(osascript -e '
tell
application
"System Events"
to picture of current desktop
')"
get_term_size
;;
"Windows")
# Fallback to ascii mode if terminal size wasn'
t
found.
case "$distro" in
if [[ -z
"
$term_width
"
]] && ((term_width == 0)); then
"Windows XP")
to_ascii
"Image: Failed to find terminal window size"
img="/cygdrive/c/Documents and Settings/${USER}"
return
img+="/Local Settings/Application Data/Microsoft"
fi
img+="/Wallpaper1.bmp"
;;
"Windows"*)
get_image_size
img="$APPDATA/Microsoft/Windows/Themes"
make_thumbnail
img+="/TranscodedWallpaper.jpg"
;;
# If the backend is still set to
'image'
after
esac
# make_thumbnail(), then display the image.
[[
"
$image_backend
"
==
"image"
]] && display_image
;;
;;
"ascii"
) get_ascii 2>/dev/null ;;
esac
esac
}
# If img is an xml file don'
t
use it.
get_image_program() {
[[
"
${
img
/*\./
}
"
==
"xml"
]] && img=
""
if [[ -n "
$ITERM_PROFILE
" ]]; then
image_program="
iterm2
"
elif [[ "
$(
tycat 2>/dev/null
)
" ]]; then
image_program="
tycat
"
# Error msg
else
[[ -z
"
$img
"
]] && err
"Image: Wallpaper detection failed, falling back to ascii mode."
image_program="
w3m
"
fi
}
}
get_ascii() {
get_ascii() {
if [[ ! -f "
$ascii
" || "
$ascii
" == "
distro
" ]]; then
if [[ ! -f "
$ascii
" || "
$ascii
" == "
distro
" ]]; then
# Error message
# Error message
[[
"
$ascii
"
!=
"distro"
]] && \
[[ "
$ascii
" != "
distro
" ]] &&
[[ ! -f "
$ascii
" ]] &&
\
[[ ! -f
"
$ascii
"
]] && err
"Ascii: Ascii file not found, using distro ascii
"
err "
Ascii: Ascii file not found, using distro ascii.
"
# Lowercase the distro name
# Lowercase the distro name
if (("
$version
" <= 3)); then
if (("
$version
" <= 3)); then
...
@@ -1880,14 +1892,13 @@ get_ascii() {
...
@@ -1880,14 +1892,13 @@ get_ascii() {
get_script_dir 2>/dev/null
get_script_dir 2>/dev/null
# If the ascii file doesn't exist fallback to text mode.
# If the ascii file doesn't exist fallback to text mode.
if [[ ! -f "$script_dir/ascii/distro/${ascii/ *}" ]]; then
if [[ -f "
$script_dir
/ascii/distro/
${
ascii
/ *
}
" ]]; then
padding="\033[0C"
ascii="
$script_dir
/ascii/distro/
${
ascii
/ *
}
"
image="off"
err "Ascii: Ascii file not found, falling back to text mode."
else
to_off "
Ascii: Ascii file not found, falling back to text mode.
"
return
return
fi
fi
ascii="$script_dir/ascii/distro/${ascii/ *}"
fi
fi
fi
fi
...
@@ -1916,33 +1927,99 @@ get_ascii() {
...
@@ -1916,33 +1927,99 @@ get_ascii() {
# Overwrite padding if ascii_length_force is set.
# Overwrite padding if ascii_length_force is set.
[[ "
$ascii_length_force
" ]] && ascii_length="
$ascii_length_force
"
[[ "
$ascii_length_force
" ]] && ascii_length="
$ascii_length_force
"
padding="\033[$((ascii_length + gap))C
"
text_padding="
$((
ascii_length
+
gap
))
"
printf "
%b
" "
$print
"
printf "
%b
" "
$print
"
export LC_ALL=C
export LC_ALL=C
}
}
get_image() {
get_w3m_img_path() {
# Fallback to ascii mode if imagemagick isn'
t
installed.
if [[ -x "
$w3m_img_path
" ]]; then
type -p convert >/dev/null 2>&1 || image=
"ascii"
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
"
elif [[ -x "
/usr/libexec64/w3m/w3mimgdisplay
" ]]; then
w3m_img_path="
/usr/libexec64/w3m/w3mimgdisplay
"
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
else
img="
$image
"
image_backend="
ascii
"
err "
Image: w3m-img wasn
't found on your system, falling back to ascii mode."
fi
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
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
if
[[
-n
"
$TMUX
"
]]
;
then
printf
"%b"
"
\0
33Ptmux;
\0
33
\0
33[14t
\0
33
\0
33[c
\0
33
\\
"
printf
"%b"
"
\0
33Ptmux;
\0
33
\0
33[14t
\0
33
\0
33[c
\0
33
\\
"
read_flags
=
"-d c"
read_flags
=
"-d c"
elif [[ "
$image_
backend
" == "
tycat
" ]]; then
elif
[[
"
$image_
program
"
==
"tycat"
]]
;
then
printf
"%b"
"
\0
33}qs
\0
00"
printf
"%b"
"
\0
33}qs
\0
00"
else
else
...
@@ -1950,11 +2027,13 @@ get_image() {
...
@@ -1950,11 +2027,13 @@ get_image() {
read_flags
=
"-d c"
read_flags
=
"-d c"
fi
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
builtin read
-s
-t
1
${
read_flags
}
-r
term_size
# Split the string
# Split the string
into height/width.
if [[ "
$image_
backend
" == "
tycat
" ]]; then
if
[[
"
$image_
program
"
==
"tycat"
]]
;
then
term_size
=(
${
term_size
//;/
}
)
term_size
=(
${
term_size
//;/
}
)
term_width
=
"
$((
term_size[2]
*
term_size[0]
))
"
term_width
=
"
$((
term_size[2]
*
term_size[0]
))
"
term_height
=
"
$((
term_size[3]
*
term_size[1]
))
"
term_height
=
"
$((
term_size[3]
*
term_size[1]
))
"
...
@@ -1969,46 +2048,44 @@ get_image() {
...
@@ -1969,46 +2048,44 @@ get_image() {
fi
fi
# Get terminal width and height if \033[14t is unsupported.
# Get terminal width and height if \033[14t is unsupported.
if (("
${#
term_size
}
" <= 5)) && [[ "
$image_backend
" != "
tycat
" ]]; then
if
((
"
${#
term_size
}
"
<
=
5
))
&&
[[
"
$image_program
"
==
"w3m"
]]
;
then
if type -p xdotool >/dev/null 2>&1 &&
\
if
type
-p
xdotool
>
/dev/null 2>&1
;
then
[[ "
$image_backend
" != "
iterm2
" ]]; then
current_window
=
"
$(
xdotool getactivewindow
)
"
current_window
=
"
$(
xdotool getactivewindow
)
"
source
<
(
xdotool getwindowgeometry
--shell
"
$current_window
"
)
source
<
(
xdotool getwindowgeometry
--shell
"
$current_window
"
)
term_height
=
"
$HEIGHT
"
term_height
=
"
$HEIGHT
"
term_width
=
"
$WIDTH
"
term_width
=
"
$WIDTH
"
elif type -p xwininfo >/dev/null 2>&1 &&
\
elif
type
-p
xwininfo
>
/dev/null 2>&1
;
then
type -p xdpyinfo >/dev/null 2>&1 ||
\
# Get the focused window's ID.
type -p xprop >/dev/null 2>&1 &&
\
[[ "
$image_backend
" != "
iterm2
" ]]; then
if
type
-p
xdpyinfo
>
/dev/null 2>&1
;
then
if
type
-p
xdpyinfo
>
/dev/null 2>&1
;
then
current_window
=
"
$(
xdpyinfo |
grep
-F
"focus"
|
grep
-E
-o
"0x[0-9a-f]+"
)
"
current_window
=
"
$(
xdpyinfo |
grep
-F
"focus"
|
grep
-E
-o
"0x[0-9a-f]+"
)
"
elif
type
-p
xprop
>
/dev/null 2>&1
;
then
elif
type
-p
xprop
>
/dev/null 2>&1
;
then
current_window
=
"
$(
xprop
-root
|
awk
'/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}'
)
"
current_window
=
"
$(
xprop
-root
|
awk
'/_NET_ACTIVE_WINDOW\(WINDOW\)/{print $NF}'
)
"
fi
fi
# 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_size
=
"
$(
xwininfo
-id
"
$current_window
"
|
awk
-F
': '
'/Width|Height/ {printf $2 " "}'
)
"
term_width
=
"
${
term_size
/ *
}
"
term_width
=
"
${
term_size
/ *
}
"
term_height
=
"
${
term_size
/
${
term_width
}}
"
term_height
=
"
${
term_size
/
${
term_width
}}
"
else
term_width
=
"0"
fi
else
term_width
=
"0"
fi
fi
fi
fi
# If
$img
isn't a file fallback to ascii mode.
# If the terminal size was found correctly
if [[ ! -f "
$img
" || -z "
$term_width
" ]] || (("
$term_width
" <= 10)); then
if
[[
"
$term_width
"
]]
&&
((
term_width
>
0
))
;
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
clear
clear
zws
=
" "
zws
=
" "
fi
fi
}
get_image_size
()
{
# This functions determines the size to make
# the thumbnail image.
# Get terminal lines and columns
# Get terminal lines and columns
term_blocks
=
"
$(
stty
size
)
"
term_blocks
=
"
$(
stty
size
)
"
...
@@ -2019,7 +2096,6 @@ get_image() {
...
@@ -2019,7 +2096,6 @@ get_image() {
font_width
=
"
$((
term_width
/
columns
))
"
font_width
=
"
$((
term_width
/
columns
))
"
font_height
=
"
$((
term_height
/
lines
))
"
font_height
=
"
$((
term_height
/
lines
))
"
# Image size is half of the terminal
case
"
$image_size
"
in
case
"
$image_size
"
in
"auto"
)
"auto"
)
image_size
=
"
$((
columns
*
font_width
/
2
))
"
image_size
=
"
$((
columns
*
font_width
/
2
))
"
...
@@ -2039,7 +2115,7 @@ get_image() {
...
@@ -2039,7 +2115,7 @@ get_image() {
"none"
)
"none"
)
# Get image size so that we can do a better crop
# 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
%% *
}
"
width
=
"
${
size
%% *
}
"
height
=
"
${
size
##*
}
"
height
=
"
${
size
##*
}
"
crop_mode
=
"none"
crop_mode
=
"none"
...
@@ -2048,28 +2124,32 @@ get_image() {
...
@@ -2048,28 +2124,32 @@ get_image() {
*
)
image_size
=
"
${
image_size
/px
}
"
;;
*
)
image_size
=
"
${
image_size
/px
}
"
;;
esac
esac
# Fallback if width / height are empty.
width
=
"
${
width
:-
$image_size
}
"
width
=
"
${
width
:-
$image_size
}
"
height
=
"
${
height
:-
$image_size
}
"
height
=
"
${
height
:-
$image_size
}
"
# Padding is half the terminal width + gap
text_padding
=
"
$((
width
/
font_width
+
gap
+
xoffset/font_width
))
"
padding="
\0
33[
$((
width
/
font_width
+
gap
+
xoffset/font_width
))
C
"
}
# Make the directory if it doesn't exist
make_thumbnail
()
{
mkdir -p "
$thumbnail_dir
"
# 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
# Check to see if the image has a file extension,
# then add one.
#
if it doesn't
then add one.
case "
${
im
g
##*/
}
" in
case
"
${
im
age
##*/
}
"
in
*"
.
"*) im
gname="
$crop_mode
-
$crop_offset
-
$width
-
$height
-
${
img
##*/
}
" ;;
*
"."
*
)
im
age_name
=
"
${
image_name
}
-
${
image
##*/
}
"
;;
*) im
gname="
$crop_mode
-
$crop_offset
-
$width
-
$height
-
${
img
##*/
}
.jpg
" ;;
*
)
im
age_name
=
"
${
image_name
}
-
${
image
##*/
}
.jpg"
;;
esac
esac
# Check to see if the thumbnail exists before we do any cropping.
# 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
# Get image size so that we can do a better crop
if
[[
-z
"
$size
"
]]
;
then
if
[[
-z
"
$size
"
]]
;
then
size="
$(
identify
-format
"%w %h"
"
$im
g
"
)
"
size
=
"
$(
identify
-format
"%w %h"
"
$im
age
"
)
"
og_width
=
"
${
size
%% *
}
"
og_width
=
"
${
size
%% *
}
"
og_height
=
"
${
size
##*
}
"
og_height
=
"
${
size
##*
}
"
...
@@ -2080,101 +2160,79 @@ get_image() {
...
@@ -2080,101 +2160,79 @@ get_image() {
fi
fi
case
"
$crop_mode
"
in
case
"
$crop_mode
"
in
fit
)
"fit"
)
c="
$(
convert
"
$im
g
"
\
c
=
"
$(
convert
"
$im
age
"
\
-colorspace
srgb
\
-colorspace
srgb
\
-format
"%[pixel:p{0,0}]"
info:
)
"
-format
"%[pixel:p{0,0}]"
info:
)
"
convert
\
convert
\
"
$im
g
"
\
"
$im
age
"
\
-trim
+repage
\
-trim
+repage
\
-gravity
south
\
-gravity
south
\
-background
"
$c
"
\
-background
"
$c
"
\
-extent
"
$size
"
x
"
$size
"
\
-extent
"
$size
"
x
"
$size
"
\
-scale
"
$width
"
x
"
$height
"
\
-scale
"
$width
"
x
"
$height
"
\
"
$thumbnail_dir
/
$im
g
name
"
"
$thumbnail_dir
/
$im
age_
name
"
;;
;;
fill
)
"fill"
)
convert
\
convert
\
"
$im
g
"
\
"
$im
age
"
\
-trim
+repage
\
-trim
+repage
\
-scale
"
$width
"
x
"
$height
"
^
\
-scale
"
$width
"
x
"
$height
"
^
\
-extent
"
$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
\
convert
\
"
$im
g
"
\
"
$im
age
"
\
-gravity
"
$crop_offset
"
\
-gravity
"
$crop_offset
"
\
-crop
"
$size
"
x
"
$size
"
+0+0
\
-crop
"
$size
"
x
"
$size
"
+0+0
\
-quality
95
\
-quality
95
\
-scale
"
$width
"
x
"
$height
"
\
-scale
"
$width
"
x
"
$height
"
\
"
$thumbnail_dir
/
$im
g
name
"
"
$thumbnail_dir
/
$im
age_
name
"
;;
;;
esac
esac
fi
fi
# The final image
# The final image
img="
$thumbnail_dir
/
$imgname
"
image
=
"
$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
"
elif [[ -x "
/usr/libexec64/w3m/w3mimgdisplay
" ]]; then
w3m_img_path="
/usr/libexec64/w3m/w3mimgdisplay
"
else
image="
ascii
"
err "
Image: w3m-img wasn
't found on your system, falling back to ascii mode."
fi
}
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
}
}
display_image
()
{
display_image
()
{
if [[ "$image" != "ascii" ]]; then
case
"
$image_program
"
in
case "$image_backend" in
"w3m"
)
"w3m"
)
# Add a tiny delay to fix issues with images not
# Add a tiny delay to fix issues with images not
# appearing in specific terminal emulators.
# appearing in specific terminal emulators.
sleep
0.05
sleep
0.05
printf "%b\n" "0;1;$xoffset;$yoffset;$width;$height;;;;;$img
\n4;\n3;" |\
printf
"%b
\n
"
"0;1;
$xoffset
;
$yoffset
;
$width
;
$height
;;;;;
$image
\n
4;
\n
3;"
|
\
"$w3m_img_path" -bg "$background_color" >/dev/null & 2>&1 || padding="\033[0C
"
"
$w3m_img_path
"
-bg
"
$background_color
"
>
/dev/null & 2>&1
||
to_off
"Images: w3m-img failed to display the image.
"
;;
;;
"iterm2"
)
"iterm2"
)
printf "%b\a\n" "\033]1337;File=width=${width}px;height=${height}px;inline=1:$(base64 < "$img
")"
printf
"%b
\a\n
"
"
\0
33]1337;File=width=
${
width
}
px;height=
${
height
}
px;inline=1:
$(
base64
<
"
$image
"
)
"
;;
;;
"tycat"
)
"tycat"
)
tycat "$img
"
tycat
"
$image
"
;;
;;
esac
esac
fi
}
to_ascii
()
{
# This function makes neofetch fallback to ascii mode.
image_backend
=
"ascii"
get_ascii 2>/dev/null
err
"
$1
"
}
to_off
()
{
# This function makes neofetch fallback to off mode.
text_padding
=
"0"
image_backend
=
"off"
err
"
$1
"
}
}
# SCREENSHOT
# SCREENSHOT
...
@@ -2239,7 +2297,7 @@ info() {
...
@@ -2239,7 +2297,7 @@ info() {
# If the output is empty, don't print anything.
# If the output is empty, don't print anything.
[[ -z "
${
output
//
}
" ]] &&
\
[[ -z "
${
output
//
}
" ]] &&
\
err
"Info: Couldn't detect
$subtitle
"
&&
return
err "
Info
:
Couldn
't detect $subtitle
.
" && return
case "$1" in
case "$1" in
title)
title)
...
@@ -2261,7 +2319,7 @@ info() {
...
@@ -2261,7 +2319,7 @@ info() {
[[ -z "$2" ]] && string="${string/*: }"
[[ -z "$2" ]] && string="${string/*: }"
# Print the string
# Print the string
printf
"%b
\n
"
"
${
padding
}
${
zws
}${
string
}${
reset
}
"
printf "%b\n" "
\033[${text_padding}C
${zws}${string}${reset} "
# Calculate info height
# Calculate info height
info_height="$((info_height+=1))"
info_height="$((info_height+=1))"
...
@@ -2269,10 +2327,8 @@ info() {
...
@@ -2269,10 +2327,8 @@ info() {
# Fix rendering issues with w3m and lines that
# Fix rendering issues with w3m and lines that
# wrap to the next line by adding a max line
# wrap to the next line by adding a max line
# length.
# length.
if
[[
"
$image
"
!=
"off"
&&
"
$image
"
!=
"ascii"
&&
"
$1
"
!=
"cols"
]]
;
then
[[ "$image_backend" == "image" ]] && \
padding_num
=
"
${
padding
/\\033\[
}
"
string="$(printf "%.$((columns - text_padding - gap))s" "$string")"
output
=
"
$(
printf
"%.
$((
columns
-
${
padding_num
/C
}
-
gap
-
${#
subtitle
}))
s"
"
$output
"
)
"
fi
}
}
prin() {
prin() {
...
@@ -2289,7 +2345,7 @@ prin() {
...
@@ -2289,7 +2345,7 @@ prin() {
string=
"
$(
trim
"
$string
"
)
"
string=
"
$(
trim
"
$string
"
)
"
# Print the info
# Print the info
printf
"%b
\n
"
"
${
padding
}
${
zws
}${
string
}${
reset
}
"
printf
"%b
\n
"
"
\0
33[
${
text_padding
}
C
${
zws
}${
string
}${
reset
}
"
# Calculate info height
# Calculate info height
info_height=
"
$((
info_height+
=
1
))
"
info_height=
"
$((
info_height+
=
1
))
"
...
@@ -2297,10 +2353,8 @@ prin() {
...
@@ -2297,10 +2353,8 @@ prin() {
# Fix rendering issues with w3m and lines that
# Fix rendering issues with w3m and lines that
# wrap to the next line by adding a max line
# wrap to the next line by adding a max line
# length.
# length.
if
[[
"
$image
"
!=
"off"
&&
"
$image
"
!=
"ascii"
]]
;
then
[[
"
$image_backend
"
==
"image"
]] && \
padding_num
=
"
${
padding
/\\033\[
}
"
string=
"
$(
printf
"%.
$((
columns
-
text_padding
-
gap
))
s"
"
$string
"
)
"
string
=
"
$(
printf
"%.
$((
columns
-
${
padding_num
/C
}
-
gap
))
s"
"
$string
"
)
"
fi
# Tell info() that prin() was used.
# Tell info() that prin() was used.
prin=1
prin=1
...
@@ -2593,13 +2647,6 @@ err() {
...
@@ -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() {
get_script_dir() {
[[ "
$script_dir
" ]] && return
[[ "
$script_dir
" ]] && return
...
@@ -2635,7 +2682,7 @@ get_default_config() {
...
@@ -2635,7 +2682,7 @@ get_default_config() {
fi
fi
if source "
$default_config
"; then
if source "
$default_config
"; then
err
"Config: Sourced default config (
$default_config
)"
err "
Config: Sourced default config
.
(
$default_config
)
"
else
else
err "
Config
:
Default config not found, continuing...
"
err "
Config
:
Default config not found, continuing...
"
fi
fi
...
@@ -2645,12 +2692,12 @@ get_user_config() {
...
@@ -2645,12 +2692,12 @@ get_user_config() {
# Check
$config_file
# Check
$config_file
if [[ -f "
$config_file
" ]]; then
if [[ -f "
$config_file
" ]]; then
source "
$config_file
"
source "
$config_file
"
err
"Config: Sourced user config (
$config_file
)"
err "
Config
:
Sourced user config
.
(
$config_file
)
"
return
return
elif [[ "
$config_file
" == "
travis
" ]]; then
elif [[ "
$config_file
" == "
travis
" ]]; then
source "
$travis_config
"
source "
$travis_config
"
err
"Config: Sourced user config (
$travis_config
)"
err "
Config
:
Sourced user config
.
(
$travis_config
)
"
return
return
fi
fi
mkdir -p "
$XDG_CONFIG_HOME
/neofetch/
"
mkdir -p "
$XDG_CONFIG_HOME
/neofetch/
"
...
@@ -2676,7 +2723,7 @@ get_user_config() {
...
@@ -2676,7 +2723,7 @@ get_user_config() {
fi
fi
source "
$config_file
"
source "
$config_file
"
err
"Config: Sourced user config (
$config_file
)"
err "
Config
:
Sourced user config
.
(
$config_file
)
"
}
}
bar() {
bar() {
...
@@ -2746,7 +2793,7 @@ get_term_padding() {
...
@@ -2746,7 +2793,7 @@ get_term_padding() {
dynamic_prompt() {
dynamic_prompt() {
# Calculate image height in terminal cells.
# Calculate image height in terminal cells.
if
[[
"
$image
"
!=
"ascii"
]]
;
then
if [[ "
$image
_backend
" != "
ascii
" ]]; then
get_term_padding 2>/dev/null
get_term_padding 2>/dev/null
lines="
$((
(
height
+
(
${
border
:-
0
}
*
2
)
+
${
yoffset
:-
0
}
)
/
font_height
))
"
lines="
$((
(
height
+
(
${
border
:-
0
}
*
2
)
+
${
yoffset
:-
0
}
)
/
font_height
))
"
fi
fi
...
@@ -2786,6 +2833,14 @@ old_functions() {
...
@@ -2786,6 +2833,14 @@ old_functions() {
fi
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_uname() {
# Cache the output of uname so we don't
# Cache the output of uname so we don't
# have to spawn it multiple times.
# have to spawn it multiple times.
...
@@ -3011,8 +3066,8 @@ get_args() {
...
@@ -3011,8 +3066,8 @@ get_args() {
# Image
# Image
--image
)
--image
)
image
=
"
$2
"
image
_source
=
"
$2
"
case
"
$2
"
in
"-"
*
|
""
)
image
=
"ascii"
;;
esac
case
"
$2
"
in
"-"
*
|
""
)
image
_backend
=
"ascii"
;;
esac
;;
;;
--image_size
|
--size
)
image_size
=
"
$2
"
;;
--image_size
|
--size
)
image_size
=
"
$2
"
;;
...
@@ -3031,7 +3086,7 @@ get_args() {
...
@@ -3031,7 +3086,7 @@ get_args() {
# Ascii
# Ascii
--ascii
)
--ascii
)
image
=
"ascii"
image
_backend
=
"ascii"
ascii
=
"
$2
"
ascii
=
"
$2
"
case
"
$2
"
in
"-"
*
|
""
)
ascii
=
"distro"
;;
esac
case
"
$2
"
in
"-"
*
|
""
)
ascii
=
"distro"
;;
esac
;;
;;
...
@@ -3048,7 +3103,7 @@ get_args() {
...
@@ -3048,7 +3103,7 @@ get_args() {
;;
;;
--ascii_distro
)
--ascii_distro
)
image
=
"ascii"
image
_backend
=
"ascii"
ascii_distro
=
"
$2
"
ascii_distro
=
"
$2
"
case
"
$2
"
in
"-"
*
|
""
)
ascii_distro
=
"
$distro
"
;;
esac
case
"
$2
"
in
"-"
*
|
""
)
ascii_distro
=
"
$distro
"
;;
esac
;;
;;
...
@@ -3056,7 +3111,7 @@ get_args() {
...
@@ -3056,7 +3111,7 @@ get_args() {
--ascii_logo_size
)
ascii_logo_size
=
"
$2
"
;;
--ascii_logo_size
)
ascii_logo_size
=
"
$2
"
;;
--ascii_bold
)
ascii_bold
=
"
$2
"
;;
--ascii_bold
)
ascii_bold
=
"
$2
"
;;
--logo
|
-L
)
--logo
|
-L
)
image
=
"ascii"
image
_backend
=
"ascii"
print_info
()
{
info line_break
;
}
print_info
()
{
info line_break
;
}
;;
;;
...
@@ -3094,7 +3149,7 @@ main() {
...
@@ -3094,7 +3149,7 @@ main() {
cache_uname
cache_uname
get_os
get_os
get_default_config 2>/dev/null
get_default_config 2>/dev/null
check_
old_flags
old_flags
get_args
"
$@
"
get_args
"
$@
"
get_distro
get_distro
bold
bold
...
@@ -3109,21 +3164,9 @@ main() {
...
@@ -3109,21 +3164,9 @@ main() {
# Hide the cursor and disable line wrap
# Hide the cursor and disable line wrap
printf
"
\0
33[?25l
\0
33[?7l"
printf
"
\0
33[?25l
\0
33[?7l"
# Display the image
if
[[
"
$image
"
!=
"off"
]]
;
then
get_image_backend
get_image_backend
# Find w3mimgdisplay
if
[[
"
$image_backend
"
!=
"off"
]]
;
then
[[
"
$image_backend
"
==
"w3m"
]]
&&
\
[[
"
$image
"
!=
"ascii"
]]
&&
\
get_w3m_img_path
# Get the image src
get_image
# Display the image if enabled
display_image
# Set cursor position next to ascii art
# Set cursor position next to ascii art
printf
"%b"
"
\0
33[
$((${
lines
:-
0
}
-
${
prompt_loc
:-
0
}))
A"
printf
"%b"
"
\0
33[
$((${
lines
:-
0
}
-
${
prompt_loc
:-
0
}))
A"
...
@@ -3136,12 +3179,12 @@ main() {
...
@@ -3136,12 +3179,12 @@ main() {
print_info 2>/dev/null
print_info 2>/dev/null
# Prompt calculation
# Prompt calculation
if
[[
"
$image
"
!=
"off"
]]
;
then
if
[[
"
$image
_backend
"
!=
"off"
]]
;
then
dynamic_prompt
dynamic_prompt
# w3m-img: Draw the image a second time to fix
# w3m-img: Draw the image a second time to fix
# rendering issues in specific terminal emulators.
# rendering issues in specific terminal emulators.
[[
"
$image_backend
"
==
"w3m"
]]
&&
display_image
[[
"
$image_backend
"
==
"
image"
&&
"
$image_program
"
==
"
w3m"
]]
&&
display_image
fi
fi
# Re-enable line wrap
# 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