General: Add a new function called cache_uname

This commit is contained in:
Dylan Araps 2016-11-11 16:51:23 +11:00
commit 5ca6d69d28
5 changed files with 107 additions and 333 deletions

View file

@ -14,6 +14,8 @@
- Removed all traces of `eval` from neofetch. - Removed all traces of `eval` from neofetch.
- All functions/variables now follow the same naming scheme. `example_func_name` - All functions/variables now follow the same naming scheme. `example_func_name`
- Convert math tests to correct syntax. - Convert math tests to correct syntax.
- Removed all vim fold markers and stopped enforcing folding for vim users.
- See [#431](https://github.com/dylanaraps/neofetch/pull/431)
## Operating System ## Operating System
@ -61,3 +63,7 @@
**CPU Usage**<br \> **CPU Usage**<br \>
- [iOS] Fixed CPU usage. - [iOS] Fixed CPU usage.
**Shell**<br \>
- [bash] Simplify bash version.

View file

@ -1,5 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# vim:fdm=marker
# #
# Neofetch config file # Neofetch config file
# https://github.com/dylanaraps/neofetch # https://github.com/dylanaraps/neofetch
@ -8,10 +7,7 @@
export LC_ALL=C export LC_ALL=C
export LANG=C export LANG=C
# Info Options {{{
# 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
print_info() { print_info() {
@ -54,15 +50,18 @@ print_info() {
# Kernel # Kernel
# Show more kernel info
# Shorten the output of the kernel function
# --kernel_shorthand on, off # --kernel_shorthand on, off
kernel_shorthand="on" kernel_shorthand="on"
# Distro # Distro
# Shorten the output of distro (tiny, on, off)
# Shorten the output of the distro function
# NOTE: This is only possible on Linux, macOS, and Solaris # NOTE: This is only possible on Linux, macOS, and Solaris
# --distro_shorthand on, off, tiny
distro_shorthand="off" distro_shorthand="off"
# Show 'x86_64' and 'x86' in 'Distro:' output. # Show 'x86_64' and 'x86' in 'Distro:' output.
@ -72,6 +71,7 @@ os_arch="on"
# Uptime # Uptime
# Shorten the output of the uptime function # Shorten the output of the uptime function
# --uptime_shorthand tiny, on, off # --uptime_shorthand tiny, on, off
uptime_shorthand="off" uptime_shorthand="off"
@ -79,25 +79,26 @@ uptime_shorthand="off"
# Shell # Shell
# Show the path to $SHELL # Show the path to $SHELL
# --shell_path on, off # --shell_path on, off
shell_path="off" shell_path="off"
# Show $SHELL's version # Show $SHELL version
# --shell_version on, off # --shell_version on, off
shell_version="on" shell_version="on"
# CPU # CPU
# CPU speed type # CPU speed type
# Only works on Linux with cpufreq. # Only works on Linux with cpufreq.
# --speed_type current, min, max, bios, # --speed_type current, min, max, bios,
# scaling_current, scaling_min, scaling_max # scaling_current, scaling_min, scaling_max
speed_type="max" speed_type="max"
# CPU Shorthand # Shorten the output of the CPU function
# Set shorthand setting
# --cpu_shorthand name, speed, tiny, on, off # --cpu_shorthand name, speed, tiny, on, off
cpu_shorthand="off" cpu_shorthand="off"
@ -115,19 +116,20 @@ cpu_speed="on"
# Display CPU cores in output # Display CPU cores in output
# Logical: All virtual cores # Logical: All virtual cores
# Physical: All physical cores # Physical: All physical cores
# --cpu_cores logical, physical, off
# Note: 'physical' doesn't work on BSD. # Note: 'physical' doesn't work on BSD.
# --cpu_cores logical, physical, off
cpu_cores="logical" cpu_cores="logical"
# CPU Temperature # CPU Temperature
# Hide/Show CPU temperature. # Hide/Show CPU temperature.
# --cpu_temp on, off
# Note: Only works on Linux. # Note: Only works on Linux.
# --cpu_temp on, off
cpu_temp="off" cpu_temp="off"
# GPU # GPU
# Enable/Disable GPU Brand # Enable/Disable GPU Brand
# --gpu_brand on, off # --gpu_brand on, off
gpu_brand="on" gpu_brand="on"
@ -135,6 +137,7 @@ gpu_brand="on"
# Resolution # Resolution
# Display refresh rate next to each monitor # Display refresh rate next to each monitor
# Unsupported on Windows # Unsupported on Windows
# --refresh_rate on, off # --refresh_rate on, off
@ -143,6 +146,7 @@ refresh_rate="off"
# Gtk Theme / Icons # Gtk Theme / Icons
# Shorten output (Hide [GTK2] etc) # Shorten output (Hide [GTK2] etc)
# --gtk_shorthand on, off # --gtk_shorthand on, off
gtk_shorthand="off" gtk_shorthand="off"
@ -159,6 +163,7 @@ gtk3="on"
# IP Address # IP Address
# Website to ping for the public IP # Website to ping for the public IP
# --ip_host url # --ip_host url
public_ip_host="http://ident.me" public_ip_host="http://ident.me"
@ -166,6 +171,7 @@ public_ip_host="http://ident.me"
# Song # Song
# Print the Artist and Title on seperate lines # Print the Artist and Title on seperate lines
# --song_shorthand on, off # --song_shorthand on, off
song_shorthand="off" song_shorthand="off"
@ -173,6 +179,7 @@ song_shorthand="off"
# Birthday # Birthday
# Whether to show a long pretty output # Whether to show a long pretty output
# or a shortened one # or a shortened one
# NOTE: Long pretty output doesn't work on OpenBSD or NetBSD. # NOTE: Long pretty output doesn't work on OpenBSD or NetBSD.
@ -188,9 +195,7 @@ birthday_time="on"
birthday_format="+%a %d %b %Y %l:%M %p" birthday_format="+%a %d %b %Y %l:%M %p"
# }}} # Text Colors
# Text Colors {{{
# Text Colors # Text Colors
@ -203,9 +208,7 @@ birthday_format="+%a %d %b %Y %l:%M %p"
colors=(distro) colors=(distro)
# }}} # Text Options
# Text Options {{{
# Toggle bold text # Toggle bold text
@ -221,9 +224,7 @@ underline_enabled="on"
underline_char="-" underline_char="-"
# }}} # Color Blocks
# Color Blocks {{{
# Color block range # Color block range
@ -244,9 +245,7 @@ block_width=3
block_height=1 block_height=1
# }}} # Progress Bars
# Progress Bars {{{
# Progress bar character # Progress bar character
@ -284,9 +283,7 @@ battery_display="off"
disk_display="off" disk_display="off"
# }}} # Image Options
# Image Options {{{
# Image Source # Image Source
@ -345,9 +342,7 @@ xoffset=0
background_color= background_color=
# }}} # Ascii Options
# Ascii Options {{{
# Default ascii image to use # Default ascii image to use
@ -383,9 +378,7 @@ ascii_logo_size="normal"
ascii_bold="on" ascii_bold="on"
# }}} # Scrot Options
# Scrot Options {{{
# Whether or not to always take a screenshot # Whether or not to always take a screenshot
@ -417,9 +410,7 @@ image_host="imgur"
imgur_client_id="0e8b44d15e9fc95" imgur_client_id="0e8b44d15e9fc95"
# }}} # Config Options
# Config Options {{{
# Enable/Disable config file # Enable/Disable config file
@ -429,6 +420,3 @@ config="on"
# Path to custom config file location # Path to custom config file location
# --config path/to/config # --config path/to/config
config_file="${XDG_CONFIG_HOME:-${HOME}/.config}/neofetch/config" config_file="${XDG_CONFIG_HOME:-${HOME}/.config}/neofetch/config"
# }}}

View file

@ -1,5 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# vim:fdm=marker
# #
# Neofetch config file for travis.ci # Neofetch config file for travis.ci
# https://github.com/dylanaraps/neofetch # https://github.com/dylanaraps/neofetch

367
neofetch
View file

@ -1,6 +1,6 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# set -x # set -x
# vim: fdm=marker:noai:ts=4:sw=4:expandtab # vim: noai:ts=4:sw=4:expandtab
# #
# Neofetch: Simple system information script. # Neofetch: Simple system information script.
# https://github.com/dylanaraps/neofetch # https://github.com/dylanaraps/neofetch
@ -19,15 +19,10 @@ export LANG=C
# Set no case match. # Set no case match.
shopt -s nocasematch shopt -s nocasematch
# Cache uname output for use later in the script. # DETECT INFORMATION
uname=($(uname -srm))
# Gather Info {{{
# Operating System {{{
get_os() { get_os() {
case "${uname[0]}" in case "$kernel_name" in
"Linux") os="Linux" ;; "Linux") os="Linux" ;;
"Darwin") os="$(sw_vers -productName)" ;; "Darwin") os="$(sw_vers -productName)" ;;
*"BSD" | "DragonFly" | "Bitrig") os="BSD" ;; *"BSD" | "DragonFly" | "Bitrig") os="BSD" ;;
@ -35,14 +30,10 @@ get_os() {
"SunOS") os="Solaris" ;; "SunOS") os="Solaris" ;;
"Haiku") os="Haiku" ;; "Haiku") os="Haiku" ;;
"GNU"*) os="GNU" ;; "GNU"*) os="GNU" ;;
*) printf "%s\n" "Unknown OS detected: ${uname[0]}"; exit 1 ;; *) printf "%s\n" "Unknown OS detected: $kernel_name"; exit 1 ;;
esac esac
} }
# }}}
# Model {{{
get_model() { get_model() {
case "$os" in case "$os" in
"Linux") "Linux")
@ -65,7 +56,7 @@ get_model() {
"Mac OS X") model="$(sysctl -n hw.model)" ;; "Mac OS X") model="$(sysctl -n hw.model)" ;;
"iPhone OS") "iPhone OS")
case "${uname[2]}" in case "$machine_arch" in
"iPad1,1") model="iPad" ;; "iPad1,1") model="iPad" ;;
"iPad2,"[1-4]) model="iPad2" ;; "iPad2,"[1-4]) model="iPad2" ;;
"iPad3,"[1-3]) model="iPad3" ;; "iPad3,"[1-3]) model="iPad3" ;;
@ -121,17 +112,13 @@ get_model() {
esac esac
} }
# }}}
# Distro {{{
get_distro() { get_distro() {
[[ "$distro" ]] && return [[ "$distro" ]] && return
case "$os" in case "$os" in
"Linux" | "GNU") "Linux" | "GNU")
if grep -q -F 'Microsoft' /proc/version >/dev/null || \ if grep -q -F 'Microsoft' /proc/version || \
grep -q -F 'Microsoft' /proc/sys/kernel/osrelease >/dev/null; then grep -q -F 'Microsoft' /proc/sys/kernel/osrelease; then
case "$distro_shorthand" in case "$distro_shorthand" in
"on") distro="$(lsb_release -sir) [Windows 10]" ;; "on") distro="$(lsb_release -sir) [Windows 10]" ;;
"tiny") distro="Windows 10" ;; "tiny") distro="Windows 10" ;;
@ -227,8 +214,8 @@ get_distro() {
"BSD") "BSD")
case "$distro_shorthand" in case "$distro_shorthand" in
"tiny" | "on") distro="${uname[0]}" ;; "tiny" | "on") distro="$kernel_name" ;;
*) distro="${uname[0]} ${uname[1]}" ;; *) distro="$kernel_name $kernel_version" ;;
esac esac
distro="${distro/DragonFly/DragonFlyBSD}" distro="${distro/DragonFly/DragonFlyBSD}"
@ -261,43 +248,31 @@ get_distro() {
# Get architecture # Get architecture
[[ "$os_arch" == "on" ]] && \ [[ "$os_arch" == "on" ]] && \
distro+=" ${uname[2]}" distro+=" ${HOSTTYPE:-${machine_arch}}"
[[ "${ascii_distro:-auto}" == "auto" ]] && \ [[ "${ascii_distro:-auto}" == "auto" ]] && \
ascii_distro="$(trim "$distro")" ascii_distro="$(trim "$distro")"
} }
# }}}
# Title {{{
get_title() { get_title() {
title="${USER:-$(whoami || printf "%s" "${HOME/*\/}")}@${HOSTNAME:-$(hostname)}" title="${USER:-$(whoami || printf "%s" "${HOME/*\/}")}@${HOSTNAME:-$(hostname)}"
} }
# }}}
# Kernel {{{
get_kernel() { get_kernel() {
case "$kernel_shorthand" in case "$kernel_shorthand" in
"on") kernel="${uname[1]}" ;; "on") kernel="$kernel_version" ;;
"off") kernel="${uname[0]} ${uname[1]}" ;; "off") kernel="$kernel_name $kernel_version" ;;
esac esac
# Hardcode kernel settings in BSDs # Hardcode kernel settings in BSDs
if [[ "$os" == "BSD" && ! "$distro" =~ (PacBSD|PCBSD) ]]; then if [[ "$os" == "BSD" && ! "$distro" =~ (PacBSD|PCBSD) ]]; then
case "$distro_shorthand" in case "$distro_shorthand" in
"on" | "tiny") kernel="${uname[1]}" ;; "on" | "tiny") kernel="$kernel_version" ;;
*) unset kernel ;; *) unset kernel ;;
esac esac
fi fi
} }
# }}}
# Uptime {{{
get_uptime() { 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
@ -377,10 +352,6 @@ get_uptime() {
esac esac
} }
# }}}
# Package Count {{{
get_packages() { get_packages() {
case "$os" in case "$os" in
"Linux" | "iPhone OS" | "Solaris" | "GNU") "Linux" | "iPhone OS" | "Solaris" | "GNU")
@ -477,10 +448,6 @@ get_packages() {
(("$packages" == "0")) && unset packages (("$packages" == "0")) && unset packages
} }
# }}}
# Shell {{{
get_shell() { get_shell() {
case "$shell_path" in case "$shell_path" in
"on") shell="$SHELL" ;; "on") shell="$SHELL" ;;
@ -491,9 +458,7 @@ get_shell() {
shell+=" " shell+=" "
case "${SHELL##*/}" in case "${SHELL##*/}" in
"bash") "bash")
shell+="$(bash --version)" shell+=" ${BASH_VERSION/-*}"
shell="${shell/ *, version}"
shell="${shell/$'\n'*}"
;; ;;
"zsh") "zsh")
@ -520,9 +485,6 @@ get_shell() {
fi fi
} }
# }}}
# Desktop Environment {{{
get_de() { get_de() {
case "$os" in case "$os" in
"Mac OS X") de="Aqua" ;; "Mac OS X") de="Aqua" ;;
@ -553,10 +515,6 @@ get_de() {
fi fi
} }
# }}}
# Window Manager {{{
get_wm() { 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}')"
@ -582,10 +540,6 @@ get_wm() {
fi fi
} }
# }}}
# Window Manager Theme {{{
get_wm_theme() { get_wm_theme() {
[[ -z "$wm" ]] && get_wm [[ -z "$wm" ]] && get_wm
[[ -z "$de" ]] && get_de [[ -z "$de" ]] && get_de
@ -705,10 +659,6 @@ get_wm_theme() {
(("$version" >= 4)) && wm_theme="${wm_theme^}" (("$version" >= 4)) && wm_theme="${wm_theme^}"
} }
# }}}
# CPU {{{
get_cpu() { 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
@ -774,7 +724,7 @@ get_cpu() {
;; ;;
"iPhone OS") "iPhone OS")
case "${uname[2]}" in case "$machine_arch" in
"iPhone1,"[1-2] | "iPod1,1") cpu="Samsung S5L8900 (1) @ 412MHz" ;; "iPhone1,"[1-2] | "iPod1,1") cpu="Samsung S5L8900 (1) @ 412MHz" ;;
"iPhone2,1") cpu="Samsung S5PC100 (1) @ 600MHz" ;; "iPhone2,1") cpu="Samsung S5PC100 (1) @ 600MHz" ;;
"iPhone3,"[1-3] | "iPod4,1") cpu="Apple A4 (1) @ 800MHz" ;; "iPhone3,"[1-3] | "iPod4,1") cpu="Apple A4 (1) @ 800MHz" ;;
@ -898,10 +848,6 @@ get_cpu() {
esac esac
} }
# }}}
# CPU Usage {{{
get_cpu_usage() { get_cpu_usage() {
case "$os" in case "$os" in
"Windows") "Windows")
@ -935,10 +881,6 @@ get_cpu_usage() {
esac esac
} }
# }}}
# GPU {{{
get_gpu() { get_gpu() {
case "$os" in case "$os" in
"Linux" | "GNU") "Linux" | "GNU")
@ -996,7 +938,7 @@ get_gpu() {
;; ;;
"iPhone OS") "iPhone OS")
case "${uname[2]}" in case "$machine_arch" in
"iPhone1,"[1-2]) gpu="PowerVR MBX Lite 3D" ;; "iPhone1,"[1-2]) gpu="PowerVR MBX Lite 3D" ;;
"iPhone5,"[1-4]) gpu="PowerVR SGX543MP3" ;; "iPhone5,"[1-4]) gpu="PowerVR SGX543MP3" ;;
"iPhone8,"[1-4]) gpu="PowerVR GT7600" ;; "iPhone8,"[1-4]) gpu="PowerVR GT7600" ;;
@ -1059,10 +1001,6 @@ get_gpu() {
fi fi
} }
# }}}
# Memory {{{
get_memory() { get_memory() {
case "$os" in case "$os" in
"Linux" | "Windows" | "GNU") "Linux" | "Windows" | "GNU")
@ -1129,10 +1067,6 @@ get_memory() {
esac esac
} }
# }}}
# Song {{{
get_song() { 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}')"
@ -1247,10 +1181,6 @@ get_song() {
fi fi
} }
# }}}
# Resolution {{{
get_resolution() { get_resolution() {
case "$os" in case "$os" in
"Linux" | "BSD" | "Solaris" | "GNU") "Linux" | "BSD" | "Solaris" | "GNU")
@ -1310,10 +1240,6 @@ get_resolution() {
resolution="${resolution%,*}" resolution="${resolution%,*}"
} }
# }}}
# Theme/Icons/Font {{{
get_style() { get_style() {
# Fix weird output when the function # Fix weird output when the function
# is run multiple times. # is run multiple times.
@ -1485,10 +1411,6 @@ get_font() {
font="$theme" font="$theme"
} }
# }}}
# Terminal Emulator {{{
get_term() { get_term() {
# Check $PPID for terminal emulator. # Check $PPID for terminal emulator.
case "$os" in case "$os" in
@ -1533,10 +1455,6 @@ get_term() {
esac esac
} }
# }}}
# Terminal Emulator Font {{{
get_term_font() { get_term_font() {
[[ -z "$term" ]] && get_term [[ -z "$term" ]] && get_term
@ -1588,10 +1506,6 @@ get_term_font() {
(("$version" >= 4)) && term_font="${term_font^}" (("$version" >= 4)) && term_font="${term_font^}"
} }
# }}}
# Disk Usage {{{
get_disk() { get_disk() {
# df flags # df flags
case "$os" in case "$os" in
@ -1653,10 +1567,6 @@ get_disk() {
esac esac
} }
# }}}
# Battery Usage {{{
get_battery() { get_battery() {
case "$os" in case "$os" in
"Linux") "Linux")
@ -1738,10 +1648,6 @@ get_battery() {
esac esac
} }
# }}}
# IP Address {{{
get_local_ip() { get_local_ip() {
case "$os" in case "$os" in
"Linux") "Linux")
@ -1782,19 +1688,11 @@ get_public_ip() {
fi fi
} }
# }}}
# Logged In Users {{{
get_users() { get_users() {
users="$(who | awk '!seen[$1]++ {printf $1 ", "}')" users="$(who | awk '!seen[$1]++ {printf $1 ", "}')"
users="${users%\,*}" users="${users%\,*}"
} }
# }}}
# Birthday {{{
get_birthday() { get_birthday() {
case "$os" in case "$os" in
"Linux" | "GNU" | "iPhone OS") "Linux" | "GNU" | "iPhone OS")
@ -1864,10 +1762,6 @@ get_birthday() {
birthday="${birthday/??:??*}" birthday="${birthday/??:??*}"
} }
# }}}
# Terminal colors {{{
get_cols() { get_cols() {
if [[ "$color_blocks" == "on" ]]; then if [[ "$color_blocks" == "on" ]]; then
# Convert the width to space chars. # Convert the width to space chars.
@ -1897,13 +1791,7 @@ get_cols() {
fi fi
} }
# }}} # IMAGES
# }}}
# Images {{{
# Wallpaper {{{
get_wallpaper() { get_wallpaper() {
case "$os" in case "$os" in
@ -1957,10 +1845,6 @@ get_wallpaper() {
[[ -z "$img" ]] && err "Image: Wallpaper detection failed, falling back to ascii mode." [[ -z "$img" ]] && err "Image: Wallpaper detection failed, falling back to ascii mode."
} }
# }}}
# Ascii {{{
get_ascii() { get_ascii() {
if [[ ! -f "$ascii" || "$ascii" == "distro" ]]; then if [[ ! -f "$ascii" || "$ascii" == "distro" ]]; then
# Error message # Error message
@ -2033,10 +1917,6 @@ get_ascii() {
export LC_ALL=C export LC_ALL=C
} }
# }}}
# Image {{{
get_image() { 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"
@ -2237,11 +2117,6 @@ get_image() {
img="$thumbnail_dir/$imgname" img="$thumbnail_dir/$imgname"
} }
# }}}
# Find w3m-img {{{
# Find w3mimgdisplay automatically
get_w3m_img_path() { get_w3m_img_path() {
if [[ -x "$w3m_img_path" ]]; then if [[ -x "$w3m_img_path" ]]; then
return return
@ -2264,9 +2139,17 @@ get_w3m_img_path() {
fi fi
} }
# }}} get_image_backend() {
if [[ -n "$ITERM_PROFILE" ]]; then
image_backend="iterm2"
# Display image {{{ elif [[ "$(tycat 2>/dev/null)" ]]; then
image_backend="tycat"
else
image_backend="w3m"
fi
}
display_image() { display_image() {
if [[ "$image" != "ascii" ]]; then if [[ "$image" != "ascii" ]]; then
@ -2290,35 +2173,13 @@ display_image() {
fi fi
} }
# }}} # SCREENSHOT
# Get image backend {{{
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
}
# }}}
# Screenshot {{{
take_scrot() { take_scrot() {
$scrot_cmd "${scrot_dir}${scrot_name}" $scrot_cmd "${scrot_dir}${scrot_name}"
[[ "$scrot_upload" == "on" ]] && scrot_upload [[ "$scrot_upload" == "on" ]] && scrot_upload
} }
# }}}
# Screenshot Upload {{{
scrot_upload() { scrot_upload() {
if ! type -p curl >/dev/null 2>&1; then if ! type -p curl >/dev/null 2>&1; then
printf "%s\n" "[!] Install curl to upload images" printf "%s\n" "[!] Install curl to upload images"
@ -2344,13 +2205,18 @@ scrot_upload() {
printf "%s\n" "${image_url:-'[!] Image failed to upload'}" printf "%s\n" "${image_url:-'[!] Image failed to upload'}"
} }
# }}} scrot_args() {
scrot="on"
case "$2" in
"-"* | "") ;;
*)
scrot_name="${2##*/}"
scrot_dir="${2/$scrot_name}"
;;
esac
}
# }}} # TEXT FORMATTING
# Text Formatting {{{
# Info {{{
info() { info() {
# $1 is the subtitle # $1 is the subtitle
@ -2405,10 +2271,6 @@ info() {
fi fi
} }
# }}}
# Prin {{{
prin() { prin() {
string="${1//$'\033[0m'}${2:+: $2}" string="${1//$'\033[0m'}${2:+: $2}"
@ -2440,10 +2302,6 @@ prin() {
prin=1 prin=1
} }
# }}}
# Underline {{{
get_underline() { get_underline() {
if [[ "$underline_enabled" == "on" ]]; then if [[ "$underline_enabled" == "on" ]]; then
underline="$(printf %"$length"s)" underline="$(printf %"$length"s)"
@ -2451,10 +2309,6 @@ get_underline() {
fi fi
} }
# }}}
# Colors {{{
colors() { colors() {
# Reset colors/bold # Reset colors/bold
reset="\033[0m" reset="\033[0m"
@ -2689,10 +2543,6 @@ color() {
esac esac
} }
# }}}
# Bold {{{
bold() { bold() {
case "$ascii_bold" in case "$ascii_bold" in
"on") ascii_bold="\033[1m" ;; "on") ascii_bold="\033[1m" ;;
@ -2705,10 +2555,6 @@ bold() {
esac esac
} }
# }}}
# Linebreak {{{
get_line_break() { get_line_break() {
line_break=" " line_break=" "
@ -2716,42 +2562,29 @@ get_line_break() {
info_height="$((info_height+=1))" info_height="$((info_height+=1))"
} }
# }}}
# Trim whitespace {{{
# When a string is passed to 'echo' all trailing and leading
# whitespace is removed and inside the string multiple spaces are
# condensed into single spaces.
#
# The 'set -f/+f' is here so that 'echo' doesn't cause any expansion
# of special characters.
#
# The whitespace trim doesn't work with multiline strings so we use
# '${1//[[:space:]]/ }' to remove newlines beofre we trim the whitespace.
trim() { trim() {
# When a string is passed to 'echo' all trailing and leading
# whitespace is removed and inside the string multiple spaces are
# condensed into single spaces.
#
# The 'set -f/+f' is here so that 'echo' doesn't cause any expansion
# of special characters.
#
# The whitespace trim doesn't work with multiline strings so we use
# '${1//[[:space:]]/ }' to remove newlines beofre we trim the whitespace.
set -f set -f
builtin echo -E ${1//[[:space:]]/ } builtin echo -E ${1//[[:space:]]/ }
set +f set +f
} }
# }}} # OTHER
# }}}
# Other {{{
# Error {{{
err() { err() {
err+="$(color 1)[!]\033[0m $1 err+="$(color 1)[!]\033[0m $1
" "
} }
# }}}
# Check for old flags {{{
check_old_flags() { 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."
@ -2759,10 +2592,6 @@ check_old_flags() {
[[ "$cpu_cores" == "on" ]] && err "Config: \$cpu_cores='on' is deprecated, use \$cpu_cores='logical|physical|off' instead." [[ "$cpu_cores" == "on" ]] && err "Config: \$cpu_cores='on' is deprecated, use \$cpu_cores='logical|physical|off' instead."
} }
# }}}
# Get script directory {{{
get_script_dir() { get_script_dir() {
[[ "$script_dir" ]] && return [[ "$script_dir" ]] && return
@ -2781,10 +2610,6 @@ get_script_dir() {
script_dir="$(pwd -P)" script_dir="$(pwd -P)"
} }
# }}}
# Source default config {{{
get_default_config() { 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"
@ -2808,10 +2633,6 @@ get_default_config() {
fi fi
} }
# }}}
# Source config {{{
get_user_config() { get_user_config() {
# Check $config_file # Check $config_file
if [[ -f "$config_file" ]]; then if [[ -f "$config_file" ]]; then
@ -2850,10 +2671,6 @@ get_user_config() {
err "Config: Sourced user config ($config_file)" err "Config: Sourced user config ($config_file)"
} }
# }}}
# Progress bars {{{
bar() { bar() {
# Get the values # Get the values
elapsed="$(($1 * progress_length / $2))" elapsed="$(($1 * progress_length / $2))"
@ -2875,19 +2692,11 @@ bar() {
printf "%b\n" "${bar}${info_color}" printf "%b\n" "${bar}${info_color}"
} }
# }}}
# Cache {{{
cache() { cache() {
mkdir -p "$3/neofetch" mkdir -p "$3/neofetch"
echo "${1/*-}=\"$2\"" > "$3/neofetch/${1/*-}" echo "${1/*-}=\"$2\"" > "$3/neofetch/${1/*-}"
} }
# }}}
# KDE config directory {{{
kde_config_dir() { kde_config_dir() {
if [[ "$kde_config_dir" ]]; then if [[ "$kde_config_dir" ]]; then
return return
@ -2906,20 +2715,17 @@ kde_config_dir() {
fi fi
} }
# }}}
# Terminal info {{{
#
# Parse terminal config files to get
# info about padding. Due to how w3m-img
# works padding around the terminal throws
# off the cursor placement calculation in
# specific terminals.
#
# Note: This issue only seems to affect
# URxvt.
get_term_padding() { get_term_padding() {
# Terminal info
#
# Parse terminal config files to get
# info about padding. Due to how w3m-img
# works padding around the terminal throws
# off the cursor placement calculation in
# specific terminals.
#
# Note: This issue only seems to affect
# URxvt.
[[ -z "$term" ]] && get_term [[ -z "$term" ]] && get_term
case "$term" in case "$term" in
@ -2930,10 +2736,6 @@ get_term_padding() {
esac esac
} }
# }}}
# Dynamic prompt location {{{
dynamic_prompt() { dynamic_prompt() {
# Calculate image height in terminal cells. # Calculate image height in terminal cells.
if [[ "$image" != "ascii" ]]; then if [[ "$image" != "ascii" ]]; then
@ -2961,29 +2763,11 @@ dynamic_prompt() {
printf "\n\n\n\n" printf "\n\n\n\n"
} }
# }}}
# Scrot args {{{
scrot_args() {
scrot="on"
case "$2" in
"-"* | "") ;;
*)
scrot_name="${2##*/}"
scrot_dir="${2/$scrot_name}"
;;
esac
}
# }}}
# Deprecated functions {{{
# Neofetch 2.0 changed the names of a few variables.
# This function adds backwards compatibility for the
# old variable names.
old_functions() { old_functions() {
# Deprecated functions
# Neofetch 2.0 changed the names of a few variables.
# This function adds backwards compatibility for the
# old variable names.
if type printinfo >/dev/null 2>&1; then if type printinfo >/dev/null 2>&1; then
print_info() { printinfo ; } print_info() { printinfo ; }
get_wmtheme() { get_wm_theme; wmtheme="$wm_theme"; } get_wmtheme() { get_wm_theme; wmtheme="$wm_theme"; }
@ -2994,11 +2778,17 @@ old_functions() {
fi fi
} }
# }}} cache_uname() {
# Cache the output of uname so we don't
# have to spawn it multiple times.
uname=($(uname -srm))
# }}} kernel_name="${uname[0]}"
kernel_version="${uname[1]}"
machine_arch="${uname[2]}"
}
# Usage {{{ # FINISH UP
usage() { printf "%s" " usage() { printf "%s" "
NEOFETCH NEOFETCH
@ -3124,10 +2914,6 @@ usage() { printf "%s" "
exit 1 exit 1
} }
# }}}
# Args {{{
get_args() { get_args() {
# Check the commandline flags early for '--config none/off' # Check the commandline flags early for '--config none/off'
case "$@" in case "$@" in
@ -3296,11 +3082,8 @@ get_args() {
done done
} }
# }}}
# Call Functions and Finish Up {{{
main() { main() {
cache_uname
get_os get_os
get_default_config 2>/dev/null get_default_config 2>/dev/null
check_old_flags check_old_flags
@ -3368,5 +3151,3 @@ main() {
} }
main "$@" main "$@"
# }}}

View file

@ -1,4 +1,4 @@
.TH NEOFETCH "1" "November 2016" "1.9.1" "User Commands" .TH NEOFETCH "1" "November 2016" "2.0" "User Commands"
.SH NAME .SH NAME
neofetch \- simple system information script neofetch \- simple system information script