mirror of
https://github.com/dylanaraps/neofetch.git
synced 2025-10-03 16:51:29 +00:00
Compare commits
21 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
25941af61b | ||
|
b0e9cc4782 | ||
|
62db9ad83a | ||
|
ebfe0dbc8c | ||
|
596952e0a2 | ||
|
4fc82847db | ||
|
94cac0676f | ||
|
cfa089e801 | ||
|
0e3fed419e | ||
|
4d0c127b9b | ||
|
656680b324 | ||
|
60e8f2a016 | ||
|
7d9ce8923e | ||
|
c034067573 | ||
|
cd4848e27c | ||
|
70af2fc12d | ||
|
b645fd71c5 | ||
|
572062d98b | ||
|
ac3d1f6c6b | ||
|
5104e448e5 | ||
|
2120fbad0f |
37
Readme.md
37
Readme.md
@@ -1,5 +1,7 @@
|
||||
# fetch.sh
|
||||
|
||||
## Big updates: Check the releases page.
|
||||
|
||||
This is the home of my fetch script! This script gathers info <br\>
|
||||
about your system and prints it to the terminal.
|
||||
|
||||
@@ -7,7 +9,7 @@ If you're having any issues or have any ideas, please open an issue! <br\>
|
||||
I can't test on many other distros and I want this to work <br\>
|
||||
for as many people as possible.
|
||||
|
||||

|
||||

|
||||
|
||||
|
||||
<!-- {{{ -->
|
||||
@@ -25,6 +27,7 @@ These are the script's optional dependencies:
|
||||
- Image Cropping: ImageMagick
|
||||
- Display Wallpaper: feh
|
||||
- Current Song: mpc
|
||||
- Resolution Detection: xorg-xdpyinfo
|
||||
|
||||
|
||||
<!-- }}} -->
|
||||
@@ -57,6 +60,8 @@ Info:
|
||||
--distro string/cmd Manually set the distro
|
||||
--kernel string/cmd Manually set the kernel
|
||||
--uptime string/cmd Manually set the uptime
|
||||
--uptime_shorthand on/off --v
|
||||
Shorten the output of uptime
|
||||
--packages string/cmd Manually set the package count
|
||||
--shell string/cmd Manually set the shell
|
||||
--winman string/cmd Manually set the window manager
|
||||
@@ -93,6 +98,7 @@ Image:
|
||||
images: (wallpaper, \$img)
|
||||
|
||||
--font_width px Used to automatically size the image
|
||||
--image_position Where to display the image: (Left/Right)
|
||||
--split_size num Width of img/text splits
|
||||
A value of 2 makes each split half the terminal
|
||||
width and etc
|
||||
@@ -127,9 +133,25 @@ Other:
|
||||
|
||||
Here's what's on my todo list
|
||||
|
||||
- Add uptime support for OS X
|
||||
- Add options to bold other text in the script (info, underline, colons)
|
||||
- Uptime doesn't work in OS X yet.
|
||||
|
||||
- Windows support (I'm almost done)
|
||||
|
||||
- OpenBSD support (Partially implemented, just needs testing)
|
||||
|
||||
- Imagemagick optimizations
|
||||
|
||||
- Cleanup of info array handling
|
||||
|
||||
- More info outputs. Now that it's easy to customize what's printed and
|
||||
everything is a function we can add optional support for pretty much anything.
|
||||
|
||||
- Resolution
|
||||
- GTK themes
|
||||
- Terminal Font
|
||||
- GPU
|
||||
- IP
|
||||
- etc
|
||||
|
||||
<!-- }}} -->
|
||||
|
||||
@@ -141,3 +163,12 @@ Here's what's on my todo list
|
||||
|
||||
#### Fill
|
||||

|
||||
|
||||
|
||||
### Thanks
|
||||
|
||||
Thanks to:
|
||||
|
||||
- Screenfetch: I've used some snippets as a base for a few functions in this script
|
||||
|
||||
- @jrgz: Helping me test the Mac OS X version.
|
||||
|
256
fetch.sh
256
fetch.sh
@@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
#!/usr/bin/env bash
|
||||
# Fetch info about your system
|
||||
#
|
||||
# Optional Dependencies: (You'll lose these features without them)
|
||||
@@ -7,6 +7,7 @@
|
||||
# Wallpaper Display: feh
|
||||
# Current Song: mpc
|
||||
# Text formatting, dynamic image size and padding: tput
|
||||
# Resolution detection: xorg-xdpyinfo
|
||||
#
|
||||
# Created by Dylan Araps
|
||||
# https://github.com/dylanaraps/dotfiles
|
||||
@@ -22,15 +23,21 @@ export LC_ALL=C
|
||||
|
||||
# Info
|
||||
# What to display and in what order.
|
||||
#
|
||||
# Format is: "Subtitle: function name"
|
||||
# Additional lines you can use include:
|
||||
# "underline" "linebreak" "echo: msg here" "title: title here"
|
||||
# You can also include your own lines by using:
|
||||
#
|
||||
# You can also include your own custom lines by using:
|
||||
# "echo: subtitlehere: $(custom cmd here)"
|
||||
# "echo: Custom string to print"
|
||||
#
|
||||
# Optional info lines that are disabled by default are:
|
||||
# "getresolution" "getsong"
|
||||
info=(
|
||||
"gettitle"
|
||||
"underline"
|
||||
"OS: getos"
|
||||
"OS: getdistro"
|
||||
"Kernel: getkernel"
|
||||
"Uptime: getuptime"
|
||||
"Packages: getpackages"
|
||||
@@ -38,10 +45,8 @@ info=(
|
||||
"Window Manager: getwindowmanager"
|
||||
"CPU: getcpu"
|
||||
"Memory: getmemory"
|
||||
"Song: getsong"
|
||||
"linebreak"
|
||||
"getcols"
|
||||
"linebreak"
|
||||
)
|
||||
|
||||
# CPU
|
||||
@@ -51,6 +56,12 @@ info=(
|
||||
speed_type="max"
|
||||
|
||||
|
||||
# Uptime
|
||||
|
||||
# Shorten the output of the uptime function
|
||||
uptime_shorthand="off"
|
||||
|
||||
|
||||
# Color Blocks
|
||||
|
||||
# Color block range
|
||||
@@ -64,7 +75,7 @@ color_blocks="on"
|
||||
|
||||
# Color block width
|
||||
# --color_block_width num
|
||||
blockwidth=3
|
||||
block_width=3
|
||||
|
||||
|
||||
# }}}
|
||||
@@ -135,6 +146,10 @@ imgtempdir="$HOME/.fetchimages"
|
||||
# --split_size num
|
||||
split_size=2
|
||||
|
||||
# Image position
|
||||
# --image_position left/right
|
||||
image_position="left"
|
||||
|
||||
# Use current wallpaper as the image
|
||||
# --wall on/off
|
||||
wall="on"
|
||||
@@ -177,23 +192,48 @@ xoffset=0
|
||||
# Gather Info {{{
|
||||
|
||||
|
||||
# Get Operating System
|
||||
# Get Operating System Type
|
||||
case "$(uname)" in
|
||||
"Linux")
|
||||
if type -p crux >/dev/null 2>&1; then
|
||||
os="CRUX"
|
||||
else
|
||||
os="$(awk -F'=' '/^NAME=/ {printf $2; exit}' /etc/*ease)"
|
||||
os=${os#\"*}
|
||||
os=${os%*\"}
|
||||
fi
|
||||
os="Linux"
|
||||
;;
|
||||
|
||||
"Darwin")
|
||||
os="Mac OS X"
|
||||
;;
|
||||
|
||||
"OpenBSD")
|
||||
os="OpenBSD"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Get Distro
|
||||
getdistro () {
|
||||
case "$os" in
|
||||
"Linux" )
|
||||
if type -p crux >/dev/null 2>&1; then
|
||||
distro="CRUX"
|
||||
else
|
||||
distro="$(awk -F'=' '/^NAME=/ {printf $2; exit}' /etc/*ease)"
|
||||
distro=${distro#\"*}
|
||||
distro=${distro%*\"}
|
||||
fi
|
||||
;;
|
||||
|
||||
"Mac OS X")
|
||||
distro="Mac OS X $(sw_vers -productVersion)"
|
||||
;;
|
||||
|
||||
"OpenBSD")
|
||||
distro="OpenBSD"
|
||||
;;
|
||||
|
||||
*)
|
||||
distro="Unknown"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Get Title
|
||||
gettitle () {
|
||||
title="${USER}@$(hostname)"
|
||||
@@ -207,18 +247,66 @@ getkernel() {
|
||||
# Get uptime
|
||||
getuptime () {
|
||||
case "$os" in
|
||||
"Linux")
|
||||
uptime="$(uptime -p)"
|
||||
;;
|
||||
|
||||
"Mac OS X")
|
||||
# TODO: Fix uptime for OS X
|
||||
# Get boottime in seconds
|
||||
boot="$(sysctl -n kern.boottime)"
|
||||
boot=${boot/{ sec = /}
|
||||
boot=${boot/,*}
|
||||
|
||||
# Get current date in seconds
|
||||
now=$(date +%s)
|
||||
uptime=$(($now-$boot))
|
||||
|
||||
# Convert uptime to days/hours/mins
|
||||
secs=$((${uptime}%60))
|
||||
mins=$((${uptime}/60%60))
|
||||
hours=$((${uptime}/3600%24))
|
||||
days=$((${uptime}/86400))
|
||||
|
||||
case "$mins" in
|
||||
0) ;;
|
||||
1) uptime="up ${mins} minute" ;;
|
||||
*) uptime="up ${mins} minutes" ;;
|
||||
esac
|
||||
|
||||
case "$hours" in
|
||||
0) ;;
|
||||
1) uptime="up ${hours} hour, ${uptime/up /}" ;;
|
||||
*) uptime="up ${hours} hours, ${uptime/up /}" ;;
|
||||
esac
|
||||
|
||||
case "$days" in
|
||||
0) ;;
|
||||
1) uptime="up ${days} day, ${uptime/up /}" ;;
|
||||
*) uptime="up ${days} days, ${uptime/up /}" ;;
|
||||
esac
|
||||
;;
|
||||
|
||||
"OpenBSD")
|
||||
uptime=$(uptime | awk -F',' '{print $1}')
|
||||
uptime=${uptime# }
|
||||
;;
|
||||
|
||||
*)
|
||||
uptime="Unknown"
|
||||
;;
|
||||
|
||||
*) uptime="$(uptime -p)" ;;
|
||||
esac
|
||||
|
||||
if [ "$uptime_shorthand" == "on" ]; then
|
||||
uptime=${uptime/up/}
|
||||
uptime=${uptime/minutes/mins}
|
||||
uptime=${uptime# }
|
||||
fi
|
||||
}
|
||||
|
||||
# Get package count
|
||||
getpackages () {
|
||||
case "$os" in
|
||||
case "$distro" in
|
||||
"Arch Linux"|"Parabola GNU/Linux-libre"|"Manjaro"|"Antergos")
|
||||
packages="$(pacman -Q | wc -l)"
|
||||
;;
|
||||
@@ -247,12 +335,18 @@ getpackages () {
|
||||
packages="$(pkginfo -i | wc -l)"
|
||||
;;
|
||||
|
||||
"Mac OS X")
|
||||
"Mac OS X"*)
|
||||
packages="$(pkgutil --pkgs | wc -l)"
|
||||
packages=${packages//[[:blank:]]/}
|
||||
;;
|
||||
|
||||
*) packages="Unknown" ;;
|
||||
"OpenBSD")
|
||||
packages=$(pkg_info | wc -l)
|
||||
;;
|
||||
|
||||
*)
|
||||
packages="Unknown"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
@@ -263,7 +357,9 @@ getshell () {
|
||||
|
||||
# Get window manager
|
||||
getwindowmanager () {
|
||||
if [ -e "$HOME/.xinitrc" ]; then
|
||||
if [ ! -z "${XDG_CURRENT_DESKTOP}" ]; then
|
||||
windowmanager="${XDG_CURRENT_DESKTOP}"
|
||||
elif [ -e "$HOME/.xinitrc" ]; then
|
||||
xinitrc=$(awk '/^[^#]*exec/ {print $2}' "${HOME}/.xinitrc")
|
||||
windowmanager="${xinitrc/-session/}"
|
||||
else
|
||||
@@ -282,14 +378,11 @@ getwindowmanager () {
|
||||
|
||||
# Get cpu
|
||||
getcpu () {
|
||||
case $os in
|
||||
"Mac OS X")
|
||||
cpu="$(sysctl -n machdep.cpu.brand_string)"
|
||||
;;
|
||||
|
||||
*)
|
||||
case "$os" in
|
||||
"Linux")
|
||||
cpu="$(awk -F ': ' '/model name/ {printf $2; exit}' /proc/cpuinfo)"
|
||||
|
||||
# We're using lscpu because /proc/cpuinfo doesn't have min/max speed.
|
||||
case $speed_type in
|
||||
current) speed="$(lscpu | awk '/CPU MHz:/ {printf $3}')" ;;
|
||||
min) speed="$(lscpu | awk '/CPU min MHz:/ {printf $4}')" ;;
|
||||
@@ -301,6 +394,18 @@ getcpu () {
|
||||
speed=${speed:0:1}.${speed:1}
|
||||
cpu="$cpu @ ${speed}GHz"
|
||||
;;
|
||||
|
||||
"Mac OS X")
|
||||
cpu="$(sysctl -n machdep.cpu.brand_string)"
|
||||
;;
|
||||
|
||||
"OpenBSD")
|
||||
cpu="$(sysctl -n hw.model)"
|
||||
;;
|
||||
|
||||
*)
|
||||
cpu="Unknown"
|
||||
;;
|
||||
esac
|
||||
|
||||
# Remove uneeded patterns from cpu output
|
||||
@@ -316,17 +421,8 @@ getcpu () {
|
||||
|
||||
# Get memory
|
||||
getmemory () {
|
||||
case $os in
|
||||
"Mac OS X")
|
||||
memtotal=$(printf "$(sysctl -n hw.memsize)"/1024^2 | bc)
|
||||
memwired=$(vm_stat | awk '/wired/ { print $4 }')
|
||||
memactive=$(vm_stat | awk '/active / { print $3 }')
|
||||
memcompressed=$(vm_stat | awk '/occupied/ { print $5 }')
|
||||
memused=$(((${memwired//.} + ${memactive//.} + ${memcompressed//.}) * 4 / 1024))
|
||||
memory="${memused}MB / ${memtotal}MB"
|
||||
;;
|
||||
|
||||
*)
|
||||
case "$os" in
|
||||
"Linux")
|
||||
mem="$(awk 'NR < 4 {printf $2 " "}' /proc/meminfo)"
|
||||
|
||||
# Split the string above into 3 vars
|
||||
@@ -339,6 +435,27 @@ getmemory () {
|
||||
memused="$((memtotal - memavail))"
|
||||
memory="$(( ${memused%% *} / 1024))MB / $(( ${memtotal%% *} / 1024))MB"
|
||||
;;
|
||||
|
||||
"Mac OS X")
|
||||
memtotal=$(printf "%s\n" "$(sysctl -n hw.memsize)"/1024^2 | bc)
|
||||
memwired=$(vm_stat | awk '/wired/ { print $4 }')
|
||||
memactive=$(vm_stat | awk '/active / { print $3 }')
|
||||
memcompressed=$(vm_stat | awk '/occupied/ { print $5 }')
|
||||
memused=$(((${memwired//.} + ${memactive//.} + ${memcompressed//.}) * 4 / 1024))
|
||||
memory="${memused}MB / ${memtotal}MB"
|
||||
;;
|
||||
|
||||
"OpenBSD")
|
||||
memtotal=$(dmesg | awk '/real mem/ {printf $5}')
|
||||
memused=$(top -1 1 | awk '/Real:/ {print $3}')
|
||||
memtotal=${memtotal/()MB/}
|
||||
memused=${memused/M/}
|
||||
memory="${memused}MB / ${memtotal}MB"
|
||||
;;
|
||||
|
||||
*)
|
||||
memory="Unknown"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
@@ -347,11 +464,29 @@ getsong () {
|
||||
song=$(mpc current 2>/dev/null || printf "%s" "Unknown")
|
||||
}
|
||||
|
||||
# Get Resolution
|
||||
getresolution () {
|
||||
case "$os" in
|
||||
"Linux"|"OpenBSD")
|
||||
resolution=$(xdpyinfo | awk '/dimensions:/ {printf $2}')
|
||||
;;
|
||||
|
||||
"Mac OS X")
|
||||
resolution=$(system_profiler SPDisplaysDataType | awk '/Resolution:/ {print $2"x"$4" "}')
|
||||
;;
|
||||
|
||||
*)
|
||||
resolution="Unknown"
|
||||
;;
|
||||
esac
|
||||
|
||||
}
|
||||
|
||||
getcols () {
|
||||
if [ "$color_blocks" == "on" ]; then
|
||||
printf "%s" "${padding}"
|
||||
while [ $start -le $end ]; do
|
||||
printf "%s%${blockwidth}s" "$(tput setab $start)"
|
||||
printf "%s%${block_width}s" "$(tput setab $start)"
|
||||
start=$((start + 1))
|
||||
|
||||
# Split the blocks at 8 colors
|
||||
@@ -381,8 +516,18 @@ getimage () {
|
||||
# Image size is half of the terminal
|
||||
imgsize=$((columns * font_width / split_size))
|
||||
|
||||
# Padding is half the terminal width + gap
|
||||
padding="$(tput cuf $((columns / split_size + gap)))"
|
||||
# Where to draw the image
|
||||
case "$image_position" in
|
||||
"left")
|
||||
# Padding is half the terminal width + gap
|
||||
padding="$(tput cuf $((columns / split_size + gap)))"
|
||||
;;
|
||||
|
||||
"right")
|
||||
padding=$(tput cuf 0)
|
||||
xoffset=$((columns * font_width / split_size - gap))
|
||||
;;
|
||||
esac
|
||||
|
||||
# If wall=on, Get image to display from current wallpaper.
|
||||
if [ "$wall" == "on" ]; then
|
||||
@@ -489,9 +634,6 @@ clear="$(tput sgr0)"
|
||||
# }}}
|
||||
|
||||
|
||||
# Args {{{
|
||||
|
||||
|
||||
# Usage {{{
|
||||
|
||||
|
||||
@@ -504,6 +646,8 @@ usage () {
|
||||
printf "%s\n" " --distro string/cmd Manually set the distro"
|
||||
printf "%s\n" " --kernel string/cmd Manually set the kernel"
|
||||
printf "%s\n" " --uptime string/cmd Manually set the uptime"
|
||||
printf "%s\n" " --uptime_shorthand on/off --v"
|
||||
printf "%s\n" " Shorten the output of uptime"
|
||||
printf "%s\n" " --packages string/cmd Manually set the package count"
|
||||
printf "%s\n" " --shell string/cmd Manually set the shell"
|
||||
printf "%s\n" " --winman string/cmd Manually set the window manager"
|
||||
@@ -539,6 +683,7 @@ usage () {
|
||||
printf "%s\n" " The image gets priority over other"
|
||||
printf "%s\n" " images: (wallpaper, \$img)"
|
||||
printf "%s\n" " --font_width px Used to automatically size the image"
|
||||
printf "&s\n" " --image_position Where to display the image: (Left/Right)"
|
||||
printf "%s\n" " --split_size num Width of img/text splits"
|
||||
printf "%s\n" " A value of 2 makes each split half the terminal"
|
||||
printf "%s\n" " width and etc"
|
||||
@@ -569,13 +714,17 @@ usage () {
|
||||
# }}}
|
||||
|
||||
|
||||
while [ ! -z $1 ]; do
|
||||
# Args {{{
|
||||
|
||||
|
||||
while [ ! -z "$1" ]; do
|
||||
case $1 in
|
||||
# Info
|
||||
--title) title="$2" ;;
|
||||
--os) os="$2" ;;
|
||||
--kernel) kernel="$2" ;;
|
||||
--uptime) uptime="$2" ;;
|
||||
--uptime_shorthand) uptime_shorthand="$2" ;;
|
||||
--packages) packages="$2" ;;
|
||||
--shell) shell="$2" ;;
|
||||
--winman) windowmanager="$2" ;;
|
||||
@@ -605,11 +754,12 @@ while [ ! -z $1 ]; do
|
||||
# Color Blocks
|
||||
--color_blocks) color_blocks="$2" ;;
|
||||
--block_range) start=$2; end=$3 ;;
|
||||
--block_width) blockwidth="$2" ;;
|
||||
--block_width) block_width="$2" ;;
|
||||
|
||||
# Image
|
||||
--image) wall="off"; img="$2" ;;
|
||||
--font_width) font_width="$2" ;;
|
||||
--image_position) image_position="$2" ;;
|
||||
--split_size) split_size="$2" ;;
|
||||
--crop_mode) crop_mode="$2" ;;
|
||||
--crop_offset) crop_offset="$2" ;;
|
||||
@@ -643,8 +793,9 @@ printinfo () {
|
||||
case "$info" in
|
||||
echo:*:*)
|
||||
info=${function#*: }
|
||||
subtitle=${function%:*}
|
||||
subtitle=${function/:*/}
|
||||
string="${bold}${subtitle_color}${subtitle}${clear}${colon_color}: ${info_color}${info}"
|
||||
length=${#function}
|
||||
;;
|
||||
|
||||
echo:*)
|
||||
@@ -668,17 +819,12 @@ printinfo () {
|
||||
fi
|
||||
;;
|
||||
|
||||
*getos*)
|
||||
continue
|
||||
;;
|
||||
|
||||
*:*|*)
|
||||
# Update the var
|
||||
output=${function/get/}
|
||||
typeset -n output=$output
|
||||
var=${function/get/}
|
||||
typeset -n output=$var
|
||||
|
||||
# Call the function
|
||||
# [ -z "$output" ] && echo "$function"; time $function; continue
|
||||
[ -z "$output" ] && $function
|
||||
;;&
|
||||
|
||||
@@ -689,7 +835,7 @@ printinfo () {
|
||||
|
||||
*:*)
|
||||
string="${bold}${subtitle_color}${subtitle}${clear}${colon_color}: ${info_color}${output}"
|
||||
length=${#subtitle}
|
||||
length=$((${#subtitle} + ${#output} + 2))
|
||||
;;
|
||||
|
||||
*)
|
||||
@@ -707,7 +853,7 @@ printinfo () {
|
||||
# }}}
|
||||
|
||||
|
||||
# Print The Info {{{
|
||||
# Call Functions and Finish Up {{{
|
||||
|
||||
|
||||
# Get image
|
||||
|
Reference in New Issue
Block a user