Merge pull request #429 from dylanaraps/vars

General: Change all vars/functions to use underlines
This commit is contained in:
Dylan Araps 2016-11-09 23:32:26 +11:00 committed by GitHub
commit 4f4af5a2ea
3 changed files with 188 additions and 166 deletions

View file

@ -14,7 +14,7 @@ export LANG=C
# Info # Info
# See this wiki page for more info: # See this wiki page for more info:
# https://github.com/dylanaraps/neofetch/wiki/Customizing-Info # https://github.com/dylanaraps/neofetch/wiki/Customizing-Info
printinfo() { print_info() {
info title info title
info underline info underline
@ -27,11 +27,11 @@ printinfo() {
info "Resolution" resolution info "Resolution" resolution
info "DE" de info "DE" de
info "WM" wm info "WM" wm
info "WM Theme" wmtheme info "WM Theme" wm_theme
info "Theme" theme info "Theme" theme
info "Icons" icons info "Icons" icons
info "Terminal" term info "Terminal" term
info "Terminal Font" termfont info "Terminal Font" term_font
info "CPU" cpu info "CPU" cpu
info "GPU" gpu info "GPU" gpu
info "Memory" memory info "Memory" memory
@ -41,14 +41,14 @@ printinfo() {
# info "Battery" battery # info "Battery" battery
# info "Font" font # info "Font" font
# info "Song" song # info "Song" song
# info "Local IP" localip # info "Local IP" local_ip
# info "Public IP" publicip # info "Public IP" public_ip
# info "Users" users # info "Users" users
# info "Birthday" birthday # info "Birthday" birthday
info linebreak info line_break
info cols info cols
info linebreak info line_break
} }

View file

@ -4,10 +4,10 @@
# Neofetch config file for travis.ci # Neofetch config file for travis.ci
# https://github.com/dylanaraps/neofetch # https://github.com/dylanaraps/neofetch
printinfo() { print_info() {
if [ "$TRAVIS_OS_NAME" ]; then if [ "$TRAVIS_OS_NAME" ]; then
info linebreak info line_break
info linebreak info line_break
fi fi
info title info title
@ -22,11 +22,11 @@ printinfo() {
info "Resolution" resolution info "Resolution" resolution
info "DE" de info "DE" de
info "WM" wm info "WM" wm
info "WM Theme" wmtheme info "WM Theme" wm_theme
info "Theme" theme info "Theme" theme
info "Icons" icons info "Icons" icons
info "Terminal" term info "Terminal" term
info "Terminal Font" termfont info "Terminal Font" term_font
info "CPU" cpu info "CPU" cpu
info "GPU" gpu info "GPU" gpu
info "Memory" memory info "Memory" memory
@ -36,14 +36,14 @@ printinfo() {
info "Battery" battery info "Battery" battery
info "Font" font info "Font" font
info "Song" song info "Song" song
info "Local IP" localip info "Local IP" local_ip
info "Public IP" publicip info "Public IP" public_ip
info "Users" users info "Users" users
info "Birthday" birthday info "Birthday" birthday
info linebreak info line_break
info cols info cols
info linebreak info line_break
} }
refresh_rate="on" refresh_rate="on"

322
neofetch
View file

@ -9,7 +9,7 @@
# https://github.com/dylanaraps/ # https://github.com/dylanaraps/
version="${BASH_VERSION/.*}" version="${BASH_VERSION/.*}"
SYS_LOCALE="${LANG:-C}" sys_locale="${LANG:-C}"
XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-${HOME}/.config}" XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-${HOME}/.config}"
# Speed up script by not using unicode # Speed up script by not using unicode
@ -23,7 +23,7 @@ shopt -s nocasematch
# Operating System {{{ # Operating System {{{
getos() { get_os() {
case "$(uname)" in case "$(uname)" in
"Linux") os="Linux" ;; "Linux") os="Linux" ;;
"Darwin") os="$(sw_vers -productName)" ;; "Darwin") os="$(sw_vers -productName)" ;;
@ -40,7 +40,7 @@ getos() {
# Model {{{ # Model {{{
getmodel() { get_model() {
case "$os" in case "$os" in
"Linux") "Linux")
if [[ -d "/system/app/" && -d "/system/priv-app" ]]; then if [[ -d "/system/app/" && -d "/system/priv-app" ]]; then
@ -122,7 +122,7 @@ getmodel() {
# Distro {{{ # Distro {{{
getdistro() { get_distro() {
[[ "$distro" ]] && return [[ "$distro" ]] && return
case "$os" in case "$os" in
@ -268,7 +268,7 @@ getdistro() {
# Title {{{ # Title {{{
gettitle() { get_title() {
title="${USER:-$(whoami || printf "%s" "${HOME/*\/}")}@${HOSTNAME:-$(hostname)}" title="${USER:-$(whoami || printf "%s" "${HOME/*\/}")}@${HOSTNAME:-$(hostname)}"
} }
@ -276,7 +276,7 @@ gettitle() {
# Kernel {{{ # Kernel {{{
getkernel() { get_kernel() {
case "$kernel_shorthand" in case "$kernel_shorthand" in
"on") kernel_flags="-r" ;; "on") kernel_flags="-r" ;;
"off") kernel_flags="-sr" ;; "off") kernel_flags="-sr" ;;
@ -297,7 +297,7 @@ getkernel() {
# Uptime {{{ # Uptime {{{
getuptime() { get_uptime() {
# Since Haiku's uptime cannot be fetched in seconds, a case outside # Since Haiku's uptime cannot be fetched in seconds, a case outside
# the usual case is needed # the usual case is needed
case "$os" in case "$os" in
@ -380,7 +380,7 @@ getuptime() {
# Package Count {{{ # Package Count {{{
getpackages() { get_packages() {
case "$os" in case "$os" in
"Linux" | "iPhone OS" | "Solaris" | "GNU") "Linux" | "iPhone OS" | "Solaris" | "GNU")
type -p pacman >/dev/null && \ type -p pacman >/dev/null && \
@ -480,7 +480,7 @@ getpackages() {
# Shell {{{ # Shell {{{
getshell() { get_shell() {
case "$shell_path" in case "$shell_path" in
"on") shell="$SHELL" ;; "on") shell="$SHELL" ;;
"off") shell="${SHELL##*/}" ;; "off") shell="${SHELL##*/}" ;;
@ -522,7 +522,7 @@ getshell() {
# }}} # }}}
# Desktop Environment {{{ # Desktop Environment {{{
getde() { get_de() {
case "$os" in case "$os" in
"Mac OS X") de="Aqua" ;; "Mac OS X") de="Aqua" ;;
"Windows") "Windows")
@ -556,7 +556,7 @@ getde() {
# Window Manager {{{ # Window Manager {{{
getwm() { get_wm() {
if [[ -n "$DISPLAY" && "$os" != "Mac OS X" ]]; then if [[ -n "$DISPLAY" && "$os" != "Mac OS X" ]]; then
id="$(xprop -root -notype | awk '$1=="_NET_SUPPORTING_WM_CHECK:"{print $5}')" id="$(xprop -root -notype | awk '$1=="_NET_SUPPORTING_WM_CHECK:"{print $5}')"
wm="$(xprop -id "$id" -notype -f _NET_WM_NAME 8t)" wm="$(xprop -id "$id" -notype -f _NET_WM_NAME 8t)"
@ -585,57 +585,57 @@ getwm() {
# Window Manager Theme {{{ # Window Manager Theme {{{
getwmtheme() { get_wm_theme() {
[[ -z "$wm" ]] && getwm [[ -z "$wm" ]] && get_wm
[[ -z "$de" ]] && getde [[ -z "$de" ]] && get_de
case "$wm" in case "$wm" in
"E16") wmtheme="$(awk -F "= " '/theme.name/ {print $2}' "$HOME/.e16/e_config--0.0.cfg")";; "E16") wm_theme="$(awk -F "= " '/theme.name/ {print $2}' "$HOME/.e16/e_config--0.0.cfg")";;
"Sawfish") wmtheme="$(awk -F ")" '/\(quote default-frame-style/ {print $2}' "$HOME/.sawfish/custom")" ;; "Sawfish") wm_theme="$(awk -F ")" '/\(quote default-frame-style/ {print $2}' "$HOME/.sawfish/custom")" ;;
"Cinnamon" | "Muffin" | "Mutter (Muffin)") "Cinnamon" | "Muffin" | "Mutter (Muffin)")
detheme="$(gsettings get org.cinnamon.theme name)" detheme="$(gsettings get org.cinnamon.theme name)"
wmtheme="$(gsettings get org.cinnamon.desktop.wm.preferences theme)" wm_theme="$(gsettings get org.cinnamon.desktop.wm.preferences theme)"
wmtheme="$detheme (${wmtheme})" wm_theme="$detheme (${wm_theme})"
;; ;;
"Compiz" | "Mutter" | "GNOME Shell" | "Gala") "Compiz" | "Mutter" | "GNOME Shell" | "Gala")
if type -p gsettings >/dev/null; then if type -p gsettings >/dev/null; then
wmtheme="$(gsettings get org.gnome.shell.extensions.user-theme name)" wm_theme="$(gsettings get org.gnome.shell.extensions.user-theme name)"
[[ -z "${wmtheme//\'}" ]] && \ [[ -z "${wm_theme//\'}" ]] && \
wmtheme="$(gsettings get org.gnome.desktop.wm.preferences theme)" wm_theme="$(gsettings get org.gnome.desktop.wm.preferences theme)"
elif type -p gconftool-2 >/dev/null; then elif type -p gconftool-2 >/dev/null; then
wmtheme="$(gconftool-2 -g /apps/metacity/general/theme)" wm_theme="$(gconftool-2 -g /apps/metacity/general/theme)"
fi fi
;; ;;
"Metacity"*) "Metacity"*)
if [[ "$de" == "Deepin" ]]; then if [[ "$de" == "Deepin" ]]; then
wmtheme="$(gsettings get com.deepin.wrap.gnome.desktop.wm.preferences theme)" wm_theme="$(gsettings get com.deepin.wrap.gnome.desktop.wm.preferences theme)"
else else
wmtheme="$(gconftool-2 -g /apps/metacity/general/theme)" wm_theme="$(gconftool-2 -g /apps/metacity/general/theme)"
fi fi
;; ;;
"E17" | "Enlightenment") "E17" | "Enlightenment")
if type -p eet >/dev/null; then if type -p eet >/dev/null; then
wmtheme="$(eet -d "$HOME/.e/e/config/standard/e.cfg" config | awk '/value \"file\" string.*.edj/ {print $4}')" wm_theme="$(eet -d "$HOME/.e/e/config/standard/e.cfg" config | awk '/value \"file\" string.*.edj/ {print $4}')"
wmtheme="${wmtheme##*/}" wm_theme="${wm_theme##*/}"
wmtheme="${wmtheme%.*}" wm_theme="${wm_theme%.*}"
fi fi
;; ;;
"Fluxbox") "Fluxbox")
[[ -f "$HOME/.fluxbox/init" ]] && \ [[ -f "$HOME/.fluxbox/init" ]] && \
wmtheme="$(awk -F "/" '/styleFile/ {print $NF}' "$HOME/.fluxbox/init")" wm_theme="$(awk -F "/" '/styleFile/ {print $NF}' "$HOME/.fluxbox/init")"
;; ;;
"IceWM"*) "IceWM"*)
[[ -f "$HOME/.icewm/theme" ]] && \ [[ -f "$HOME/.icewm/theme" ]] && \
wmtheme="$(awk -F "[\",/]" '!/#/ {print $2}' "$HOME/.icewm/theme")" wm_theme="$(awk -F "[\",/]" '!/#/ {print $2}' "$HOME/.icewm/theme")"
;; ;;
"Openbox") "Openbox")
@ -646,37 +646,37 @@ getwmtheme() {
ob_file="rc" ob_file="rc"
fi fi
wmtheme="$(awk -F "[<,>]" '/<theme/ {getline; print $3}' "$XDG_CONFIG_HOME/openbox/${ob_file}.xml")"; wm_theme="$(awk -F "[<,>]" '/<theme/ {getline; print $3}' "$XDG_CONFIG_HOME/openbox/${ob_file}.xml")";
;; ;;
"PekWM") "PekWM")
[[ -f "$HOME/.pekwm/config" ]] && \ [[ -f "$HOME/.pekwm/config" ]] && \
wmtheme="$(awk -F "/" '/Theme/ {gsub(/\"/,""); print $NF}' "$HOME/.pekwm/config")" wm_theme="$(awk -F "/" '/Theme/ {gsub(/\"/,""); print $NF}' "$HOME/.pekwm/config")"
;; ;;
"Xfwm4") "Xfwm4")
[[ -f "${HOME}/.config/xfce4/xfconf/xfce-perchannel-xml/xfwm4.xml" ]] && \ [[ -f "${HOME}/.config/xfce4/xfconf/xfce-perchannel-xml/xfwm4.xml" ]] && \
wmtheme="$(xfconf-query -c xfwm4 -p /general/theme)" wm_theme="$(xfconf-query -c xfwm4 -p /general/theme)"
;; ;;
"KWin"*) "KWin"*)
kdeconfigdir kde_config_dir
kde_config_dir="${kde_config_dir%/}" kde_config_dir="${kde_config_dir%/}"
if [[ -f "$kde_config_dir/share/config/kwinrc" ]]; then if [[ -f "$kde_config_dir/share/config/kwinrc" ]]; then
wmtheme="$(awk '/PluginLib=kwin3_/{gsub(/PluginLib=kwin3_/,"",$0); print $0; exit}' "$kde_config_dir/share/config/kwinrc")" wm_theme="$(awk '/PluginLib=kwin3_/{gsub(/PluginLib=kwin3_/,"",$0); print $0; exit}' "$kde_config_dir/share/config/kwinrc")"
elif [[ -f "$kde_config_dir/share/config/kdebugrc" ]]; then elif [[ -f "$kde_config_dir/share/config/kdebugrc" ]]; then
wmtheme="$(awk '/(decoration)/ {gsub(/\[/,"",$1); print $1; exit}' "$kde_config_dir/share/config/kdebugrc")" wm_theme="$(awk '/(decoration)/ {gsub(/\[/,"",$1); print $1; exit}' "$kde_config_dir/share/config/kdebugrc")"
fi fi
;; ;;
"Quartz Compositor") "Quartz Compositor")
wmtheme="$(/usr/libexec/PlistBuddy -c "Print AppleAquaColorVariant" ~/Library/Preferences/.GlobalPreferences.plist)" wm_theme="$(/usr/libexec/PlistBuddy -c "Print AppleAquaColorVariant" ~/Library/Preferences/.GlobalPreferences.plist)"
if [[ -z "$wmtheme" || "$wmtheme" == "1" ]]; then if [[ -z "$wm_theme" || "$wm_theme" == "1" ]]; then
wmtheme="Blue" wm_theme="Blue"
else else
wmtheme="Graphite" wm_theme="Graphite"
fi fi
;; ;;
@ -684,31 +684,31 @@ getwmtheme() {
path="/proc/registry/HKEY_CURRENT_USER/Software/Microsoft" path="/proc/registry/HKEY_CURRENT_USER/Software/Microsoft"
path+="/Windows/CurrentVersion/Themes/CurrentTheme" path+="/Windows/CurrentVersion/Themes/CurrentTheme"
wmtheme="$(head -n1 "$path")" wm_theme="$(head -n1 "$path")"
wmtheme="${wmtheme##*\\}" wm_theme="${wm_theme##*\\}"
wmtheme="${wmtheme%.*}" wm_theme="${wm_theme%.*}"
;; ;;
"Blackbox" | "bbLean"*) "Blackbox" | "bbLean"*)
path="$(wmic process get ExecutablePath | grep -F "blackbox")" path="$(wmic process get ExecutablePath | grep -F "blackbox")"
path="${path//\\/\/}" path="${path//\\/\/}"
wmtheme="$(grep "^session\.styleFile:" "${path/\.exe/.rc}")" wm_theme="$(grep "^session\.styleFile:" "${path/\.exe/.rc}")"
wmtheme="${wmtheme/'session.styleFile: '}" wm_theme="${wm_theme/'session.styleFile: '}"
wmtheme="${wmtheme##*\\}" wm_theme="${wm_theme##*\\}"
wmtheme="${wmtheme%.*}" wm_theme="${wm_theme%.*}"
;; ;;
esac esac
wmtheme="${wmtheme//\'}" wm_theme="${wm_theme//\'}"
[[ "$version" -ge 4 ]] && wmtheme="${wmtheme^}" [[ "$version" -ge 4 ]] && wm_theme="${wm_theme^}"
} }
# }}} # }}}
# CPU {{{ # CPU {{{
getcpu() { get_cpu() {
# NetBSD emulates the linux /proc filesystem instead of using sysctl for hw # NetBSD emulates the linux /proc filesystem instead of using sysctl for hw
# information so we have to use this block below which temporarily sets the # information so we have to use this block below which temporarily sets the
# OS to 'Linux' for the duration of this function. # OS to 'Linux' for the duration of this function.
@ -901,7 +901,7 @@ getcpu() {
# CPU Usage {{{ # CPU Usage {{{
getcpu_usage() { get_cpu_usage() {
case "$os" in case "$os" in
"Windows") "Windows")
cpu_usage="$(wmic cpu get loadpercentage /value)" cpu_usage="$(wmic cpu get loadpercentage /value)"
@ -938,7 +938,7 @@ getcpu_usage() {
# GPU {{{ # GPU {{{
getgpu() { get_gpu() {
case "$os" in case "$os" in
"Linux" | "GNU") "Linux" | "GNU")
# Use cache if it exists # Use cache if it exists
@ -1062,7 +1062,7 @@ getgpu() {
# Memory {{{ # Memory {{{
getmemory() { get_memory() {
case "$os" in case "$os" in
"Linux" | "Windows" | "GNU") "Linux" | "Windows" | "GNU")
# MemUsed = Memtotal + Shmem - MemFree - Buffers - Cached - SReclaimable # MemUsed = Memtotal + Shmem - MemFree - Buffers - Cached - SReclaimable
@ -1132,7 +1132,7 @@ getmemory() {
# Song {{{ # Song {{{
getsong() { get_song() {
# This is absurdly long. # This is absurdly long.
player="$(ps x | awk '!(/awk|Helper|Cache/) && /mpd|cmus|mocp|spotify|Google Play|iTunes.app|rhythmbox|banshee|amarok|deadbeef|audacious/ {printf $5 " " $6; exit}')" player="$(ps x | awk '!(/awk|Helper|Cache/) && /mpd|cmus|mocp|spotify|Google Play|iTunes.app|rhythmbox|banshee|amarok|deadbeef|audacious/ {printf $5 " " $6; exit}')"
@ -1250,7 +1250,7 @@ getsong() {
# Resolution {{{ # Resolution {{{
getresolution() { get_resolution() {
case "$os" in case "$os" in
"Linux" | "BSD" | "Solaris" | "GNU") "Linux" | "BSD" | "Solaris" | "GNU")
if type -p xrandr >/dev/null; then if type -p xrandr >/dev/null; then
@ -1313,7 +1313,7 @@ getresolution() {
# Theme/Icons/Font {{{ # Theme/Icons/Font {{{
getstyle() { get_style() {
# Fix weird output when the function # Fix weird output when the function
# is run multiple times. # is run multiple times.
unset gtk2theme gtk3theme theme path unset gtk2theme gtk3theme theme path
@ -1346,11 +1346,11 @@ getstyle() {
if [[ -n "$DISPLAY" && "$os" != "Mac OS X" ]]; then if [[ -n "$DISPLAY" && "$os" != "Mac OS X" ]]; then
# Get DE if user has disabled the function. # Get DE if user has disabled the function.
[[ -z "$de" ]] && getde [[ -z "$de" ]] && get_de
case "$de" in case "$de" in
"KDE"*) "KDE"*)
kdeconfigdir kde_config_dir
if [[ -f "${kde_config_dir}/share/config/kdeglobals" ]]; then if [[ -f "${kde_config_dir}/share/config/kdeglobals" ]]; then
kde_config_file="${kde_config_dir}/share/config/kdeglobals" kde_config_file="${kde_config_dir}/share/config/kdeglobals"
@ -1470,17 +1470,17 @@ getstyle() {
fi fi
} }
gettheme() { get_theme() {
getstyle theme get_style theme
} }
geticons() { get_icons() {
getstyle icons get_style icons
icons="$theme" icons="$theme"
} }
getfont() { get_font() {
getstyle font get_style font
font="$theme" font="$theme"
} }
@ -1488,7 +1488,7 @@ getfont() {
# Terminal Emulator {{{ # Terminal Emulator {{{
getterm() { get_term() {
# Check $PPID for terminal emulator. # Check $PPID for terminal emulator.
case "$os" in case "$os" in
"Mac OS X") "Mac OS X")
@ -1524,7 +1524,7 @@ getterm() {
esac esac
case "${name// }" in case "${name// }" in
"${SHELL/*\/}" | *"sh" | "tmux"* | "screen") getterm "$parent" ;; "${SHELL/*\/}" | *"sh" | "tmux"* | "screen") get_term "$parent" ;;
"login"* | *"Login"* | "init") term="$(tty)" ;; "login"* | *"Login"* | "init") term="$(tty)" ;;
"ruby" | "1" | "systemd" | "sshd"* | "python"* | "USER"*"PID"*) unset term ;; "ruby" | "1" | "systemd" | "sshd"* | "python"* | "USER"*"PID"*) unset term ;;
"gnome-terminal-") term="gnome-terminal" ;; "gnome-terminal-") term="gnome-terminal" ;;
@ -1536,62 +1536,62 @@ getterm() {
# Terminal Emulator Font {{{ # Terminal Emulator Font {{{
gettermfont() { get_term_font() {
[[ -z "$term" ]] && getterm [[ -z "$term" ]] && get_term
case "$term" in case "$term" in
"urxvt" | "urxvtd" | "xterm") "urxvt" | "urxvtd" | "xterm")
termfont="$(grep -i -F "${term/d}*font" <<< "$(xrdb -query)")" term_font="$(grep -i -F "${term/d}*font" <<< "$(xrdb -query)")"
termfont="${termfont/*font:}" term_font="${term_font/*font:}"
termfont="$(trim "$termfont")" term_font="$(trim "$term_font")"
# Xresources has two different font syntax, this checks which # Xresources has two different font syntax, this checks which
# one is in use and formats it accordingly. # one is in use and formats it accordingly.
case "$termfont" in case "$term_font" in
*"xft:"*) *"xft:"*)
termfont="${termfont/xft:}" term_font="${term_font/xft:}"
termfont="${termfont/:*}" term_font="${term_font/:*}"
;; ;;
"-"*) termfont="$(awk -F '\\-' '{printf $3}' <<< "$termfont")" ;; "-"*) term_font="$(awk -F '\\-' '{printf $3}' <<< "$term_font")" ;;
esac esac
;; ;;
"xfce4-terminal") "xfce4-terminal")
termfont="$(awk -F '=' '/^FontName/ {a=$2} END{print a}' "${XDG_CONFIG_HOME}/xfce4/terminal/terminalrc")" term_font="$(awk -F '=' '/^FontName/ {a=$2} END{print a}' "${XDG_CONFIG_HOME}/xfce4/terminal/terminalrc")"
;; ;;
"termite") "termite")
termfont="$(awk -F '= ' '/^font/ {a=$2} END{print a}' "${XDG_CONFIG_HOME}/termite/config")" term_font="$(awk -F '= ' '/^font/ {a=$2} END{print a}' "${XDG_CONFIG_HOME}/termite/config")"
;; ;;
"mintty") "mintty")
termfont="$(awk -F '=' '!/^($|#)/ && /Font/ {printf $2; exit}' "${HOME}/.minttyrc")" term_font="$(awk -F '=' '!/^($|#)/ && /Font/ {printf $2; exit}' "${HOME}/.minttyrc")"
;; ;;
"Apple_Terminal") "Apple_Terminal")
termfont="$(osascript -e 'tell application "Terminal" to font name of window frontmost')" term_font="$(osascript -e 'tell application "Terminal" to font name of window frontmost')"
;; ;;
"terminology") "terminology")
termfont="$(strings "${XDG_CONFIG_HOME}/terminology/config/standard/base.cfg" | awk '/^font\.name$/{print a}{a=$0}')" term_font="$(strings "${XDG_CONFIG_HOME}/terminology/config/standard/base.cfg" | awk '/^font\.name$/{print a}{a=$0}')"
termfont="${termfont/.pcf}" term_font="${term_font/.pcf}"
termfont="${termfont/:*}" term_font="${term_font/:*}"
;; ;;
"Hyper"*) "Hyper"*)
termfont="$(awk -F "," '/fontFamily/ {a=$1} END{print a}' "${HOME}/.hyper.js" | awk -F "'" '{a=$2} END{print a}')" term_font="$(awk -F "," '/fontFamily/ {a=$1} END{print a}' "${HOME}/.hyper.js" | awk -F "'" '{a=$2} END{print a}')"
;; ;;
esac esac
[[ "$version" -ge 4 ]] && termfont="${termfont^}" [[ "$version" -ge 4 ]] && term_font="${term_font^}"
} }
# }}} # }}}
# Disk Usage {{{ # Disk Usage {{{
getdisk() { get_disk() {
# df flags # df flags
case "$os" in case "$os" in
"Linux" | "iPhone OS" | "Windows" | "Solaris" | "GNU") "Linux" | "iPhone OS" | "Windows" | "Solaris" | "GNU")
@ -1656,7 +1656,7 @@ getdisk() {
# Battery Usage {{{ # Battery Usage {{{
getbattery() { get_battery() {
case "$os" in case "$os" in
"Linux") "Linux")
# We use 'prin' here and exit the function early so that we can # We use 'prin' here and exit the function early so that we can
@ -1741,43 +1741,43 @@ getbattery() {
# IP Address {{{ # IP Address {{{
getlocalip() { get_local_ip() {
case "$os" in case "$os" in
"Linux") "Linux")
localip="$(ip route get 1 | awk '{print $NF;exit}')" local_ip="$(ip route get 1 | awk '{print $NF;exit}')"
;; ;;
"Mac OS X" | "iPhone OS") "Mac OS X" | "iPhone OS")
localip="$(ipconfig getifaddr en0)" local_ip="$(ipconfig getifaddr en0)"
[[ -z "$localip" ]] && localip="$(ipconfig getifaddr en1)" [[ -z "$local_ip" ]] && local_ip="$(ipconfig getifaddr en1)"
;; ;;
"BSD" | "Solaris") "BSD" | "Solaris")
localip="$(ifconfig | awk '/broadcast/ {print $2}')" local_ip="$(ifconfig | awk '/broadcast/ {print $2}')"
;; ;;
"Windows") "Windows")
localip="$(ipconfig | awk -F ': ' '/IPv4 Address/ {printf $2}')" local_ip="$(ipconfig | awk -F ': ' '/IPv4 Address/ {printf $2}')"
;; ;;
"Haiku") "Haiku")
localip="$(ifconfig | awk -F ': ' '/Bcast/ {print $2}')" local_ip="$(ifconfig | awk -F ': ' '/Bcast/ {print $2}')"
localip="${localip/', Bcast'}" local_ip="${local_ip/', Bcast'}"
;; ;;
esac esac
} }
getpublicip() { get_public_ip() {
if type -p dig >/dev/null; then if type -p dig >/dev/null; then
publicip="$(dig +time=1 +tries=1 +short myip.opendns.com @resolver1.opendns.com)" public_ip="$(dig +time=1 +tries=1 +short myip.opendns.com @resolver1.opendns.com)"
fi fi
if [[ -z "$publicip" ]] && type -p curl >/dev/null; then if [[ -z "$public_ip" ]] && type -p curl >/dev/null; then
publicip="$(curl --max-time 10 -w '\n' "$public_ip_host")" public_ip="$(curl --max-time 10 -w '\n' "$public_ip_host")"
fi fi
if [[ -z "$publicip" ]] && type -p wget >/dev/null; then if [[ -z "$public_ip" ]] && type -p wget >/dev/null; then
publicip="$(wget -T 10 -qO- "$public_ip_host"; printf "%s")" public_ip="$(wget -T 10 -qO- "$public_ip_host"; printf "%s")"
fi fi
} }
@ -1785,7 +1785,7 @@ getpublicip() {
# Logged In Users {{{ # Logged In Users {{{
getusers() { get_users() {
users="$(who | awk '!seen[$1]++ {printf $1 ", "}')" users="$(who | awk '!seen[$1]++ {printf $1 ", "}')"
users="${users%\,*}" users="${users%\,*}"
} }
@ -1794,7 +1794,7 @@ getusers() {
# Birthday {{{ # Birthday {{{
getbirthday() { get_birthday() {
case "$os" in case "$os" in
"Linux" | "GNU" | "iPhone OS") "Linux" | "GNU" | "iPhone OS")
birthday="$(ls -alct --full-time / | awk '/lost\+found|private/ {printf $6 " " $7}')" birthday="$(ls -alct --full-time / | awk '/lost\+found|private/ {printf $6 " " $7}')"
@ -1867,7 +1867,7 @@ getbirthday() {
# Terminal colors {{{ # Terminal colors {{{
getcols() { get_cols() {
if [[ "$color_blocks" == "on" ]]; then if [[ "$color_blocks" == "on" ]]; then
# Convert the width to space chars. # Convert the width to space chars.
block_width="$(printf "%${block_width}s")" block_width="$(printf "%${block_width}s")"
@ -1904,7 +1904,7 @@ getcols() {
# Wallpaper {{{ # Wallpaper {{{
getwallpaper() { get_wallpaper() {
case "$os" in case "$os" in
"Linux" | "BSD") "Linux" | "BSD")
if type -p feh >/dev/null && [[ -f "$HOME/.fehbg" ]]; then if type -p feh >/dev/null && [[ -f "$HOME/.fehbg" ]]; then
@ -1915,7 +1915,7 @@ getwallpaper() {
elif type -p gsettings >/dev/null; then elif type -p gsettings >/dev/null; then
# Get DE if user has disabled the function. # Get DE if user has disabled the function.
[[ -z "$de" ]] && getde [[ -z "$de" ]] && get_de
case "$de" in case "$de" in
"MATE"*) img="$(gsettings get org.mate.background picture-filename)" ;; "MATE"*) img="$(gsettings get org.mate.background picture-filename)" ;;
@ -1960,7 +1960,7 @@ getwallpaper() {
# Ascii {{{ # Ascii {{{
getascii() { get_ascii() {
if [[ ! -f "$ascii" || "$ascii" == "distro" ]]; then if [[ ! -f "$ascii" || "$ascii" == "distro" ]]; then
# Error message # Error message
[[ "$ascii" != "distro" ]] && \ [[ "$ascii" != "distro" ]] && \
@ -1988,7 +1988,7 @@ getascii() {
ascii="/data/data/com.termux/files/usr/share/neofetch/ascii/distro/${ascii/ *}" ascii="/data/data/com.termux/files/usr/share/neofetch/ascii/distro/${ascii/ *}"
else else
getscriptdir 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
@ -2003,7 +2003,7 @@ getascii() {
fi fi
# Set locale to get correct padding # Set locale to get correct padding
export LC_ALL="$SYS_LOCALE" export LC_ALL="$sys_locale"
# Turn file into variable # Turn file into variable
while IFS=$'\n' read -r line 2>/dev/null; do while IFS=$'\n' read -r line 2>/dev/null; do
@ -2036,13 +2036,13 @@ getascii() {
# Image {{{ # Image {{{
getimage() { get_image() {
# Fallback to ascii mode if imagemagick isn't installed. # Fallback to ascii mode if imagemagick isn't installed.
type -p convert >/dev/null 2>&1 || image="ascii" type -p convert >/dev/null 2>&1 || image="ascii"
case "$image" in case "$image" in
"wall") getwallpaper 2>/dev/null ;; "wall") get_wallpaper 2>/dev/null ;;
"ascii") getascii; return ;; "ascii") get_ascii; return ;;
*) *)
if [[ -d "$image" ]]; then if [[ -d "$image" ]]; then
files=("${image%/}"/*.{png,jpg,jpeg}) files=("${image%/}"/*.{png,jpg,jpeg})
@ -2113,7 +2113,7 @@ getimage() {
# If $img isn't a file fallback to ascii mode. # If $img isn't a file fallback to ascii mode.
if [[ ! -f "$img" || -z "$term_width" || "$term_width" -le 10 ]]; then if [[ ! -f "$img" || -z "$term_width" || "$term_width" -le 10 ]]; then
image="ascii" image="ascii"
getascii get_ascii
# Error messages # Error messages
[[ ! -f "$img" ]] && err "Image: \$img, isn't a file, falling back to ascii mode." [[ ! -f "$img" ]] && err "Image: \$img, isn't a file, falling back to ascii mode."
@ -2241,7 +2241,7 @@ getimage() {
# Find w3m-img {{{ # Find w3m-img {{{
# Find w3mimgdisplay automatically # Find w3mimgdisplay automatically
getw3m_img_path() { get_w3m_img_path() {
if [[ -x "$w3m_img_path" ]]; then if [[ -x "$w3m_img_path" ]]; then
return return
@ -2267,7 +2267,7 @@ getw3m_img_path() {
# Display image {{{ # Display image {{{
displayimage() { display_image() {
if [[ "$image" != "ascii" ]]; then if [[ "$image" != "ascii" ]]; then
case "$image_backend" in case "$image_backend" in
"w3m") "w3m")
@ -2293,7 +2293,7 @@ displayimage() {
# Get image backend {{{ # Get image backend {{{
getimagebackend() { get_image_backend() {
if [[ -n "$ITERM_PROFILE" ]]; then if [[ -n "$ITERM_PROFILE" ]]; then
image_backend="iterm2" image_backend="iterm2"
@ -2309,7 +2309,7 @@ getimagebackend() {
# Screenshot {{{ # Screenshot {{{
takescrot() { take_scrot() {
$scrot_cmd "${scrot_dir}${scrot_name}" $scrot_cmd "${scrot_dir}${scrot_name}"
[[ "$scrot_upload" == "on" ]] && scrot_upload [[ "$scrot_upload" == "on" ]] && scrot_upload
} }
@ -2356,7 +2356,7 @@ info() {
subtitle="$1" subtitle="$1"
# Call the function and update variable # Call the function and update variable
"get${2:-$1}" 2>/dev/null "get_${2:-$1}" 2>/dev/null
output="${2:-$1}" output="${2:-$1}"
# Trim whitespace # Trim whitespace
@ -2443,7 +2443,7 @@ prin() {
# Underline {{{ # Underline {{{
getunderline() { get_underline() {
if [[ "$underline_enabled" == "on" ]]; then if [[ "$underline_enabled" == "on" ]]; then
underline="$(printf %"$length"s)" underline="$(printf %"$length"s)"
underline="${underline// /$underline_char}" underline="${underline// /$underline_char}"
@ -2708,8 +2708,8 @@ bold() {
# Linebreak {{{ # Linebreak {{{
getlinebreak() { get_line_break() {
linebreak=" " line_break=" "
# Calculate info height # Calculate info height
info_height="$((info_height+=1))" info_height="$((info_height+=1))"
@ -2751,7 +2751,7 @@ err() {
# Check for old flags {{{ # Check for old flags {{{
checkoldflags() { check_old_flags() {
[[ -n "$osx_buildversion" ]] && err "Config: \$osx_buildversion is deprecated, use \$distro_shorthand instead." [[ -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 "$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." [[ -n "$progress_char" ]] && err "Config: \$progress_char is deprecated, use \$progress_char_elapsed and \$progress_char_total instead."
@ -2762,7 +2762,7 @@ checkoldflags() {
# Get script directory {{{ # Get script directory {{{
getscriptdir() { get_script_dir() {
[[ "$script_dir" ]] && return [[ "$script_dir" ]] && return
# Use $0 to get the script's physical path. # Use $0 to get the script's physical path.
@ -2784,7 +2784,7 @@ getscriptdir() {
# Source default config {{{ # Source default config {{{
getdefaultconfig() { get_default_config() {
if [[ -f "/usr/share/neofetch/config" ]]; then if [[ -f "/usr/share/neofetch/config" ]]; then
default_config="/usr/share/neofetch/config" default_config="/usr/share/neofetch/config"
@ -2795,7 +2795,7 @@ getdefaultconfig() {
default_config="/data/data/com.termux/files/usr/share/neofetch/config" default_config="/data/data/com.termux/files/usr/share/neofetch/config"
else else
getscriptdir get_script_dir
default_config="${script_dir}/config/config" default_config="${script_dir}/config/config"
travis_config="${script_dir}/config/travis" travis_config="${script_dir}/config/travis"
fi fi
@ -2811,7 +2811,7 @@ getdefaultconfig() {
# Source config {{{ # Source config {{{
getuserconfig() { 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"
@ -2839,7 +2839,7 @@ getuserconfig() {
config_file="$XDG_CONFIG_HOME/neofetch/config" config_file="$XDG_CONFIG_HOME/neofetch/config"
else else
getscriptdir get_script_dir
cp "$script_dir/config/config" "$XDG_CONFIG_HOME/neofetch" cp "$script_dir/config/config" "$XDG_CONFIG_HOME/neofetch"
config_file="$XDG_CONFIG_HOME/neofetch/config" config_file="$XDG_CONFIG_HOME/neofetch/config"
@ -2887,8 +2887,11 @@ cache() {
# KDE config directory {{{ # KDE config directory {{{
kdeconfigdir() { kde_config_dir() {
if [[ -n "$KDE_CONFIG_DIR" ]]; then if [[ "$kde_config_dir" ]]; then
return
elif [[ -n "$KDE_CONFIG_DIR" ]]; then
kde_config_dir="$KDE_CONFIG_DIR" kde_config_dir="$KDE_CONFIG_DIR"
elif type -p kde5-config >/dev/null 2>&1; then elif type -p kde5-config >/dev/null 2>&1; then
@ -2915,8 +2918,8 @@ kdeconfigdir() {
# Note: This issue only seems to affect # Note: This issue only seems to affect
# URxvt. # URxvt.
gettermpadding() { get_term_padding() {
[[ -z "$term" ]] && getterm [[ -z "$term" ]] && get_term
case "$term" in case "$term" in
"URxvt"*) "URxvt"*)
@ -2930,10 +2933,10 @@ gettermpadding() {
# Dynamic prompt location {{{ # Dynamic prompt location {{{
dynamicprompt() { dynamic_prompt() {
# Calculate image height in terminal cells. # Calculate image height in terminal cells.
if [[ "$image" != "ascii" ]]; then if [[ "$image" != "ascii" ]]; then
gettermpadding 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
@ -2974,6 +2977,24 @@ scrot_args() {
# }}} # }}}
# Deprecated functions {{{
# Neofetch 2.0 changed the names of a few variables.
# This function adds backwards compatibility for the
# old variable names.
old_functions() {
if type printinfo >/dev/null 2>&1; then
print_info() { printinfo ; }
get_wmtheme() { get_wm_theme; wmtheme="$wm_theme"; }
get_termfont() { get_term_font; termfont="$term_font"; }
get_localip() { get_local_ip; localip="$local_ip"; }
get_publicip() { get_public_ip; publicip="$public_ip"; }
get_linebreak() { get_line_break; linebreak="$line_break"; }
fi
}
# }}}
# }}} # }}}
# Usage {{{ # Usage {{{
@ -3106,7 +3127,7 @@ exit 1
# Args {{{ # Args {{{
getargs() { get_args() {
# Check the commandline flags early for '--config none/off' # Check the commandline flags early for '--config none/off'
case "$@" in case "$@" in
*"--config off"* | *'--config "off"'* | *"--config 'off'"* | \ *"--config off"* | *'--config "off"'* | *"--config 'off'"* | \
@ -3118,7 +3139,7 @@ getargs() {
*"--config"*) config="off" ;; *"--config"*) config="off" ;;
esac esac
[[ "${config:-on}" == "on" ]] && getuserconfig 2>/dev/null [[ "${config:-on}" == "on" ]] && get_user_config 2>/dev/null
while [[ "$1" ]]; do while [[ "$1" ]]; do
case "$1" in case "$1" in
@ -3149,7 +3170,7 @@ getargs() {
case "$func" in case "$func" in
"--disable") continue ;; "--disable") continue ;;
"-"*) return ;; "-"*) return ;;
*) unset -f "get$func" ;; *) unset -f "get_$func" ;;
esac esac
done done
;; ;;
@ -3241,7 +3262,7 @@ getargs() {
--ascii_bold) ascii_bold="$2" ;; --ascii_bold) ascii_bold="$2" ;;
--logo | -L) --logo | -L)
image="ascii" image="ascii"
printinfo() { info linebreak; } print_info() { info line_break; }
;; ;;
@ -3261,13 +3282,13 @@ getargs() {
--config) --config)
case "$2" in case "$2" in
"none" | "off") config="off" ;; "none" | "off") config="off" ;;
*) config_file="$2"; config="on"; getuserconfig 2>/dev/null ;; *) config_file="$2"; config="on"; get_user_config 2>/dev/null ;;
esac esac
;; ;;
-v) verbose="on" ;; -v) verbose="on" ;;
-vv) set -x; verbose="on" ;; -vv) set -x; verbose="on" ;;
--help) usage ;; --help) usage ;;
--version) printf "%s\n" "Neofetch 1.9.1"; exit ;; --version) printf "%s\n" "Neofetch 2.0"; exit ;;
esac esac
shift shift
@ -3279,11 +3300,11 @@ getargs() {
# Call Functions and Finish Up {{{ # Call Functions and Finish Up {{{
main() { main() {
getos get_os
getdefaultconfig 2>/dev/null get_default_config 2>/dev/null
checkoldflags check_old_flags
getargs "$@" get_args "$@"
getdistro get_distro
# Get colors and bold # Get colors and bold
bold bold
@ -3300,18 +3321,18 @@ main() {
# Display the image # Display the image
if [[ "$image" != "off" ]]; then if [[ "$image" != "off" ]]; then
getimagebackend get_image_backend
# Find w3mimgdisplay # Find w3mimgdisplay
[[ "$image_backend" == "w3m" ]] && \ [[ "$image_backend" == "w3m" ]] && \
[[ "$image" != "ascii" ]] && \ [[ "$image" != "ascii" ]] && \
getw3m_img_path get_w3m_img_path
# Get the image src # Get the image src
getimage get_image
# Display the image if enabled # Display the image if enabled
displayimage display_image
# Set cursor position next to ascii art # Set cursor position next to ascii art
printf "\033[$((${lines:-0} - ${prompt_loc:-0}))A" printf "\033[$((${lines:-0} - ${prompt_loc:-0}))A"
@ -3321,21 +3342,22 @@ main() {
fi fi
# Print the info # Print the info
printinfo 2>/dev/null old_functions
print_info 2>/dev/null
# Prompt calculation # Prompt calculation
if [[ "$image" != "off" ]]; then if [[ "$image" != "off" ]]; then
dynamicprompt 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" ]] && displayimage [[ "$image_backend" == "w3m" ]] && display_image
fi fi
# Re-enable line wrap # Re-enable line wrap
printf "%b" "\033[?7h" printf "%b" "\033[?7h"
[[ "$scrot" == "on" ]] && takescrot [[ "$scrot" == "on" ]] && take_scrot
# Show error messages # Show error messages
[[ "$verbose" == "on" ]] && printf "%b" "$err" [[ "$verbose" == "on" ]] && printf "%b" "$err"