45 Commits
term ... 0.2

Author SHA1 Message Date
Dylan Araps
d706ec7a01 docs: update 2019-09-30 23:01:36 +03:00
Dylan Araps
c9d961836c solaris: comments 2019-09-30 20:08:27 +03:00
dylan
3a8ac8c53d Merge pull request #18 from Crestwave/solaris
pfetch: initial solaris support
2019-09-30 20:05:49 +03:00
Dylan Araps
fcd62e9043 better os-release handling, and sunos ascii 2019-09-30 20:02:36 +03:00
Crestwave
02a9bd84af pfetch: code style changes 2019-09-30 15:32:54 +08:00
Crestwave
a9af270b96 pfetch: initial solaris support 2019-09-30 15:18:09 +08:00
Dylan Araps
9985e6cfe9 pfetch: fix whoami not posix 2019-09-30 09:25:39 +03:00
Dylan Araps
0977e5f1a1 docs: update 2019-09-29 17:25:26 +03:00
Dylan Araps
8ff9d722b5 memory: netBSD fix 2019-09-29 16:59:08 +03:00
Dylan Araps
ca4004de90 uptime: bug fix 2019-09-29 16:28:43 +03:00
Dylan Araps
ee6e1bd390 memory: bug fix 2019-09-29 16:27:45 +03:00
Dylan Araps
c888f4cdca pfetch: fix dragonfly issues 2019-09-29 16:20:16 +03:00
Dylan Araps
1363a973d4 misc: clean up 2019-09-29 13:20:27 +03:00
Dylan Araps
7e70668ce7 kiss: faster package list' 2019-09-29 12:24:18 +03:00
Dylan Araps
935fd295dd docs: update 2019-09-29 12:21:16 +03:00
Dylan Araps
5648839b55 pfetch: Ubuntu support 2019-09-29 12:21:07 +03:00
Dylan Araps
d79c2f20d5 docs: update 2019-09-29 11:46:15 +03:00
Dylan Araps
24e063479a docs: update 2019-09-29 09:32:42 +03:00
Dylan Araps
3a562917c3 pfetch: initial DragonflyBSD support 2019-09-29 09:19:35 +03:00
Dylan Araps
300f31c5cd memory: fix issue in yash 2019-09-28 17:18:18 +03:00
Dylan Araps
f4bb7a3da8 pfetch: initial dragonfly support 2019-09-28 16:50:49 +03:00
Dylan Araps
09c179f6f5 docs: update 2019-09-28 15:56:13 +03:00
Dylan Araps
b85ec5657d docs: update 2019-09-28 15:04:05 +03:00
Dylan Araps
6b46e941cd fix more minixisms 2019-09-28 15:02:44 +03:00
Dylan Araps
180c00173a fix more minixisms 2019-09-28 15:00:45 +03:00
Dylan Araps
be6b5ae5ed minix's sh requires all variables have default values 2019-09-28 14:56:12 +03:00
Dylan Araps
c6f46d5428 pfetch: portability with minix 2019-09-28 14:49:34 +03:00
Dylan Araps
a43a697551 fix arithmetic in minix 2019-09-28 14:41:57 +03:00
Dylan Araps
8b801b8b50 pfetch: minix support 2019-09-28 14:31:10 +03:00
Dylan Araps
c9c27ba54b initial minux support 2019-09-28 13:11:49 +03:00
Dylan Araps
090fe64dec guix: simpler package list 2019-09-28 12:57:23 +03:00
Dylan Araps
fddfe5435c docs: update 2019-09-28 12:21:36 +03:00
Dylan Araps
a7d1a6d980 docs: update 2019-09-28 12:20:15 +03:00
Dylan Araps
6c50390f78 docs: update 2019-09-28 12:16:51 +03:00
Dylan Araps
ec69fcb195 docs: update 2019-09-28 12:13:16 +03:00
Dylan Araps
599db8dc83 docs: update 2019-09-28 12:12:20 +03:00
Dylan Araps
7d343f9d62 haiku: comment 2019-09-28 11:51:40 +03:00
Dylan Araps
1b37bf9dd2 docs: update 2019-09-28 10:32:41 +03:00
Dylan Araps
eb9c8a3cfe pfetch: WSL support 2019-09-28 10:30:59 +03:00
Dylan Araps
59340ff4ce pkgs: fix extra count 2019-09-28 07:25:20 +03:00
Dylan Araps
68d2422a1b os: fixed lsb_release, closes #14 2019-09-28 07:01:50 +03:00
Dylan Araps
55b78b9e58 docs: update 2019-09-27 22:45:16 +03:00
Dylan Araps
b7292e0cbc docs: update 2019-09-27 22:03:34 +03:00
Dylan Araps
ba03cb3cf4 pfetch: add get_palette 2019-09-27 21:49:44 +03:00
Dylan Araps
d91cd1c0bf docs: update 2019-09-27 21:04:00 +03:00
3 changed files with 269 additions and 73 deletions

View File

@@ -6,4 +6,6 @@ jobs:
steps:
- uses: actions/checkout@v1
- name: Run shellcheck.
run: shellcheck pfetch
run: |
shellcheck pfetch
sh pfetch

View File

@@ -21,24 +21,54 @@ _/\ __)/_) pkgs 130
## OS support
- [x] Linux (A myriad of distributions)
- [x] MacOS
- [x] OpenBSD
- [x] FreeBSD
- [x] NetBSD
- [x] Haiku
- 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
## TODO
- [ ] Add optional and additional information detection.
- [ ] CPU
- [ ] Terminal Emulator
- [ ] Terminal Emulator ([#12](https://github.com/dylanaraps/pfetch/pull/12))
- The way I implement this in `neofetch` is interesting.
- [ ] Terminal colors
- [x] Terminal colors ([commit](https://github.com/dylanaraps/pfetch/commit/ba03cb3cf4dfbc767abce6acd53c07ab5568e23d))
- [ ] Window manager ([#13](https://github.com/dylanaraps/pfetch/pull/13))
- [ ] ???
- [ ] Expand operating system support.
- [ ] Solaris ([#5](https://github.com/dylanaraps/pfetch/issues/5))
- [ ] MINIX ([#6](https://github.com/dylanaraps/pfetch/issues/6))
- [x] Solaris ([#5](https://github.com/dylanaraps/pfetch/issues/5))
- [x] 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))
@@ -46,7 +76,7 @@ _/\ __)/_) pkgs 130
- [ ] CYGWIN
- [ ] MSYS
- [ ] MINGW
- [ ] WSL (*this is fairly simple*)
- [x] WSL (*this is fairly simple*)
## Configuration
@@ -58,14 +88,14 @@ _/\ __)/_) pkgs 130
# Default: first example below
# Valid: space separated string
#
# OFF by default: shell
PF_INFO="ascii title distro host kernel uptime pkgs memory"
# OFF by default: shell palette
PF_INFO="ascii title os host kernel uptime pkgs memory"
# Example: Only ASCII.
PF_INFO="ascii"
# Example: Only Information.
PF_INFO="title distro host kernel uptime pkgs memory"
PF_INFO="title os host kernel uptime pkgs memory"
# Separator between info name and info data.
# Default: unset

280
pfetch
View File

@@ -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
# whitespace inside of the string.
# white-space 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\n' "${PF_COL2-7}" "$info"
# Keep track of the number of times 'log()' has been run.
: $((info_height+=1))
info_height=$((${info_height:-0} + 1))
}
get_title() {
# Username is retrieved by first checking '$USER' with a fallback
# to the 'whoami' command.
user=${USER:-$(whoami)}
# to the 'id -un' command.
user=${USER:-$(id -un)}
# Hostname is retrieved by first checking '$HOSTNAME' with a fallback
# to the 'hostname' command.
@@ -155,16 +155,39 @@ get_os() {
distro=$(lsb_release -sd)
else
# 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
# 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
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'
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"
;;
Darwin*)
@@ -215,8 +238,22 @@ get_os() {
Haiku)
# Haiku uses 'uname -v' for version information
# instead of 'uname -r'.
distro="Haiku $(uname -v)"
# 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
;;
*)
@@ -231,7 +268,7 @@ get_kernel() {
case $os in
# Don't print kernel output on some systems as the
# OS name includes it.
*BSD*|Haiku) ;;
*BSD*|Haiku|Minix) ;;
*)
# '$kernel' is the cached output of 'uname -r'.
@@ -257,7 +294,7 @@ get_host() {
host="$name $version $model"
;;
Darwin*|FreeBSD*)
Darwin*|FreeBSD*|DragonFly*)
host=$(sysctl -n hw.model)
;;
@@ -318,11 +355,11 @@ get_uptime() {
# converting that data into days, hours and minutes using simple
# math.
case $os in
Linux*)
Linux*|Minix*)
IFS=. read -r s _ < /proc/uptime
;;
Darwin*|*BSD*)
Darwin*|*BSD*|DragonFly*)
s=$(sysctl -n kern.boottime)
# Extract the uptime in seconds from the following output:
@@ -340,6 +377,19 @@ 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.
@@ -356,6 +406,10 @@ 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.
@@ -376,27 +430,22 @@ get_pkgs() {
case $os in
Linux*)
# Commands which print packages one per line.
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
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
# Directories containing 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
}
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/*
# NIX requires two commands.
command -v nix-store && {
has nix-store && {
nix-store -q --requisites /run/current-system/sw
nix-store -q --requisites ~.nix-profile
}
@@ -404,14 +453,14 @@ get_pkgs() {
Darwin*)
# Commands which print packages one per line.
command -v pkgin && pkgin list
command -v port && port installed
has pkgin && pkgin list
has port && port installed
# Directories containing packages.
command -v brew && printf '%s\n' /usr/local/Cellar/*
has brew && printf '%s\n' /usr/local/Cellar/*
;;
FreeBSD*)
FreeBSD*|DragonFly*)
pkg info
;;
@@ -426,6 +475,15 @@ 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
`
@@ -434,14 +492,14 @@ get_pkgs() {
get_memory() {
case $os in
# Used memory is calculated using the following "formula" (Linux):
# Used memory is calculated using the following "formula":
# 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))
@@ -462,7 +520,7 @@ get_memory() {
mem_full=$((mem_full / 1024))
;;
# Used memory is calculated using the following "formula" (MacOS):
# Used memory is calculated using the following "formula":
# (wired + active + occupied) * 4 / 1024
Darwin*)
mem_full=$(($(sysctl -n hw.memsize) / 1024 / 1024))
@@ -512,9 +570,9 @@ get_memory() {
EOF
;;
# Used memory is calculated using the following "formula" (FreeBSD):
# (inactive_count + free_count + cache_count) * page_size / 1024
FreeBSD*)
# Used memory is calculated using the following "formula":
# mem_full - ((inactive + free + cache) * page_size / 1024)
FreeBSD*|DragonFly*)
mem_full=$(($(sysctl -n hw.physmem) / 1024 / 1024))
# Use 'set --' to store the output of the command in the
@@ -536,7 +594,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=$((($2 + $3 + $4) * $1 / 1024 / 1024))
mem_used=$((mem_full - (($2 + $3 + $4) * $1 / 1024 / 1024)))
;;
NetBSD*)
@@ -544,7 +602,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))
@@ -571,11 +629,55 @@ 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.
#
# This allows us to save hardcoding a second set of sequences
# for background colors.
palette=" $c1 $c2 $c3 $c4 $c5 $c6 $c7 "
# 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\n' "${ascii_width-1}" "$palette" >&6
}
get_ascii() {
# This is a simple function to read the contents of
# an ascii file from 'stdin'. It allows for the use
@@ -683,6 +785,18 @@ 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} _______
@@ -841,6 +955,19 @@ 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} \\\\ /
@@ -948,6 +1075,27 @@ 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} _______
@@ -984,8 +1132,12 @@ get_ascii() {
# information. The 'sed' is used to strip 'm' color codes from
# the ascii art so they don't affect the width variable.
while read -r line; do
: $((ascii_height+=1))
ascii_width=$((${#line} > ascii_width ? ${#line} : ascii_width))
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}
# Using '<<-EOF' is the only way to loop over a command's
# output without the use of a pipe ('|').
@@ -996,16 +1148,20 @@ get_ascii() {
EOF
# Add a gap between the ascii art and the information.
: $((ascii_width+=4))
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
# 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 '[?7l[?25l%s[%sA' "$ascii" "$ascii_height" >&6
printf '%s[%sA' "$ascii" "$ascii_height" >&6
}
main() {
@@ -1056,12 +1212,16 @@ main() {
# "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 &&
info_length=$((${#info} > info_length ? ${#info} : info_length))
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}
done
# Add an additional space of length to act as a gap.
: $((info_length+=1))
info_length=$((info_length + 1))
# Iterate over the above list and run any existing "get_" functions.
for info; do "get_$info"; done
@@ -1069,15 +1229,19 @@ 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, else move it down N lines.
cursor_pos=$((info_height > ascii_height ? 0 : ascii_height - info_height))
# 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))
# 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" ]; do
while [ "${i:=0}" -le "${cursor_pos:-0}" ]; do
printf '\n'
: $((i+=1))
i=$((i + 1))
done >&6
}