mirror of
https://github.com/dylanaraps/pfetch.git
synced 2026-01-02 16:02:12 +01:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
67003d91b1 |
4
.github/workflows/main.yml
vendored
4
.github/workflows/main.yml
vendored
@@ -6,6 +6,4 @@ jobs:
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
- name: Run shellcheck.
|
||||
run: |
|
||||
shellcheck pfetch
|
||||
sh pfetch
|
||||
run: shellcheck pfetch
|
||||
|
||||
58
README.md
58
README.md
@@ -21,54 +21,24 @@ _/\ __)/_) pkgs 130
|
||||
|
||||
## OS support
|
||||
|
||||
- Linux
|
||||
- Alpine Linux
|
||||
- Arch Linux
|
||||
- Arco Linux
|
||||
- Artix Linux
|
||||
- CentOS
|
||||
- Debian
|
||||
- Elementary
|
||||
- Fedora
|
||||
- Gentoo
|
||||
- Guix
|
||||
- Hyperbola
|
||||
- KISS Linux
|
||||
- Linux Lite
|
||||
- Linux Mint
|
||||
- Mageia
|
||||
- Manjaro
|
||||
- MX Linux
|
||||
- NixOS
|
||||
- OpenSUSE
|
||||
- Parabola
|
||||
- Pop!\_OS
|
||||
- PureOS
|
||||
- Slackware
|
||||
- Ubuntu
|
||||
- Void Linux
|
||||
- BSD
|
||||
- DragonflyBSD
|
||||
- FreeBSD
|
||||
- NetBSD
|
||||
- OpenBSD
|
||||
- MacOS
|
||||
- Haiku
|
||||
- Minix
|
||||
- Solaris
|
||||
- [x] Linux (A myriad of distributions)
|
||||
- [x] MacOS
|
||||
- [x] OpenBSD
|
||||
- [x] FreeBSD
|
||||
- [x] NetBSD
|
||||
- [x] Haiku
|
||||
|
||||
## TODO
|
||||
|
||||
- [ ] Add optional and additional information detection.
|
||||
- [ ] CPU
|
||||
- [ ] Terminal Emulator ([#12](https://github.com/dylanaraps/pfetch/pull/12))
|
||||
- [ ] Terminal Emulator
|
||||
- The way I implement this in `neofetch` is interesting.
|
||||
- [x] Terminal colors ([commit](https://github.com/dylanaraps/pfetch/commit/ba03cb3cf4dfbc767abce6acd53c07ab5568e23d))
|
||||
- [ ] Window manager ([#13](https://github.com/dylanaraps/pfetch/pull/13))
|
||||
- [ ] Terminal colors
|
||||
- [ ] ???
|
||||
- [ ] Expand operating system support.
|
||||
- [x] Solaris ([#5](https://github.com/dylanaraps/pfetch/issues/5))
|
||||
- [x] MINIX ([#6](https://github.com/dylanaraps/pfetch/issues/6))
|
||||
- [ ] Solaris ([#5](https://github.com/dylanaraps/pfetch/issues/5))
|
||||
- [ ] MINIX ([#6](https://github.com/dylanaraps/pfetch/issues/6))
|
||||
- [ ] AIX ([#7](https://github.com/dylanaraps/pfetch/issues/7))
|
||||
- [ ] IRIX ([#8](https://github.com/dylanaraps/pfetch/issues/8))
|
||||
- [ ] FreeMiNT ([#9](https://github.com/dylanaraps/pfetch/issues/9))
|
||||
@@ -76,7 +46,7 @@ _/\ __)/_) pkgs 130
|
||||
- [ ] CYGWIN
|
||||
- [ ] MSYS
|
||||
- [ ] MINGW
|
||||
- [x] WSL (*this is fairly simple*)
|
||||
- [ ] WSL (*this is fairly simple*)
|
||||
|
||||
## Configuration
|
||||
|
||||
@@ -88,14 +58,14 @@ _/\ __)/_) pkgs 130
|
||||
# Default: first example below
|
||||
# Valid: space separated string
|
||||
#
|
||||
# OFF by default: shell palette
|
||||
PF_INFO="ascii title os host kernel uptime pkgs memory"
|
||||
# OFF by default: shell
|
||||
PF_INFO="ascii title distro host kernel uptime pkgs memory"
|
||||
|
||||
# Example: Only ASCII.
|
||||
PF_INFO="ascii"
|
||||
|
||||
# Example: Only Information.
|
||||
PF_INFO="title os host kernel uptime pkgs memory"
|
||||
PF_INFO="title distro host kernel uptime pkgs memory"
|
||||
|
||||
# Separator between info name and info data.
|
||||
# Default: unset
|
||||
|
||||
402
pfetch
402
pfetch
@@ -64,7 +64,7 @@ log() {
|
||||
|
||||
# Use 'set --' as a means of stripping all leading and trailing
|
||||
# white-space from the info string. This also normalizes all
|
||||
# white-space inside of the string.
|
||||
# whitespace inside of the string.
|
||||
#
|
||||
# Disable the shellcheck warning for word-splitting
|
||||
# as it's safe and intended ('set -f' disables globbing).
|
||||
@@ -95,13 +95,13 @@ log() {
|
||||
printf '[3%sm%s[m\n' "${PF_COL2-7}" "$info"
|
||||
|
||||
# Keep track of the number of times 'log()' has been run.
|
||||
info_height=$((${info_height:-0} + 1))
|
||||
: $((info_height+=1))
|
||||
}
|
||||
|
||||
get_title() {
|
||||
# Username is retrieved by first checking '$USER' with a fallback
|
||||
# to the 'id -un' command.
|
||||
user=${USER:-$(id -un)}
|
||||
# to the 'whoami' command.
|
||||
user=${USER:-$(whoami)}
|
||||
|
||||
# Hostname is retrieved by first checking '$HOSTNAME' with a fallback
|
||||
# to the 'hostname' command.
|
||||
@@ -155,39 +155,16 @@ get_os() {
|
||||
distro=$(lsb_release -sd)
|
||||
|
||||
else
|
||||
# This used to be a simple '. /etc/os-release' but I believe
|
||||
# this is insecure as we blindly execute whatever is in the
|
||||
# file. This parser instead simply handles 'key=val', treating
|
||||
# the file contents as plain-text.
|
||||
while IFS='=' read -r key val; do
|
||||
case $key in
|
||||
PRETTY_NAME) distro=$val ;;
|
||||
esac
|
||||
done < /etc/os-release
|
||||
# Disable warning about shellcheck not being able
|
||||
# to read '/etc/os-release'. This is fine.
|
||||
# shellcheck source=/dev/null
|
||||
. /etc/os-release && distro=$PRETTY_NAME
|
||||
fi
|
||||
|
||||
# 'os-release' and 'lsb_release' sometimes add quotes
|
||||
# around the distribution name, strip them.
|
||||
distro=${distro##[\"\']}
|
||||
distro=${distro%%[\"\']}
|
||||
|
||||
# Special cases for (independent) distributions which
|
||||
# don't follow any os-release/lsb standards whatsoever.
|
||||
command -v crux && distro=$(crux)
|
||||
command -v guix && distro='Guix System'
|
||||
|
||||
# Check to see if Linux is running in Windows 10 under
|
||||
# WSL (Windows subsystem for Linux) and append a string
|
||||
# accordingly.
|
||||
#
|
||||
# If the kernel version string ends in "-Microsoft",
|
||||
# we're very likely running under Windows 10 in WSL.
|
||||
#
|
||||
# This also acts as a means of allowing the user to
|
||||
# fake this by changing their kernel version to end in
|
||||
# "Microsoft".
|
||||
[ "${kernel%%*-Microsoft}" ] ||
|
||||
distro="$distro on Windows 10"
|
||||
command -v crux && distro=$(crux)
|
||||
command -v guix && distro='Guix System'
|
||||
;;
|
||||
|
||||
Darwin*)
|
||||
@@ -238,22 +215,8 @@ get_os() {
|
||||
|
||||
Haiku)
|
||||
# Haiku uses 'uname -v' for version information
|
||||
# instead of 'uname -r' which only prints '1'.
|
||||
distro=$(uname -sv)
|
||||
;;
|
||||
|
||||
Minix|DragonFly)
|
||||
distro="$os $kernel"
|
||||
|
||||
# Minix and DragonFly don't support the escape
|
||||
# sequences used, clear the exit trap.
|
||||
trap '' EXIT
|
||||
;;
|
||||
|
||||
SunOS)
|
||||
# Grab the first line of the '/etc/release' file
|
||||
# discarding everything after '('.
|
||||
IFS='(' read -r distro _ < /etc/release
|
||||
# instead of 'uname -r'.
|
||||
distro="Haiku $(uname -v)"
|
||||
;;
|
||||
|
||||
*)
|
||||
@@ -268,7 +231,7 @@ get_kernel() {
|
||||
case $os in
|
||||
# Don't print kernel output on some systems as the
|
||||
# OS name includes it.
|
||||
*BSD*|Haiku|Minix) ;;
|
||||
*BSD*|Haiku) ;;
|
||||
|
||||
*)
|
||||
# '$kernel' is the cached output of 'uname -r'.
|
||||
@@ -277,10 +240,6 @@ get_kernel() {
|
||||
esac
|
||||
}
|
||||
|
||||
get_shell() {
|
||||
log shell "${SHELL##*/}" >&6
|
||||
}
|
||||
|
||||
get_host() {
|
||||
case $os in
|
||||
Linux*)
|
||||
@@ -294,7 +253,7 @@ get_host() {
|
||||
host="$name $version $model"
|
||||
;;
|
||||
|
||||
Darwin*|FreeBSD*|DragonFly*)
|
||||
Darwin*|FreeBSD*)
|
||||
host=$(sysctl -n hw.model)
|
||||
;;
|
||||
|
||||
@@ -355,11 +314,11 @@ get_uptime() {
|
||||
# converting that data into days, hours and minutes using simple
|
||||
# math.
|
||||
case $os in
|
||||
Linux*|Minix*)
|
||||
Linux*)
|
||||
IFS=. read -r s _ < /proc/uptime
|
||||
;;
|
||||
|
||||
Darwin*|*BSD*|DragonFly*)
|
||||
Darwin*|*BSD*)
|
||||
s=$(sysctl -n kern.boottime)
|
||||
|
||||
# Extract the uptime in seconds from the following output:
|
||||
@@ -377,19 +336,6 @@ get_uptime() {
|
||||
# regular seconds.
|
||||
s=$(($(system_time) / 1000000))
|
||||
;;
|
||||
|
||||
SunOS)
|
||||
# Split the output of 'kstat' on '.' and any white-space
|
||||
# which exists in the command output.
|
||||
#
|
||||
# The output is as follows:
|
||||
# unix:0:system_misc:snaptime 14809.906993005
|
||||
#
|
||||
# The parser extracts: ^^^^^
|
||||
IFS=' .' read -r _ s _ <<-EOF
|
||||
$(kstat -p unix:0:system_misc:snaptime)
|
||||
EOF
|
||||
;;
|
||||
esac
|
||||
|
||||
# Convert the uptime from seconds into days, hours and minutes.
|
||||
@@ -406,10 +352,6 @@ get_uptime() {
|
||||
}
|
||||
|
||||
get_pkgs() {
|
||||
# This is just a simple wrapper around 'command -v' to avoid
|
||||
# spamming '>/dev/null' throughout this function.
|
||||
has() { command -v "$1" >/dev/null; }
|
||||
|
||||
# This works by first checking for which package managers are
|
||||
# installed and finally by printing each package manager's
|
||||
# package list with each package one per line.
|
||||
@@ -430,22 +372,27 @@ get_pkgs() {
|
||||
case $os in
|
||||
Linux*)
|
||||
# Commands which print packages one per line.
|
||||
has bonsai && bonsai list
|
||||
has pacman-key && pacman -Qq
|
||||
has dpkg && dpkg-query -f '.\n' -W
|
||||
has rpm && rpm -qa
|
||||
has xbps-query && xbps-query -l
|
||||
has apk && apk info
|
||||
has guix && guix package --list-installed
|
||||
command -v kiss && kiss l
|
||||
command -v bonsai && bonsai list
|
||||
command -v pacman-key && pacman -Qq
|
||||
command -v dpkg && dpkg-query -f '.\n' -W
|
||||
command -v rpm && rpm -qa
|
||||
command -v xbps-query && xbps-query -l
|
||||
command -v apk && apk info
|
||||
|
||||
# Directories containing packages.
|
||||
has kiss && printf '%s\n' /var/db/kiss/installed/*/
|
||||
has brew && printf '%s\n' "$(brew --cellar)/"*
|
||||
has emerge && printf '%s\n' /var/db/pkg/*/*/
|
||||
has pkgtool && printf '%s\n' /var/log/packages/*
|
||||
command -v brew && printf '%s\n' "$(brew --cellar)/"*
|
||||
command -v emerge && printf '%s\n' /var/db/pkg/*/*/
|
||||
command -v pkgtool && printf '%s\n' /var/log/packages/*
|
||||
|
||||
# GUIX requires two commands.
|
||||
command -v guix && {
|
||||
guix package -p /run/current-system/profile -I
|
||||
guix package -I
|
||||
}
|
||||
|
||||
# NIX requires two commands.
|
||||
has nix-store && {
|
||||
command -v nix-store && {
|
||||
nix-store -q --requisites /run/current-system/sw
|
||||
nix-store -q --requisites ~.nix-profile
|
||||
}
|
||||
@@ -453,14 +400,14 @@ get_pkgs() {
|
||||
|
||||
Darwin*)
|
||||
# Commands which print packages one per line.
|
||||
has pkgin && pkgin list
|
||||
has port && port installed
|
||||
command -v pkgin && pkgin list
|
||||
command -v port && port installed
|
||||
|
||||
# Directories containing packages.
|
||||
has brew && printf '%s\n' /usr/local/Cellar/*
|
||||
command -v brew && printf '%s\n' /usr/local/Cellar/*
|
||||
;;
|
||||
|
||||
FreeBSD*|DragonFly*)
|
||||
FreeBSD*)
|
||||
pkg info
|
||||
;;
|
||||
|
||||
@@ -475,15 +422,6 @@ get_pkgs() {
|
||||
Haiku)
|
||||
printf '%s\n' /boot/system/package-links/*
|
||||
;;
|
||||
|
||||
Minix)
|
||||
printf '%s\n' /usr/pkg/var/db/pkg/*/
|
||||
;;
|
||||
|
||||
SunOS)
|
||||
has pkginfo && pkginfo -i
|
||||
has pkg && pkg list
|
||||
;;
|
||||
esac | wc -l
|
||||
`
|
||||
|
||||
@@ -492,14 +430,14 @@ get_pkgs() {
|
||||
|
||||
get_memory() {
|
||||
case $os in
|
||||
# Used memory is calculated using the following "formula":
|
||||
# Used memory is calculated using the following "formula" (Linux):
|
||||
# MemUsed = MemTotal + Shmem - MemFree - Buffers - Cached - SReclaimable
|
||||
# Source: https://github.com/KittyKatt/screenFetch/issues/386
|
||||
Linux*)
|
||||
# Parse the '/proc/meminfo' file splitting on ':' and 'k'.
|
||||
# The format of the file is 'key: 000kB' and an additional
|
||||
# split is used on 'k' to filter out 'kB'.
|
||||
while IFS=':k ' read -r key val _; do
|
||||
while IFS=:k read -r key val _; do
|
||||
case $key in
|
||||
MemTotal)
|
||||
mem_used=$((mem_used + val))
|
||||
@@ -520,7 +458,7 @@ get_memory() {
|
||||
mem_full=$((mem_full / 1024))
|
||||
;;
|
||||
|
||||
# Used memory is calculated using the following "formula":
|
||||
# Used memory is calculated using the following "formula" (MacOS):
|
||||
# (wired + active + occupied) * 4 / 1024
|
||||
Darwin*)
|
||||
mem_full=$(($(sysctl -n hw.memsize) / 1024 / 1024))
|
||||
@@ -570,9 +508,9 @@ get_memory() {
|
||||
EOF
|
||||
;;
|
||||
|
||||
# Used memory is calculated using the following "formula":
|
||||
# mem_full - ((inactive + free + cache) * page_size / 1024)
|
||||
FreeBSD*|DragonFly*)
|
||||
# Used memory is calculated using the following "formula" (FreeBSD):
|
||||
# (inactive_count + free_count + cache_count) * page_size / 1024
|
||||
FreeBSD*)
|
||||
mem_full=$(($(sysctl -n hw.physmem) / 1024 / 1024))
|
||||
|
||||
# Use 'set --' to store the output of the command in the
|
||||
@@ -594,7 +532,7 @@ get_memory() {
|
||||
# $2: vm.stats.vm.v_inactive_count
|
||||
# $3: vm.stats.vm.v_free_count
|
||||
# $4: vm.stats.vm.v_cache_count
|
||||
mem_used=$((mem_full - (($2 + $3 + $4) * $1 / 1024 / 1024)))
|
||||
mem_used=$((($2 + $3 + $4) * $1 / 1024 / 1024))
|
||||
;;
|
||||
|
||||
NetBSD*)
|
||||
@@ -602,7 +540,7 @@ get_memory() {
|
||||
|
||||
# NetBSD implements a lot of the Linux '/proc' filesystem,
|
||||
# this uses the same parser as the Linux memory detection.
|
||||
while IFS=':k ' read -r key val _; do
|
||||
while IFS=:k read -r key val _; do
|
||||
case $key in
|
||||
MemFree)
|
||||
mem_free=$((val / 1024))
|
||||
@@ -629,53 +567,133 @@ get_memory() {
|
||||
mem_used=$((mem_used / 1024 / 1024))
|
||||
mem_full=$((mem_full / 1024 / 1024))
|
||||
;;
|
||||
|
||||
Minix)
|
||||
# Minix includes the '/proc' filesystem though the format
|
||||
# differs from Linux. The '/proc/meminfo' file is only a
|
||||
# single line with space separated elements and elements
|
||||
# 2 and 3 contain the total and free memory numbers.
|
||||
read -r _ mem_full mem_free _ < /proc/meminfo
|
||||
|
||||
mem_used=$(((mem_full - mem_free) / 1024))
|
||||
mem_full=$(( mem_full / 1024))
|
||||
;;
|
||||
|
||||
SunOS)
|
||||
hw_pagesize=$(pagesize)
|
||||
|
||||
while read -r key val; do
|
||||
case $key in
|
||||
*total) pages_full=$val ;;
|
||||
*free) pages_free=$val ;;
|
||||
esac
|
||||
done <<-EOF
|
||||
$(kstat -p unix:0:system_pages:pagestotal \
|
||||
unix:0:system_pages:pagesfree)
|
||||
EOF
|
||||
|
||||
mem_full=$((pages_full * hw_pagesize / 1024 / 1024))
|
||||
mem_free=$((pages_free * hw_pagesize / 1024 / 1024))
|
||||
mem_used=$((mem_full - mem_free))
|
||||
;;
|
||||
esac
|
||||
|
||||
log memory "${mem_used:-?}M / ${mem_full:-?}M" >&6
|
||||
}
|
||||
|
||||
get_palette() {
|
||||
# Print the first 8 terminal colors. This uses the existing
|
||||
# sequences to change text color with a sequence prepended
|
||||
# to reverse the foreground and background colors.
|
||||
get_term() {
|
||||
# Workaround for macOS systems that don't support the
|
||||
# "algorithm" of obtaining the terminal program name.
|
||||
#
|
||||
# This allows us to save hardcoding a second set of sequences
|
||||
# for background colors.
|
||||
palette=" [7m$c1 $c2 $c3 $c4 $c5 $c6 $c7 "
|
||||
# This also doubles as a means of allowing the user to
|
||||
# set whatever value they like here through the
|
||||
# '$TERM_PROGRAM' environment variable.
|
||||
case $TERM_PROGRAM in
|
||||
iTerm.app) term=iTerm2 ;;
|
||||
Terminal.app) term='Apple Terminal' ;;
|
||||
Hyper) term=HyperTerm ;;
|
||||
*) term=${TERM_PROGRAM%%.app} ;;
|
||||
esac
|
||||
|
||||
# Print the palette with a newline before and after.
|
||||
# The '\033[%sC' moves the text to the right, the
|
||||
# length of the ascii art.
|
||||
printf '\n[%sC%s[m\n' "${ascii_width-1}" "$palette" >&6
|
||||
# Special case for TosWin2 (FreeMiNT) which doesn't
|
||||
# support the "algorithm" of obtaining the terminal
|
||||
# program name.
|
||||
[ "$TERM" = tw52 ] || [ "$TERM" = tw100 ] &&
|
||||
term=TosWin2
|
||||
|
||||
# Special case for when 'pfetch' is run over SSH.
|
||||
[ "$SSH_CONNECTION" ] &&
|
||||
term=$SSH_TTY
|
||||
|
||||
# This surprisingly reliable method of detecting the current
|
||||
# terminal emulator is kinda neat.
|
||||
#
|
||||
# It works by looping through each parent of each process
|
||||
# starting with '$PPID' (the parent process ID) until we
|
||||
# find a match or hit PID 1 (init).
|
||||
#
|
||||
# On each iteration the name of the current parent process
|
||||
# is checked against a list of good values and bad values.
|
||||
# If no match is found we check the parent of the parent
|
||||
# and so on.
|
||||
#
|
||||
# Using this method *no* terminal emulator names are
|
||||
# hardcoded and the list remains small and general. In short
|
||||
# it's basically a list of what *isn't* a terminal emulator
|
||||
# and a list of places we should *stop*.
|
||||
while [ -z "$term" ]; do
|
||||
# This block is OS-specific and handles the fetching of
|
||||
# the parent process (of the parent) and the fetching of
|
||||
# said process' name.
|
||||
case $os in
|
||||
Linux*)
|
||||
# On Linux some implementation of 'ps' aren't POSIX
|
||||
# compliant, thankfully Linux provides this information
|
||||
# though the '/proc' filesystem.
|
||||
#
|
||||
# This loops line by line over the '/proc/PID/status'
|
||||
# file splitting at ':' and '<TAB>', we then look for
|
||||
# the key containing 'PPid' and grab the value.
|
||||
while IFS=': ' read -r key val; do
|
||||
case $key in
|
||||
PPid)
|
||||
ppid=$val
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done < "/proc/${ppid:-$PPID}/status"
|
||||
|
||||
# Get the name of the parent process.
|
||||
read -r name < "/proc/$ppid/comm"
|
||||
;;
|
||||
|
||||
Windows*)
|
||||
# I need some assistance to add Windows support
|
||||
# as the 'ps' command used in MINGW, MSYS and CYGWIN
|
||||
# isn't POSIX compliant(?).
|
||||
return
|
||||
;;
|
||||
|
||||
*)
|
||||
# POSIX compliant 'ps' makes this really easy,
|
||||
# just two simple commands to grab the parent
|
||||
# process ID and the ID's name.
|
||||
ppid=$(ps -p "${ppid:-$PPID}" -o ppid=)
|
||||
name=$(ps -p "$ppid" -o comm=)
|
||||
;;
|
||||
esac
|
||||
|
||||
# Check the parent process name against a list of good and bad
|
||||
# values. On a bad value we either keep iterating up the parent
|
||||
# process list or we stop altogether (PID 1 for example).
|
||||
case $name in
|
||||
# If the parent process name matches the user's shell (or
|
||||
# anything that looks like a shell), do another iteration.
|
||||
#
|
||||
# This also includes 'screen' and anything that looks like
|
||||
# 'su' or 'sudo'.
|
||||
${SHELL##*/} | *sh | screen | su* ) ;;
|
||||
|
||||
# If the parent process name matches 'login', 'init' or
|
||||
# '*Login*' we're most likely in the TTY and not a graphical
|
||||
# session. In this case 'term' is set to the current TTY and
|
||||
# we end here.
|
||||
login* | *Login* | init)
|
||||
term=$(tty)
|
||||
;;
|
||||
|
||||
# If the parent process name matches anything in this list
|
||||
# we can no longer continue. We've either hit PID 1 or a parent
|
||||
# which *won't* lead to the terminal emulator's PID.
|
||||
ruby | systemd | python* | 1 | sshd* | tmux* |\
|
||||
USER*PID* | kdeinit* | launchd* | '' )
|
||||
break
|
||||
;;
|
||||
|
||||
# If none of the above have matched we've reached the terminal
|
||||
# emulator's PID and we can end here.
|
||||
*)
|
||||
term=${name##*/}
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
[ "$term" ] && log term "$term" >&6
|
||||
}
|
||||
|
||||
get_shell() {
|
||||
log shell "${SHELL##*/}" >&6
|
||||
}
|
||||
|
||||
get_ascii() {
|
||||
@@ -785,18 +803,6 @@ get_ascii() {
|
||||
EOF
|
||||
;;
|
||||
|
||||
[Dd]ragon[Ff]ly*)
|
||||
read_ascii 1 <<-EOF
|
||||
,${c1}_${c7},
|
||||
('-_${c1}|${c7}_-')
|
||||
>--${c1}|${c7}--<
|
||||
(_-'${c1}|${c7}'-_)
|
||||
${c1}|
|
||||
|
|
||||
|
|
||||
EOF
|
||||
;;
|
||||
|
||||
[Ee]lementary*)
|
||||
read_ascii <<-EOF
|
||||
${c7} _______
|
||||
@@ -955,19 +961,6 @@ get_ascii() {
|
||||
EOF
|
||||
;;
|
||||
|
||||
[Mm]inix*)
|
||||
read_ascii 4 <<-EOF
|
||||
${c4} ,, ,,
|
||||
;${c7},${c4} ', ,' ${c7},${c4};
|
||||
; ${c7}',${c4} ',,' ${c7},'${c4} ;
|
||||
; ${c7}',${c4} ${c7},'${c4} ;
|
||||
; ${c7};, '' ,;${c4} ;
|
||||
; ${c7};${c4};${c7}',,'${c4};${c7};${c4} ;
|
||||
', ${c7};${c4};; ;;${c7};${c4} ,'
|
||||
'${c7};${c4}' '${c7};${c4}'
|
||||
EOF
|
||||
;;
|
||||
|
||||
[Mm][Xx]*)
|
||||
read_ascii <<-EOF
|
||||
${c7} \\\\ /
|
||||
@@ -1075,27 +1068,6 @@ get_ascii() {
|
||||
EOF
|
||||
;;
|
||||
|
||||
[Ss]un[Oo][Ss])
|
||||
read_ascii 3 <<-EOF
|
||||
${c3} . .; .
|
||||
. :; :: ;: .
|
||||
.;. .. .. .;.
|
||||
.. .. .. ..
|
||||
.;, ,;.
|
||||
EOF
|
||||
;;
|
||||
|
||||
[Uu]buntu*)
|
||||
read_ascii 3 <<-EOF
|
||||
${c3} _
|
||||
---(_)
|
||||
_/ --- \\
|
||||
(_) | |
|
||||
\\ --- _/
|
||||
---(_)
|
||||
EOF
|
||||
;;
|
||||
|
||||
[Vv]oid*)
|
||||
read_ascii 2 <<-EOF
|
||||
${c2} _______
|
||||
@@ -1132,12 +1104,8 @@ get_ascii() {
|
||||
# information. The 'sed' is used to strip '[3Xm' color codes from
|
||||
# the ascii art so they don't affect the width variable.
|
||||
while read -r line; do
|
||||
ascii_height=$((${ascii_height:-0} + 1))
|
||||
|
||||
# This was a ternary operation but they aren't supported in
|
||||
# Minix's shell.
|
||||
[ "${#line}" -gt "${ascii_width:-0}" ] &&
|
||||
ascii_width=${#line}
|
||||
: $((ascii_height+=1))
|
||||
ascii_width=$((${#line} > ascii_width ? ${#line} : ascii_width))
|
||||
|
||||
# Using '<<-EOF' is the only way to loop over a command's
|
||||
# output without the use of a pipe ('|').
|
||||
@@ -1148,20 +1116,16 @@ get_ascii() {
|
||||
EOF
|
||||
|
||||
# Add a gap between the ascii art and the information.
|
||||
ascii_width=$((ascii_width + 4))
|
||||
|
||||
# Minix and DragonFly don't support these!
|
||||
# '[?7l': Disable line-wrapping.
|
||||
# '[?25l': Hide the cursor.
|
||||
[ "$os" != Minix ] && [ "$os" != DragonFly ] &&
|
||||
printf '[?7l[?25l' >&6
|
||||
: $((ascii_width+=4))
|
||||
|
||||
# Print the ascii art and position the cursor back where we
|
||||
# started prior to printing it.
|
||||
# '[?7l': Disable line-wrapping.
|
||||
# '[?25l': Hide the cursor.
|
||||
# '[1m': Print the ascii in bold.
|
||||
# '[m': Clear bold.
|
||||
# '[%sA': Move the cursor up '$ascii_height' amount of lines.
|
||||
printf '[1m%s[m[%sA' "$ascii" "$ascii_height" >&6
|
||||
printf '[?7l[?25l[1m%s[m[%sA' "$ascii" "$ascii_height" >&6
|
||||
}
|
||||
|
||||
main() {
|
||||
@@ -1206,22 +1170,18 @@ main() {
|
||||
# Disable globbing and set the positional parameters to the
|
||||
# contents of 'PF_INFO'.
|
||||
set -f
|
||||
set +f ${PF_INFO-ascii title os host kernel uptime pkgs memory}
|
||||
set +f ${PF_INFO-ascii title os host kernel term uptime pkgs memory}
|
||||
|
||||
# Iterate over the info functions to determine the lengths of the
|
||||
# "info names" for output alignment. The option names and subtitles
|
||||
# match 1:1 so this is thankfully simple.
|
||||
for info; do
|
||||
command -v "get_$info" >/dev/null || continue
|
||||
|
||||
# This was a ternary operation but they aren't supported in
|
||||
# Minix's shell.
|
||||
[ "${#info}" -gt "${info_length:-0}" ] &&
|
||||
info_length=${#info}
|
||||
command -v "get_$info" >/dev/null &&
|
||||
info_length=$((${#info} > info_length ? ${#info} : info_length))
|
||||
done
|
||||
|
||||
# Add an additional space of length to act as a gap.
|
||||
info_length=$((info_length + 1))
|
||||
: $((info_length+=1))
|
||||
|
||||
# Iterate over the above list and run any existing "get_" functions.
|
||||
for info; do "get_$info"; done
|
||||
@@ -1229,19 +1189,15 @@ main() {
|
||||
|
||||
# Position the cursor below both the ascii art and information lines
|
||||
# according to the height of both. If the information exceeds the ascii
|
||||
# art in height, don't touch the cursor (0/unset), else move it down
|
||||
# N lines.
|
||||
#
|
||||
# This was a ternary operation but they aren't supported in Minix's shell.
|
||||
[ "$info_height" -lt "$ascii_height" ] &&
|
||||
cursor_pos=$((ascii_height - info_height))
|
||||
# art in height, don't touch the cursor, else move it down N lines.
|
||||
cursor_pos=$((info_height > ascii_height ? 0 : ascii_height - info_height))
|
||||
|
||||
# Print '$cursor_pos' amount of newlines to correctly position the
|
||||
# cursor. This used to be a 'printf $(seq X X)' however 'seq' is only
|
||||
# typically available (by default) on GNU based systems!
|
||||
while [ "${i:=0}" -le "${cursor_pos:-0}" ]; do
|
||||
while [ "${i:-0}" -le "$cursor_pos" ]; do
|
||||
printf '\n'
|
||||
i=$((i + 1))
|
||||
: $((i+=1))
|
||||
done >&6
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user