merge master

This commit is contained in:
Dylan Araps 2016-10-19 20:54:30 +11:00
commit 0e87355eb0
13 changed files with 595 additions and 383 deletions

485
neofetch
View file

@ -27,7 +27,7 @@ getos() {
case "$(uname)" in
"Linux") os="Linux" ;;
"Darwin") os="$(sw_vers -productName)" ;;
*"BSD" | "DragonFly") os="BSD" ;;
*"BSD" | "DragonFly" | "Bitrig") os="BSD" ;;
"CYGWIN"*) os="Windows" ;;
"SunOS") os="Solaris" ;;
*) printf "%s\n" "Unknown OS detected: $(uname)"; exit 1 ;;
@ -104,6 +104,7 @@ getmodel() {
model="$(wmic computersystem get manufacturer,model /value)"
model="${model/Manufacturer'='}"
model="${model/Model'='}"
model="${model//*To Be Filled*}"
;;
"Solaris")
@ -121,24 +122,59 @@ getdistro() {
case "$os" in
"Linux" )
if type -p lsb_release >/dev/null 2>&1; then
distro="$(lsb_release -d 2>/dev/null | awk -F ':' '/Description/ {printf $2}')"
if grep -q 'Microsoft' /proc/version >/dev/null 2>&1 || \
grep -q 'Microsoft' /proc/sys/kernel/osrelease >/dev/null 2>&1; then
case "$distro_shorthand" in
"on") distro="$(lsb_release -sir 2>/dev/null) [Windows 10]" ;;
"tiny") distro="Windows 10" ;;
*) distro="$(lsb_release -sd 2>/dev/null) on Windows 10" ;;
esac
ascii_distro="Windows 10"
elif type -p lsb_release >/dev/null 2>&1; then
case "$distro_shorthand" in
"on") distro="$(lsb_release -sir 2>/dev/null)" ;;
"tiny") distro="$(lsb_release -si 2>/dev/null)" ;;
*) distro="$(lsb_release -sd 2>/dev/null)" ;;
esac
elif type -p guix >/dev/null 2>&1; then
distro="GuixSD"
elif type -p crux >/dev/null 2>&1; then
distro="$(crux)"
case "$distro_shorthand" in
"on") distro="${distro//version}" ;;
"tiny") distro="${distro//version*}" ;;
esac
elif [ -d "/system/app/" ] && [ -d "/system/priv-app" ]; then
distro="Android $(getprop ro.build.version.release)"
else
distro="$(awk -F 'NAME=' '/^NAME=/ {printf $2}' /etc/*ease)"
distro="${distro//\"}"
# Workarounds are included in every shorthand option
case "$distro_shorthand" in
"on")
distro="$(awk -F'=' '/^NAME|VERSION_ID=/ {print $2; exit}' /etc/*ease /usr/lib/*ease)"
[ -z "$distro" ] && distro="$(awk -F'=' '/^DISTRIB_ID|DISTRIB_RELEASE=/ {print $2}' /etc/openwrt_release)"
;;
# Workaround for distros that store the value differently.
[ -z "$distro" ] && distro="$(awk -F 'TAILS_PRODUCT_NAME="|"' '/^TAILS_PRODUCT_NAME=/ {printf $2}' /etc/*ease)"
[ -z "$distro" ] && distro="$(awk '/BLAG/ {print $1; exit}' /etc/*ease)"
[ -z "$distro" ] && distro="$(awk -F "'" '/^DISTRIB_DESCRIPTION/ {print $2}' /etc/openwrt_release)"
"tiny")
distro="$(awk -F'=' '/^NAME=/ {print $2; exit}' /etc/*ease /usr/lib/*ease)"
[ -z "$distro" ] && distro="$(awk -F'=' '/^TAILS_PRODUCT_NAME=/ {print $2}' /etc/*ease)"
[ -z "$distro" ] && distro="$(awk -F'=' '/^DISTRIB_ID=/ {print $2}' /etc/openwrt_release)"
;;
*)
distro="$(awk -F'=' '/^PRETTY_NAME=/ {print $2; exit}' /etc/*ease /usr/lib/*ease)"
[ -z "$distro" ] && distro="$(awk -F'=' '{print $2}' /etc/*ease)"
[ -z "$distro" ] && distro="$(awk '/BLAG/ {print $1; exit}' /etc/*ease)"
[ -z "$distro" ] && distro="$(awk -F'=' '/^DISTRIB_DESCRIPTION=/ {print $2}' /etc/openwrt_release)"
;;
esac
fi
distro="${distro//\"}"
distro="${distro//\'}"
;;
"Mac OS X")
@ -155,9 +191,21 @@ getdistro() {
"10.10"*) codename="OS X Yosemite" ;;
"10.11"*) codename="OS X El Capitan" ;;
"10.12"*) codename="macOS Sierra" ;;
*) codename="Mac OS X" ;;
*) codename="macOS" ;;
esac
distro="$codename $osx_version $osx_build"
case "$distro_shorthand" in
"on") distro="${distro/ ${osx_build}}" ;;
"tiny")
case "$osx_version" in
"10."[4-7]*) distro="${distro/${codename}/Mac OS X}" ;;
"10."[8-9]* | "10.1"[0-1]*) distro="${distro/${codename}/OS X}" ;;
"10.12"*) distro="${distro/${codename}/macOS}" ;;
esac
distro="${distro/ ${osx_build}}"
;;
esac
;;
"iPhone OS")
@ -187,7 +235,10 @@ getdistro() {
;;
"Solaris")
distro="$(nawk 'NR==1{gsub(/^ \t]+|[ \t]+$/,""); printf $1 " " $2;}' /etc/release)"
case "$distro_shorthand" in
"on" | "tiny") distro="$(awk 'NR==1{print $1 " " $2;}' /etc/release)" ;;
*) distro="$(awk 'NR==1{print $1 " " $2 " " $3;}' /etc/release)" ;;
esac
;;
esac
@ -195,12 +246,6 @@ getdistro() {
[ "$os_arch" == "on" ] && \
distro+=" $(uname -m)"
[ "$osx_codename" == "off" ] && \
distro="${distro/${codename}/Mac OS X}"
[ "$osx_buildversion" == "off" ] && \
distro="${distro/ ${osx_build}}"
[ "${ascii_distro:-auto}" == "auto" ] && \
ascii_distro="$(trim "$distro")"
}
@ -363,6 +408,9 @@ getpackages() {
type -p nix-env >/dev/null 2>&1 && \
packages="$((packages+=$(ls -d -1 /nix/store/*/ | wc -l)))"
type -p guix >/dev/null 2>&1 && \
packages="$((packages+=$(ls -d -1 /gnu/store/*/ | wc -l)))"
type -p apk >/dev/null 2>&1 && \
packages="$((packages+=$(apk info | wc -l)))"
@ -481,7 +529,7 @@ getde() {
case "$de" in
"KDE_SESSION_VERSION"*) de="KDE${de/* = }" ;;
*"TDE_FULL_SESSION"*) de="Trinity" ;;
*"MUFFIN"*) de="Cinnamon" ;;
*"MUFFIN"*) de="$(cinnamon --version 2>/dev/null)"; de="${de:-Cinnamon}" ;;
*"xfce4"*) de="XFCE4" ;;
*"xfce5"*) de="XFCE5" ;;
esac
@ -502,18 +550,29 @@ getwm() {
# Fallback for Wayland wms
case "$wm" in
"xwlc")
wm="$(ps -e | grep -m 1 -oE "sway|orbment|velox|orbital")"
[ "$version" -ge 4 ] && wm="${wm^}"
;;
"xwlc") wm="$(ps -e | grep -m 1 -oE "sway|orbment|velox|orbital")" ;;
esac
else
case "$os" in
"Mac OS X") wm="Quartz Compositor" ;;
"Windows") wm="Explorer" ;;
"Windows")
wm="$(tasklist | grep -m 1 -o "bugn\|Windawesome\|blackbox\|emerge\|litestep")"
[ "$wm" == "blackbox" ] && wm="bbLean (Blackbox)"
if [ "$wm" ]; then
wm="$wm, Explorer"
else
wm="Explorer"
fi
;;
esac
fi
# Don't uppercase i3
[ "$version" -ge 4 ] && \
[ "$wm" != "i3" ] && \
wm="${wm^}"
}
# }}}
@ -537,7 +596,10 @@ getwmtheme() {
'Compiz' | 'Mutter'* | 'GNOME Shell' | 'Gala')
if type -p gsettings >/dev/null 2>&1; then
wmtheme="$(gsettings get org.gnome.desktop.wm.preferences theme)"
wmtheme="$(gsettings get org.gnome.shell.extensions.user-theme name)"
[ -z "$wmtheme" ] && \
wmtheme="$(gsettings get org.gnome.desktop.wm.preferences theme)"
elif type -p gconftool-2 >/dev/null 2>&1; then
wmtheme="$(gconftool-2 -g /apps/metacity/general/theme)"
@ -613,7 +675,7 @@ getwmtheme() {
fi
;;
'Explorer')
*'Explorer')
path="/proc/registry/HKEY_CURRENT_USER/Software/Microsoft"
path+="/Windows/CurrentVersion/Themes/CurrentTheme"
@ -622,6 +684,15 @@ getwmtheme() {
wmtheme="${wmtheme%.*}"
;;
'Blackbox' | "bbLean"*)
path="$(wmic process get ExecutablePath | grep "blackbox")"
path="${path//'\'/'/'}"
wmtheme="$(grep "^session\.styleFile:" ${path/\.exe/.rc})"
wmtheme="${wmtheme/'session.styleFile: '}"
wmtheme="${wmtheme##*\\}"
wmtheme="${wmtheme%.*}"
;;
esac
wmtheme="${wmtheme//\'}"
@ -647,9 +718,10 @@ getcpu() {
"Android"*) cpu="$(getprop ro.product.board)" ;;
*) cpu="$(awk -F ': | @' '/model name|Processor/ {printf $2; exit}' /proc/cpuinfo)" ;;
esac
cpu_dir="/sys/devices/system/cpu/cpu0/cpufreq"
# Get cpu speed
if [ -d "/sys/devices/system/cpu/cpu0/cpufreq" ]; then
if [ -d "$cpu_dir" ]; then
case "$speed_type" in
current) speed_type="scaling_cur_freq" ;;
min) speed_type="scaling_min_freq" ;;
@ -660,8 +732,9 @@ getcpu() {
scaling_max) speed_type="scaling_max_freq" ;;
esac
read -t 1 -r speed < \
/sys/devices/system/cpu/cpu0/cpufreq/${speed_type}
# Fallback to cpuinfo_max_freq if $speed_type fails
read -t 1 -r speed < "${cpu_dir}/${speed_type}" || \
read -t 1 -r speed < "${cpu_dir}/cpuinfo_max_freq"
speed="$((speed / 100000))"
else
@ -673,9 +746,9 @@ getcpu() {
# Fix for speeds under 1ghz
if [ -z "${speed:1}" ]; then
speed="0.${speed}"
speed="0.${speed}"
else
speed="${speed:0:1}.${speed:1}"
speed="${speed:0:1}.${speed:1}"
fi
cpu="$cpu @ ${speed}GHz"
@ -683,7 +756,7 @@ getcpu() {
"Mac OS X")
cpu="$(sysctl -n machdep.cpu.brand_string)"
cores="$(sysctl -n hw.ncpu)"
cores="$(sysctl -n hw.physicalcpu)"
;;
"iPhone OS")
@ -811,9 +884,9 @@ getcpu() {
# Fix for speeds under 1ghz
if [ -z "${speed:1}" ]; then
speed="0.${speed}"
speed="0.${speed}"
else
speed="${speed:0:1}.${speed:1}"
speed="${speed:0:1}.${speed:1}"
fi
cpu="$cpu @ ${speed}GHz"
@ -834,9 +907,9 @@ getcpu() {
# Fix for speeds under 1ghz
if [ -z "${speed:1}" ]; then
speed="0.${speed}"
speed="0.${speed}"
else
speed="${speed:0:1}.${speed:1}"
speed="${speed:0:1}.${speed:1}"
fi
cpu="$cpu @ ${speed}GHz"
@ -908,10 +981,10 @@ getcpu_usage() {
# Print the bar
case "$cpu_display" in
"info") cpu_usage="${cpu_usage}%" ;;
"bar") cpu_usage="$(bar $cpu_usage 100)" ;;
"infobar") cpu_usage="${cpu_usage}% $(bar $cpu_usage 100)" ;;
"barinfo") cpu_usage="$(bar $cpu_usage 100) ${cpu_usage}%" ;;
*) cpu_usage="${cpu_usage}%" ;;
esac
}
@ -920,8 +993,8 @@ getcpu_usage() {
# GPU {{{
getgpu() {
case "$os" in
"Linux")
case "$os" in
"Linux")
gpu="$(PATH="/sbin:$PATH" lspci | grep -F "3D")"
# If a GPU with a prefix of '3D' doesn't exist
@ -958,23 +1031,11 @@ getgpu() {
gpu="${gpu/Advanced Micro Devices, Inc\. }"
gpu="${gpu/'[AMD/ATI]' }"
gpu="${gpu/Tahiti PRO}"
gpu="${gpu/Seymour}"
gpu="${gpu/Cayman}"
gpu="${gpu/Richland}"
gpu="${gpu/Pitcairn}"
gpu="${gpu/Broadway}"
gpu="${gpu/XTMobility}"
gpu="${gpu/Mobility}"
gpu="${gpu/Hawaii}"
gpu="${gpu/Tobago}"
gpu="${gpu/Thames}"
gpu="${gpu/Kabini}"
gpu="${gpu/Bonaire}"
gpu="${gpu/XTX}"
gpu="${gpu/ OEM}"
gpu="${gpu/ Cape Verde}"
gpu="${gpu/ \[}"
gpu="${gpu/\]}"
gpu="${gpu/*Radeon/Radeon}"
brand="AMD "
;;
@ -1105,6 +1166,12 @@ getgpu() {
;;
esac
if [ "$gpu_brand" == "off" ]; then
gpu="${gpu/AMD}"
gpu="${gpu/NVIDIA}"
gpu="${gpu/Intel}"
fi
gpu="${gpu}${count}"
}
@ -1141,7 +1208,10 @@ getmemory() {
*) memfree="$(($(vmstat | awk 'END{printf $5}') / 1024))" ;;
esac
memtotal="$(($(sysctl -n hw.physmem) / 1024 / 1024))"
case "$distro" in
"NetBSD"*) memtotal="$(($(sysctl -n hw.physmem64) / 1024 / 1024))" ;;
*) memtotal="$(($(sysctl -n hw.physmem) / 1024 / 1024))" ;;
esac
memused="$((memtotal - memfree))"
;;
@ -1208,20 +1278,42 @@ getsong() {
song="$(gpmdp-remote current)"
state="$(gpmdp-remote status)"
elif [ -n "$(ps x | awk '!(/awk/ || /Helper/) && /iTunes/')" ]; then
elif [ -n "$(ps x | awk '!(/awk/ || /Helper/ || /Cache/) && /iTunes.app/')" ]; then
song="$(osascript -e 'tell application "iTunes" to artist of current track as string & " - " & name of current track as string')"
state="$(osascript -e 'tell application "iTunes" to player state as string')"
elif [ -n "$(ps x | awk '!(/awk/) && /rhythmbox/')" ]; then
song="$(rhythmbox-client --print-playing)"
# Well, what can you expect? It's dbus after all.
state="$(dbus-send --print-reply --dest=org.mpris.MediaPlayer2.rhythmbox /org/mpris/MediaPlayer2 \
org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string: 'PlayBackStatus' |\
awk -F 'string "' '{printf $2}')"
state="${state//\"}"
elif [ -n "$(ps x | awk '!(/awk/) && /banshee/')" ]; then
artist="$(banshee --query-artist | awk -F':' '{print $2}')"
title="$(banshee --query-title | awk -F':' '{print $2}')"
song="$artist - $title"
state="$(banshee --query-current-state | awk -F':' '{print $2}')"
elif [ -n "$(ps x | awk '!(/awk/) && /amarok/')" ]; then
artist="$(qdbus org.kde.amarok /Player GetMetadata | awk -F':' '/^artist/ {print $2}')"
title="$(qdbus org.kde.amarok /Player GetMetadata | awk -F':' '/title/ {print $2}')"
song="$artist - $title"
elif [ -n "$(ps x | awk '!(/awk/) && /deadbeef/')" ]; then
song="$(deadbeef --nowplaying '%a - %t')"
else
song="Not Playing"
fi
case "$state" in
"paused" | "PAUSE")
"paused" | "PAUSE" | "Paused")
song="Paused"
;;
"stopped" | "STOP")
"stopped" | "STOP" | "Stopped")
song="Stopped"
;;
esac
@ -1271,6 +1363,11 @@ getresolution() {
awk '/Resolution:/ {printf $2"x"$4" @ "$6"Hz, "}')"
fi
scale_factor="$(/usr/libexec/PlistBuddy -c "Print DisplayAnyUserSets:0:0:Resolution" /Library/Preferences/com.apple.windowserver.plist)"
[ "${scale_factor%.*}" == "2" ] && \
resolution="${resolution// @/@2x @}"
if [ "$refresh_rate" == "off" ]; then
resolution="${resolution// @ [0-9][0-9]Hz}"
resolution="${resolution// @ [0-9][0-9][0-9]Hz}"
@ -1309,7 +1406,7 @@ getstyle() {
name="gtk-theme-name"
gsettings="gtk-theme"
gconf="gtk_theme"
xfconf="ThemeName"
xfconf="/Net/ThemeName"
kde="widgetStyle"
;;
@ -1317,7 +1414,7 @@ getstyle() {
name="gtk-icon-theme-name"
gsettings="icon-theme"
gconf="icon_theme"
xfconf="IconThemeName"
xfconf="/Net/IconThemeName"
kde="Theme"
;;
@ -1325,7 +1422,7 @@ getstyle() {
name="gtk-font-name"
gsettings="font-name"
gconf="font_theme"
xfconf="FontName"
xfconf="/Gtk/FontName"
kde="font"
;;
esac
@ -1374,7 +1471,7 @@ getstyle() {
"Xfce"*)
type -p xfconf-query >/dev/null 2>&1 && \
gtk2theme="$(xfconf-query -c xsettings -p /Net/"$xfconf")"
gtk2theme="$(xfconf-query -c xsettings -p "$xfconf")"
;;
esac
@ -1474,7 +1571,7 @@ getterm() {
# Check $PPID for terminal emulator.
case "$os" in
"Mac OS X")
# Workaround for OS X systems that
# Workaround for macOS systems that
# don't support the block below.
case "$TERM_PROGRAM" in
"iTerm.app") term="iTerm2" ;;
@ -1500,12 +1597,14 @@ getterm() {
esac
case "${name// }" in
"${SHELL/*\/}" | *"sh" | "tmux" | "screen") getterm "$parent" ;;
"login" | "init") term="$(tty)"; term="${term/*\/}" ;;
"${SHELL/*\/}" | *"sh" | "tmux"* | "screen") getterm "$parent" ;;
"login" | "init") term="$(tty)" ;;
"ruby" | "1" | "systemd" | "sshd"* | "python"*) unset term ;;
"gnome-terminal-") term="gnome-terminal" ;;
*) term="$name" ;;
*) term="${name##*/}" ;;
esac
[ "$version" -ge 4 ] && term="${term^}"
}
# }}}
@ -1537,7 +1636,7 @@ gettermfont() {
;;
"termite")
termfont="$(awk -F '= ' '!/^($|#)/ && /font/ {printf $2; exit}' "${XDG_CONFIG_HOME}/termite/config")"
termfont="$(awk -F '= ' '!/^($|#|;)/ && /font/ {printf $2; exit}' "${XDG_CONFIG_HOME}/termite/config")"
;;
"mintty")
@ -1554,6 +1653,8 @@ gettermfont() {
termfont="${termfont/:*}"
;;
esac
[ "$version" -ge 4 ] && termfont="${termfont^}"
}
# }}}
@ -1575,7 +1676,7 @@ getdisk() {
"Mac OS X" | "BSD")
case "$distro" in
"FreeBSD"* | *"OS X"* )
"FreeBSD"* | *"OS X"* | "Mac"* )
df_flags="-l -H /"
df_dir="/"
;;
@ -1679,20 +1780,20 @@ getbattery() {
battery="$(envstat | awk '\\(|\\)' '/charge:/ {print $2}')"
battery="${battery/\.*/%}"
;;
"OpenBSD"* | "Bitrig"*)
battery0full="$(sysctl -n hw.sensors.acpibat0.watthour0)"
battery0full="${battery0full/ Wh*}"
battery0now="$(sysctl -n hw.sensors.acpibat0.watthour3)"
battery0now="${battery0now/ Wh*}"
[ "$battery0full" ] && \
battery="$((100 * ${battery0now/\.} / ${battery0full/\.}))%"
;;
esac
;;
"OpenBSD")
battery0full="$(sysctl -n hw.sensors.acpibat0.watthour0)"
battery0full="${battery0full/ Wh*}"
battery0now="$(sysctl -n hw.sensors.acpibat0.watthour3)"
battery0now="${battery0now/ Wh*}"
[ "$battery0full" ] && \
battery="$((100 * ${battery0now/\.} / ${battery0full/\.}))%"
;;
"Mac OS X")
battery="$(pmset -g batt | grep -o '[0-9]*%')"
battery_state="$(pmset -g batt | awk 'NR==2 {print $3}')"
@ -1793,7 +1894,7 @@ getbirthday() {
"BSD")
case "$distro" in
"OpenBSD"*)
"OpenBSD"* | "Bitrig"*)
birthday="$(ls -alctT / | awk '/lost\+found/ {printf $6 " " $7 " " $9 " " $8}')"
birthday_shorthand="on"
;;
@ -1840,14 +1941,15 @@ getbirthday() {
getcols() {
if [ "$color_blocks" == "on" ]; then
# Convert the width to space chars.
block_width="$(printf "%$((block_width-=1))s")"
block_width="$(printf "%${block_width}s")"
block_width="${block_width// /█}"
# Generate the string.
while [ $start -le $end ]; do
case "$start" in
[0-6]) blocks+="${reset}\033[3${start}m\033[4${start}m%${block_width}s" ;;
7) blocks+="${reset}\033[3${start}m\033[4${start}m%${block_width}s" ;;
*) blocks2+="\033[38;5;${start}m\033[48;5;${start}m%${block_width}s" ;;
[0-6]) blocks+="${reset}\033[3${start}m\033[4${start}m${block_width}" ;;
7) blocks+="${reset}\033[3${start}m\033[4${start}m${block_width}" ;;
*) blocks2+="\033[38;5;${start}m\033[48;5;${start}m${block_width}" ;;
esac
start="$((start+=1))"
done
@ -1861,7 +1963,7 @@ getcols() {
# Add newlines to the string.
cols="${cols%%'nl'}"
cols="${cols//nl/\\n${padding}}"
cols="${cols//nl/\\n${padding}}"
fi
}
@ -1894,6 +1996,7 @@ getwallpaper() {
# Strip quotes etc from the path.
img="${img/'file://'}"
img="${img//\'}"
img="${img//\%20/ }"
fi
;;
@ -1941,8 +2044,10 @@ getascii() {
ascii="${ascii_distro,,}"
fi
[ "$ascii_logo_size" == "small" ] && \
if [ "$ascii_logo_size" == "small" ]; then
ascii="${ascii/ *}_small"
prompt_loc="3"
fi
if [ -f "/usr/share/neofetch/ascii/distro/${ascii/ *}" ]; then
ascii="/usr/share/neofetch/ascii/distro/${ascii/ *}"
@ -2057,6 +2162,8 @@ getimage() {
[ "${#term_size}" -le 5 ] && err "Your terminal doesn't support \\\033[14t, falling back to ascii mode."
return
else
clear
fi
# Get terminal lines and columns
@ -2170,10 +2277,6 @@ getimage() {
img="$thumbnail_dir/$imgname"
}
takescrot() {
$scrot_cmd "${scrot_dir}${scrot_name}"
}
# }}}
# Find w3m-img {{{
@ -2209,6 +2312,9 @@ displayimage() {
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%s\n" "0;1;$xoffset;$yoffset;$width;$height;;;;;$img\n4;\n3;" |\
$w3m_img_path 2>/dev/null || padding="\033[0C"
;;
@ -2242,6 +2348,48 @@ getimagebackend() {
# }}}
# Screenshot {{{
takescrot() {
$scrot_cmd "${scrot_dir}${scrot_name}"
[ "$scrot_upload" == "on" ] && scrot_upload
}
# }}}
# Screenshot Upload {{{
scrot_upload() {
if ! type -p curl >/dev/null 2>&1; then
printf "%s\n" "[!] Install curl to upload images"
return
fi
image_file="${scrot_dir}${scrot_name}"
printf "%s\n" "Uploading image..."
case "$image_host" in
"teknik")
image_url="$(curl -sf -F file="@${image_file}" "https://api.teknik.io/v1/Upload")"
image_url="$(awk -F 'url:|,' '{printf $2}' <<< "${image_url//\"}")"
;;
"imgur")
image_url="$(curl -sH "Authorization: Client-ID $imgur_client_id" -F image="@${image_file}" "https://api.imgur.com/3/upload")"
image_url="$(awk -F 'id:|,' '{printf $2}' <<< "${image_url//\"}")"
[ "$image_url" ] && image_url="https://i.imgur.com/${image_url}.png"
;;
esac
if [ "$image_url" ]; then
printf "%s\n" "$image_url"
else
printf "%s\n" "[!] Image failed to upload"
fi
}
# }}}
# }}}
# Text Formatting {{{
@ -2268,14 +2416,6 @@ info() {
# Trim whitespace
output="$(trim "$output")"
# 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
case "$1" in
title)
string="${title_color}${bold}${output}"
@ -2298,7 +2438,18 @@ info() {
[ -z "$2" ] && string="${string/*: }"
# Print the string
printf "%b%s\n" "${padding}${string}${reset}"
printf "%b%s\n" "${padding}${string}${reset} "
# Calculate info height
info_height="$((info_height+=1))"
# 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
}
# }}}
@ -2308,14 +2459,6 @@ info() {
prin() {
string="$1${2:+: $2}"
# 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
# If $2 doesn't exist we format $1 as info
if [ -z "$2" ]; then
subtitle_color="$info_color"
@ -2330,7 +2473,18 @@ prin() {
string="$(trim "$string")"
# Print the info
printf "%b%s\n" "${padding}${string}${reset}"
printf "%b%s\n" "${padding}${string}${reset} "
# Calculate info height
info_height="$((info_height+=1))"
# 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
}
# }}}
@ -2342,7 +2496,7 @@ getunderline() {
"on")
underline="$(printf %"$length"s)"
underline="${underline// /$underline_char}"
;;
;;
"off") underline="" ;;
esac
}
@ -2431,7 +2585,7 @@ colors() {
ascii_distro="mint"
;;
"LMDE"* | "Chapeau"* | "Android"*)
"LMDE"* | "Chapeau"* | "Bitrig"* | "Android"*)
setcolors 2 7
;;
@ -2439,7 +2593,7 @@ colors() {
setcolors 5 7
;;
"OpenBSD"*)
"OpenBSD"* | "GuixSD"*)
setcolors 3 7 6 1 8
;;
@ -2456,12 +2610,17 @@ colors() {
ascii_distro="puppy"
;;
"Sparky"*)
setcolors 1 7
ascii_distro="sparky"
;;
"Scientific"*)
setcolors 4 1 7
;;
"Solus"*)
setcolors 7 8
setcolors 7 4 0
;;
"Trisquel"* | "NixOS"* | "Zorin"*)
@ -2566,7 +2725,7 @@ bold() {
# Linebreak {{{
getlinebreak() {
linebreak=" "
linebreak=" "
}
# }}}
@ -2603,6 +2762,15 @@ err() {
# }}}
# Check for old flags {{{
checkoldflags() {
[ -n "$osx_buildversion" ] && err "\$osx_buildversion is deprecated, use \$distro_shorthand instead."
[ -n "$osx_codename" ] && err "\$osx_codename is deprecated, use \$distro_shorthand instead."
}
# }}}
# Get script directory {{{
getscriptdir() {
@ -2741,20 +2909,41 @@ kdeconfigdir() {
# Dynamic prompt location {{{
dynamicprompt() {
# Get cursor position
info_height="$(IFS=';' builtin read -srdR -t 1 -d c -p $'\033[6n\033[c' ROW COL; printf "%s" "${ROW#*[}")"
# Calculate image height in terminal cells.
# The '+ 3' adds a gap between the prompt and the content.
# The '+ 4' adds a gap between the prompt and the content.
[ "$image" != "ascii" ] && [ "$image" != "off" ] && \
lines="$((${height:-1} / ${font_height:-1} + 3))"
lines="$((${height:-1} / ${font_height:-1} + 4))"
# 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 [ "${lines:-0}" -lt "${info_height:-0}" ]; then
lines="0"
else
lines="$((lines - info_height - 4))"
fi
# Set the prompt location
[ "$image" != "off" ] && printf "%b%s" "\033[${lines:-0}H"
[ "$image" != "off" ] && printf "\033[${lines/-*/0}B"
# Add some padding if the lines are above 0
if [ "$lines" -gt 0 ]; then
printf "\n\n"
fi
}
# }}}
# Scrot args {{{
scrot_args() {
scrot="on"
case "$2" in
"-"* | "") ;;
*)
scrot_name="${2##*/}"
scrot_dir="${2/$scrot_name}"
;;
esac
}
# }}}
@ -2774,9 +2963,7 @@ usage() { cat << EOF
in the output.
NOTE: You can supply multiple args. eg.
'neofetch --disable cpu gpu disk shell'
--osx_buildversion on/off Hide/Show Mac OS X build version.
--osx_codename on/off Hide/Show Mac OS X codename.
--os_arch on/off Hide/Show Windows architecture.
--os_arch on/off Hide/Show OS architecture.
--speed_type type Change the type of cpu speed to display.
Possible values: current, min, max, bios,
scaling_current, scaling_min, scaling_max
@ -2784,11 +2971,14 @@ usage() { cat << EOF
--cpu_shorthand type Shorten the output of CPU
Possible values: name, speed, tiny, on, off
--cpu_cores on/off Whether or not to display the number of CPU cores
--distro_shorthand on/off Shorten the output of distro (tiny, on, off)
NOTE: This is only possible on Linux, macOS, and Solaris
--kernel_shorthand on/off Shorten the output of kernel
--uptime_shorthand on/off Shorten the output of uptime (tiny, on, off)
--refresh_rate on/off Whether to display the refresh rate of each monitor
Unsupported on Windows
--gpu_shorthand on/off Shorten the output of GPU (tiny, on, off)
--gpu_brand on/off Enable/Disable GPU brand in output. (AMD/NVIDIA/Intel)
--gtk_shorthand on/off Shorten output of gtk theme/icons
--gtk2 on/off Enable/Disable gtk2 theme/icons output
--gtk3 on/off Enable/Disable gtk3 theme/icons output
@ -2860,10 +3050,13 @@ usage() { cat << EOF
--ascii_logo_size Size of ascii logo.
Supported distros: Arch, Gentoo, Crux, OpenBSD.
--ascii_bold on/off Whether or not to bold the ascii logo.
--logo | -L Hide the info text and only show the ascii logo.
Screenshot:
--scrot /path/to/img Take a screenshot, if path is left empty the screen-
--scrot | -s /path/to/img Take a screenshot, if path is left empty the screen-
shot function will use \$scrot_dir and \$scrot_name.
--upload | -su /pth/t/img Same as --scrot but uploads the scrot to a website.
--image_host Website to upload scrots to. Takes: imgur, teknik
--scrot_cmd cmd Screenshot program to launch
Other:
@ -2892,7 +3085,7 @@ getargs() {
config="off"
;;
*"--config --"*) ;;
*"--config -"*) ;;
*"--config"*) config="off" ;;
esac
@ -2902,14 +3095,14 @@ getargs() {
case $1 in
# Info
--os_arch) os_arch="$2" ;;
--osx_buildversion) osx_buildversion="$2" ;;
--osx_codename) osx_codename="$2" ;;
--cpu_cores) cpu_cores="$2" ;;
--speed_type) speed_type="$2" ;;
--distro_shorthand) distro_shorthand="$2" ;;
--kernel_shorthand) kernel_shorthand="$2" ;;
--uptime_shorthand) uptime_shorthand="$2" ;;
--cpu_shorthand) cpu_shorthand="$2" ;;
--gpu_shorthand) gpu_shorthand="$2" ;;
--gpu_brand) gpu_brand="$2" ;;
--refresh_rate) refresh_rate="$2" ;;
--gtk_shorthand) gtk_shorthand="$2" ;;
--gtk2) gtk2="$2" ;;
@ -2927,7 +3120,7 @@ getargs() {
for func in "$@"; do
case "$func" in
"--disable") continue ;;
"--"*) return ;;
"-"*) return ;;
*) unset -f "get$func" ;;
esac
done
@ -2938,7 +3131,7 @@ getargs() {
unset colors
for arg in "$2" "$3" "$4" "$5" "$6" "$7"; do
case "$arg" in
"--"*) break ;;
"-"*) break ;;
*) colors+=($arg)
esac
done
@ -2975,10 +3168,10 @@ getargs() {
# Image
--image)
image="$2"
case "$2" in "--"* | "") image="ascii" ;; esac
case "$2" in "-"* | "") image="ascii" ;; esac
;;
--size) image_size="$2" ;;
--image_size | --size) image_size="$2" ;;
--crop_mode) crop_mode="$2" ;;
--crop_offset) crop_offset="$2" ;;
--xoffset) xoffset="$2" ;;
@ -2994,14 +3187,14 @@ getargs() {
--ascii)
image="ascii"
ascii="$2"
case "$2" in "--"* | "") ascii="distro" ;; esac
case "$2" in "-"* | "") ascii="distro" ;; esac
;;
--ascii_colors)
unset ascii_colors
for arg in "$2" "$3" "$4" "$5" "$6" "$7"; do
case "$arg" in
"--"*) break ;;
"-"*) break ;;
*) ascii_colors+=($arg)
esac
done
@ -3010,20 +3203,27 @@ getargs() {
--ascii_distro)
ascii_distro="$2"
case "$2" in "--"* | "") ascii_distro="$distro" ;; esac
case "$2" in "-"* | "") ascii_distro="$distro" ;; esac
;;
--ascii_logo_size) ascii_logo_size="$2" ;;
--ascii_bold) ascii_bold="$2" ;;
--logo | -L)
image="ascii"
printinfo() { info linebreak; }
;;
# Screenshot
--scrot | -s)
scrot="on"
if [ "$2" ]; then
scrot_name="${2##*/}"
scrot_dir="${2/$scrot_name}"
fi
scrot_args "$@"
;;
--upload | -su)
scrot_upload="on"
scrot_args "$@"
;;
--image_host) image_host="$2" ;;
--scrot_cmd) scrot_cmd="$2" ;;
# Other
@ -3062,7 +3262,7 @@ getargs() {
-v) verbose="on" ;;
-vv) set -x; verbose="on" ;;
--help) usage ;;
--version) printf "%s\n" "Neofetch 1.8"; exit ;;
--version) printf "%s\n" "Neofetch 1.9"; exit ;;
esac
shift
@ -3076,6 +3276,7 @@ getargs() {
main() {
getos
getdefaultconfig 2>/dev/null
checkoldflags
getargs "$@"
getdistro
@ -3089,9 +3290,6 @@ main() {
# If the script exits for any reason, unhide the cursor.
trap 'printf "\033[?25h"' EXIT
# Clear the scren
clear
# Hide the cursor and disable line wrap
printf "\033[?25l\033[?7l"
@ -3111,8 +3309,11 @@ main() {
displayimage
fi
# Move cursor to the top
printf "\033[0H"
# Set cursor position next to ascii art
printf "\033[$((${lines:-4} - ${prompt_loc:-4}))A"
# Reset horizontal cursor position
printf "\033[9999999D"
# Print the info
printinfo