mirror of
https://github.com/dylanaraps/pfetch.git
synced 2026-01-02 16:02:12 +01:00
Compare commits
64 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
af166966b9 | ||
|
|
219d8f2117 | ||
|
|
0834d53b2a | ||
|
|
0f1d6845db | ||
|
|
3895dd003d | ||
|
|
6c3d5c3a87 | ||
|
|
616e1b0c3b | ||
|
|
44dca45301 | ||
|
|
256c1678d6 | ||
|
|
a3bdc11167 | ||
|
|
2bc0fd87a5 | ||
|
|
8b9c409650 | ||
|
|
52617b2e6e | ||
|
|
77dce6a678 | ||
|
|
812f9ef231 | ||
|
|
87effdbc5a | ||
|
|
3f5845e20c | ||
|
|
c94e2c5d9d | ||
|
|
d8d8899ad2 | ||
|
|
1ff17055b9 | ||
|
|
d1d3b7b740 | ||
|
|
9564246e6c | ||
|
|
08d9834854 | ||
|
|
b7c7bc6c4c | ||
|
|
11d1c2e789 | ||
|
|
55408239db | ||
|
|
35ae795068 | ||
|
|
e1228975fd | ||
|
|
4d1be75c20 | ||
|
|
8d1ab2d0dd | ||
|
|
301c52dd5f | ||
|
|
0d1a340ef2 | ||
|
|
49a3db1653 | ||
|
|
d828d1e718 | ||
|
|
9963de75d5 | ||
|
|
3e58031fe0 | ||
|
|
405fc20eef | ||
|
|
133d63137c | ||
|
|
3686c06238 | ||
|
|
c20823937c | ||
|
|
177f30b72f | ||
|
|
aea34f832c | ||
|
|
6829866ba9 | ||
|
|
f7180ec8a7 | ||
|
|
777a64b4b1 | ||
|
|
765dc077e7 | ||
|
|
2e3da189ca | ||
|
|
344086b464 | ||
|
|
e0b082423f | ||
|
|
66e0bfe709 | ||
|
|
c97120b82f | ||
|
|
46b68022a3 | ||
|
|
146c6b6bae | ||
|
|
d8becf6692 | ||
|
|
887df06b6a | ||
|
|
a6b4b085fb | ||
|
|
cfc0e8e4d0 | ||
|
|
29b09c8622 | ||
|
|
6c2ffdd07e | ||
|
|
8974dad27a | ||
|
|
9442360c09 | ||
|
|
ee265316d9 | ||
|
|
442a2ba217 | ||
|
|
120e8a8760 |
2
.github/workflows/main.yml
vendored
2
.github/workflows/main.yml
vendored
@@ -8,4 +8,4 @@ jobs:
|
|||||||
- name: Run shellcheck.
|
- name: Run shellcheck.
|
||||||
run: |
|
run: |
|
||||||
shellcheck pfetch
|
shellcheck pfetch
|
||||||
sh pfetch
|
TERM=dumb sh pfetch
|
||||||
|
|||||||
124
README.md
124
README.md
@@ -1,82 +1,42 @@
|
|||||||
# pfetch
|
<p align="center"><img src="https://user-images.githubusercontent.com/6799467/65944518-68834d80-e421-11e9-9b14-6ca26a16108a.png" width="350px"></p>
|
||||||
|
<h1 align="center">pfetch</h1>
|
||||||
|
<p align="center">A pretty system information tool written in POSIX sh</p><br>
|
||||||
|
|
||||||
A pretty system information tool written in POSIX `sh`.
|
<img src="https://user-images.githubusercontent.com/6799467/65945384-5bfff480-e423-11e9-863e-4e7cf16eb648.png" width="40%" align="right">
|
||||||
|
|
||||||
The goal of this project is to implement a simple system information tool in POSIX `sh` using features built into the language itself (*where possible*).
|
The goal of this project is to implement a simple system
|
||||||
|
information tool in POSIX `sh` using features built into
|
||||||
|
the language itself (*where possible*).
|
||||||
|
|
||||||
The source code is highly documented and I hope it will act as a learning resource for POSIX `sh` and simple information detection across various different operating systems.
|
The source code is highly documented and I hope it will
|
||||||
|
act as a learning resource for POSIX `sh` and simple
|
||||||
|
information detection across various different operating
|
||||||
|
systems.
|
||||||
|
|
||||||
If anything in the source code is unclear or is lacking in its explanation, open an issue. Sometimes you get too close to something and you fail to see the "bigger picture"!
|
If anything in the source code is unclear or is lacking
|
||||||
|
in its explanation, open an issue. Sometimes you get too
|
||||||
|
close to something and you fail to see the "bigger
|
||||||
|
picture"!
|
||||||
|
|
||||||
```sh
|
<br>
|
||||||
➜ pfetch
|
<br>
|
||||||
___ goldie@KISS
|
<br>
|
||||||
(.· | os KISS Linux
|
<br>
|
||||||
(<> | host Lenovo YOGA 900-13ISK
|
|
||||||
/ __ \ kernel 5.3.1-coffee
|
|
||||||
( / \ /| uptime 6h 20m
|
|
||||||
_/\ __)/_) pkgs 130
|
|
||||||
\/-____\/ memory 1721M / 7942M
|
|
||||||
```
|
|
||||||
|
|
||||||
## OS support
|
## OS support
|
||||||
|
|
||||||
- Linux
|
- **Linux**
|
||||||
- Alpine 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 and Void Linux.
|
||||||
- Arch Linux
|
- All other distributions are supported with a generic penguin logo.
|
||||||
- Arco Linux
|
- **Android**
|
||||||
- Artix Linux
|
- **BSD**
|
||||||
- CentOS
|
- DragonflyBSD, FreeBSD, NetBSD and OpenBSD.
|
||||||
- Debian
|
- **Windows**
|
||||||
- Elementary
|
- Windows subsystem for Linux.
|
||||||
- Fedora
|
- **Haiku**
|
||||||
- Gentoo
|
- **MacOS**
|
||||||
- Guix
|
- **Minix**
|
||||||
- Hyperbola
|
- **Solaris**
|
||||||
- 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 ([#12](https://github.com/dylanaraps/pfetch/pull/12))
|
|
||||||
- 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))
|
|
||||||
- [ ] ???
|
|
||||||
- [ ] Expand operating system support.
|
|
||||||
- [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))
|
|
||||||
- [ ] Windows ([#10](https://github.com/dylanaraps/pfetch/issues/10))
|
|
||||||
- [ ] CYGWIN
|
|
||||||
- [ ] MSYS
|
|
||||||
- [ ] MINGW
|
|
||||||
- [x] WSL (*this is fairly simple*)
|
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
@@ -88,7 +48,7 @@ _/\ __)/_) pkgs 130
|
|||||||
# Default: first example below
|
# Default: first example below
|
||||||
# Valid: space separated string
|
# Valid: space separated string
|
||||||
#
|
#
|
||||||
# OFF by default: shell palette
|
# OFF by default: shell editor wm de palette
|
||||||
PF_INFO="ascii title os host kernel uptime pkgs memory"
|
PF_INFO="ascii title os host kernel uptime pkgs memory"
|
||||||
|
|
||||||
# Example: Only ASCII.
|
# Example: Only ASCII.
|
||||||
@@ -126,6 +86,26 @@ PF_ALIGN=""
|
|||||||
# Default: unset (auto)
|
# Default: unset (auto)
|
||||||
# Valid: string
|
# Valid: string
|
||||||
PF_ASCII="openbsd"
|
PF_ASCII="openbsd"
|
||||||
|
|
||||||
|
# The below environment variables control more
|
||||||
|
# than just 'pfetch' and can be passed using
|
||||||
|
# 'HOSTNAME=cool_pc pfetch' to restrict their
|
||||||
|
# usage solely to 'pfetch'.
|
||||||
|
|
||||||
|
# Which user to display.
|
||||||
|
USER=""
|
||||||
|
|
||||||
|
# Which hostname to display.
|
||||||
|
HOSTNAME=""
|
||||||
|
|
||||||
|
# Which editor to display.
|
||||||
|
EDITOR=""
|
||||||
|
|
||||||
|
# Which shell to display.
|
||||||
|
SHELL=""
|
||||||
|
|
||||||
|
# Which desktop environment to display.
|
||||||
|
XDG_CURRENT_DESKTOP=""
|
||||||
```
|
```
|
||||||
|
|
||||||
## Credit
|
## Credit
|
||||||
|
|||||||
328
pfetch
328
pfetch
@@ -129,7 +129,7 @@ get_os() {
|
|||||||
|
|
||||||
case $os in
|
case $os in
|
||||||
Linux*)
|
Linux*)
|
||||||
# Some Linux disttributions (which are based on others)
|
# Some Linux distributions (which are based on others)
|
||||||
# fail to identify as they **do not** change the upstream
|
# fail to identify as they **do not** change the upstream
|
||||||
# distributions identification packages or files.
|
# distributions identification packages or files.
|
||||||
#
|
#
|
||||||
@@ -154,9 +154,15 @@ get_os() {
|
|||||||
if command -v lsb_release; then
|
if command -v lsb_release; then
|
||||||
distro=$(lsb_release -sd)
|
distro=$(lsb_release -sd)
|
||||||
|
|
||||||
|
# Android detection works by checking for the existence of
|
||||||
|
# the follow two directories. I don't think there's a simpler
|
||||||
|
# method than this.
|
||||||
|
elif [ -d /system/app ] && [ -d /system/priv-app ]; then
|
||||||
|
distro="Android $(getprop ro.build.version.release)"
|
||||||
|
|
||||||
else
|
else
|
||||||
# This used to be a simple '. /etc/os-release' but I believe
|
# This used to be a simple '. /etc/os-release' but I believe
|
||||||
# this is insecure as we blindly execute whatever is in the
|
# this is insecure as we blindly executed whatever was in the
|
||||||
# file. This parser instead simply handles 'key=val', treating
|
# file. This parser instead simply handles 'key=val', treating
|
||||||
# the file contents as plain-text.
|
# the file contents as plain-text.
|
||||||
while IFS='=' read -r key val; do
|
while IFS='=' read -r key val; do
|
||||||
@@ -177,17 +183,22 @@ get_os() {
|
|||||||
command -v guix && distro='Guix System'
|
command -v guix && distro='Guix System'
|
||||||
|
|
||||||
# Check to see if Linux is running in Windows 10 under
|
# Check to see if Linux is running in Windows 10 under
|
||||||
# WSL (Windows subsystem for Linux) and append a string
|
# WSL1 (Windows subsystem for Linux [version 1]) and
|
||||||
# accordingly.
|
# append a string accordingly.
|
||||||
#
|
#
|
||||||
# If the kernel version string ends in "-Microsoft",
|
# If the kernel version string ends in "-Microsoft",
|
||||||
# we're very likely running under Windows 10 in WSL.
|
# we're very likely running under Windows 10 in WSL1.
|
||||||
#
|
|
||||||
# This also acts as a means of allowing the user to
|
|
||||||
# fake this by changing their kernel version to end in
|
|
||||||
# "Microsoft".
|
|
||||||
[ "${kernel%%*-Microsoft}" ] ||
|
[ "${kernel%%*-Microsoft}" ] ||
|
||||||
distro="$distro on Windows 10"
|
distro="$distro on Windows 10 [WSL1]"
|
||||||
|
|
||||||
|
# Check to see if Linux is running in Windows 10 under
|
||||||
|
# WSL2 (Windows subsystem for Linux [version 2]) and
|
||||||
|
# append a string accordingly.
|
||||||
|
#
|
||||||
|
# This checks to see if '$WSLENV' is defined. This
|
||||||
|
# appends the Windows 10 string even if '$WSLENV' is
|
||||||
|
# empty. We only need to check that is has been _exported_.
|
||||||
|
distro="${distro}${WSLENV+ on Windows 10 [WSL2]}"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
Darwin*)
|
Darwin*)
|
||||||
@@ -277,10 +288,6 @@ get_kernel() {
|
|||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
get_shell() {
|
|
||||||
log shell "${SHELL##*/}" >&6
|
|
||||||
}
|
|
||||||
|
|
||||||
get_host() {
|
get_host() {
|
||||||
case $os in
|
case $os in
|
||||||
Linux*)
|
Linux*)
|
||||||
@@ -338,7 +345,7 @@ get_host() {
|
|||||||
case $word in
|
case $word in
|
||||||
To | [Bb]e | [Ff]illed | by | O.E.M. | OEM |\
|
To | [Bb]e | [Ff]illed | by | O.E.M. | OEM |\
|
||||||
Not | Applicable | Specified | System | Product | Name |\
|
Not | Applicable | Specified | System | Product | Name |\
|
||||||
Version | Undefined | Default | string | INVALID | <20> )
|
Version | Undefined | Default | string | INVALID | <20> | os )
|
||||||
continue
|
continue
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@@ -431,6 +438,7 @@ get_pkgs() {
|
|||||||
Linux*)
|
Linux*)
|
||||||
# Commands which print packages one per line.
|
# Commands which print packages one per line.
|
||||||
has bonsai && bonsai list
|
has bonsai && bonsai list
|
||||||
|
has crux && pkginfo -i
|
||||||
has pacman-key && pacman -Qq
|
has pacman-key && pacman -Qq
|
||||||
has dpkg && dpkg-query -f '.\n' -W
|
has dpkg && dpkg-query -f '.\n' -W
|
||||||
has rpm && rpm -qa
|
has rpm && rpm -qa
|
||||||
@@ -444,7 +452,7 @@ get_pkgs() {
|
|||||||
has emerge && printf '%s\n' /var/db/pkg/*/*/
|
has emerge && printf '%s\n' /var/db/pkg/*/*/
|
||||||
has pkgtool && printf '%s\n' /var/log/packages/*
|
has pkgtool && printf '%s\n' /var/log/packages/*
|
||||||
|
|
||||||
# NIX requires two commands.
|
# 'nix' requires two commands.
|
||||||
has nix-store && {
|
has nix-store && {
|
||||||
nix-store -q --requisites /run/current-system/sw
|
nix-store -q --requisites /run/current-system/sw
|
||||||
nix-store -q --requisites ~.nix-profile
|
nix-store -q --requisites ~.nix-profile
|
||||||
@@ -454,10 +462,24 @@ get_pkgs() {
|
|||||||
Darwin*)
|
Darwin*)
|
||||||
# Commands which print packages one per line.
|
# Commands which print packages one per line.
|
||||||
has pkgin && pkgin list
|
has pkgin && pkgin list
|
||||||
has port && port installed
|
|
||||||
|
|
||||||
# Directories containing packages.
|
# Directories containing packages.
|
||||||
has brew && printf '%s\n' /usr/local/Cellar/*
|
has brew && printf '%s\n' /usr/local/Cellar/*
|
||||||
|
|
||||||
|
# 'port' prints a single line of output to 'stdout'
|
||||||
|
# when no packages are installed and exits with
|
||||||
|
# success causing a false-positive of 1 package
|
||||||
|
# installed.
|
||||||
|
#
|
||||||
|
# 'port' should really exit with a non-zero code
|
||||||
|
# in this case to allow scripts to cleanly handle
|
||||||
|
# this behavior.
|
||||||
|
has port && {
|
||||||
|
pkg_list=$(port installed)
|
||||||
|
|
||||||
|
[ "$pkg_list" = "No ports are installed." ] ||
|
||||||
|
printf '%s\n' "$pkg_list"
|
||||||
|
}
|
||||||
;;
|
;;
|
||||||
|
|
||||||
FreeBSD*|DragonFly*)
|
FreeBSD*|DragonFly*)
|
||||||
@@ -487,7 +509,7 @@ get_pkgs() {
|
|||||||
esac | wc -l
|
esac | wc -l
|
||||||
`
|
`
|
||||||
|
|
||||||
log pkgs "${packages:-?}" >&6
|
[ "$packages" -gt 1 ] && log pkgs "$packages" >&6
|
||||||
}
|
}
|
||||||
|
|
||||||
get_memory() {
|
get_memory() {
|
||||||
@@ -530,7 +552,7 @@ get_memory() {
|
|||||||
# split is used on '.' to filter it out.
|
# split is used on '.' to filter it out.
|
||||||
while IFS=:. read -r key val; do
|
while IFS=:. read -r key val; do
|
||||||
case $key in
|
case $key in
|
||||||
*wired*|*active*|*occupied*)
|
*' wired'*|*' active'*|*' occupied'*)
|
||||||
mem_used=$((mem_used + ${val:-0}))
|
mem_used=$((mem_used + ${val:-0}))
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@@ -644,6 +666,15 @@ get_memory() {
|
|||||||
SunOS)
|
SunOS)
|
||||||
hw_pagesize=$(pagesize)
|
hw_pagesize=$(pagesize)
|
||||||
|
|
||||||
|
# 'kstat' outputs memory in the following format:
|
||||||
|
# unix:0:system_pages:pagestotal 1046397
|
||||||
|
# unix:0:system_pages:pagesfree 885018
|
||||||
|
#
|
||||||
|
# This simply uses the first "element" (white-space
|
||||||
|
# separated) as the key and the second element as the
|
||||||
|
# value.
|
||||||
|
#
|
||||||
|
# A variable is then assigned based on the key.
|
||||||
while read -r key val; do
|
while read -r key val; do
|
||||||
case $key in
|
case $key in
|
||||||
*total) pages_full=$val ;;
|
*total) pages_full=$val ;;
|
||||||
@@ -663,6 +694,185 @@ get_memory() {
|
|||||||
log memory "${mem_used:-?}M / ${mem_full:-?}M" >&6
|
log memory "${mem_used:-?}M / ${mem_full:-?}M" >&6
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get_disk() {
|
||||||
|
# Store the version of the 'df' command as the available
|
||||||
|
# flags, options and implementation differs between operating
|
||||||
|
# systems and we need to handle these edge-cases.
|
||||||
|
df_version=$(df --version 2>&1)
|
||||||
|
|
||||||
|
case $df_version in
|
||||||
|
# The 'df' command is from AIX.
|
||||||
|
*IMitv*)
|
||||||
|
set -- -P -g
|
||||||
|
;;
|
||||||
|
|
||||||
|
# The 'df' command is from IRIX.
|
||||||
|
*befhikm*)
|
||||||
|
set -- -P -k
|
||||||
|
;;
|
||||||
|
|
||||||
|
# The 'df' command is from OpenBSD.
|
||||||
|
*hiklnP*)
|
||||||
|
set -- -h
|
||||||
|
;;
|
||||||
|
|
||||||
|
# The 'df' command is from Haiku and is wildly
|
||||||
|
# different and provides no workable output,
|
||||||
|
# end here.
|
||||||
|
*Tracker*) # Haiku
|
||||||
|
return
|
||||||
|
;;
|
||||||
|
|
||||||
|
# From testing it is saffe to assume that
|
||||||
|
# any other 'df' version provides these flags.
|
||||||
|
*)
|
||||||
|
set -- -P -h
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
# Read the output of 'df' line by line. The first line
|
||||||
|
# contains header information for the "table" so it is
|
||||||
|
# skipped.
|
||||||
|
#
|
||||||
|
# The next lines are then split to grab the relevant
|
||||||
|
# information and thankfully the output remains the
|
||||||
|
# same between all but one 'df' implementation.
|
||||||
|
#
|
||||||
|
# TODO: Configure disks to send to 'df'. Do we need to
|
||||||
|
# do this? I'd love to _not_ do it.
|
||||||
|
df "$@" / | while read -r name full used _ perc _; do
|
||||||
|
[ "$header" ] || { header=1; continue; }
|
||||||
|
|
||||||
|
case $df_version in
|
||||||
|
# The 'df' command is from IRIX.
|
||||||
|
*befhikm*)
|
||||||
|
used=$((used/1024/1024))G
|
||||||
|
full=$((full/1024/1024))G
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
log disk "$name [$used / $full ($perc)]" >&6
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
get_wm() {
|
||||||
|
case $os in
|
||||||
|
# Don't display window manager on macOS.
|
||||||
|
Darwin*) ;;
|
||||||
|
|
||||||
|
*)
|
||||||
|
# xprop can be used to grab the window manager's properties
|
||||||
|
# which contains the window manager's name under '_NET_WM_NAME'.
|
||||||
|
#
|
||||||
|
# The upside to using 'xprop' is that you don't need to hardcode
|
||||||
|
# a list of known window manager names. The downside is that
|
||||||
|
# not all window managers conform to setting the '_NET_WM_NAME'
|
||||||
|
# atom..
|
||||||
|
#
|
||||||
|
# List of window managers which fail to set the name atom:
|
||||||
|
# catwm, fvwm, dwm, 2bwm and monster.
|
||||||
|
#
|
||||||
|
# The final downside to this approach is that it does _not_
|
||||||
|
# support Wayland environments. The only solution which supports
|
||||||
|
# Wayland is the 'ps' parsing mentioned below.
|
||||||
|
#
|
||||||
|
# A more naive implementation is to parse the last line of
|
||||||
|
# '~/.xinitrc' to extract the second white-space separated
|
||||||
|
# element.
|
||||||
|
#
|
||||||
|
# The issue with an approach like this is that this line data
|
||||||
|
# does not always equate to the name of the window manager and
|
||||||
|
# could in theory be _anything_.
|
||||||
|
#
|
||||||
|
# This also fails when the user launches xorg through a display
|
||||||
|
# manager or other means.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Another naive solution is to parse 'ps' with a hardcoded list
|
||||||
|
# of window managers to detect the current window manager (based
|
||||||
|
# on what is running).
|
||||||
|
#
|
||||||
|
# The issue with this approach is the need to hardcode and
|
||||||
|
# maintain a list of known window managers.
|
||||||
|
#
|
||||||
|
# Another issue is that process names do not always equate to
|
||||||
|
# the name of the window manager. False-positives can happen too.
|
||||||
|
#
|
||||||
|
# This is the only solution which supports Wayland based
|
||||||
|
# environments sadly. It'd be nice if some kind of standard were
|
||||||
|
# established to identify Wayland environments.
|
||||||
|
#
|
||||||
|
# pfetch's goal is to remain _simple_, if you'd like a "full"
|
||||||
|
# implementation of window manager detection use 'neofetch'.
|
||||||
|
#
|
||||||
|
# Neofetch use a combination of 'xprop' and 'ps' parsing to
|
||||||
|
# support all window managers (including non-conforming and
|
||||||
|
# Wayland) though it's a lot more complicated!
|
||||||
|
|
||||||
|
# Don't display window manager if X isn't running.
|
||||||
|
[ "$DISPLAY" ] || return
|
||||||
|
|
||||||
|
# This is a two pass call to xprop. One call to get the window
|
||||||
|
# manager's ID and another to print its properties.
|
||||||
|
command -v xprop && {
|
||||||
|
# The output of the ID command is as follows:
|
||||||
|
# _NET_SUPPORTING_WM_CHECK: window id # 0x400000
|
||||||
|
#
|
||||||
|
# To extract the ID, everything before the last space
|
||||||
|
# is removed.
|
||||||
|
id=$(xprop -root -notype _NET_SUPPORTING_WM_CHECK)
|
||||||
|
id=${id##* }
|
||||||
|
|
||||||
|
# The output of the property command is as follows:
|
||||||
|
# _NAME 8t
|
||||||
|
# _NET_WM_PID = 252
|
||||||
|
# _NET_WM_NAME = "bspwm"
|
||||||
|
# _NET_SUPPORTING_WM_CHECK: window id # 0x400000
|
||||||
|
# WM_CLASS = "wm", "Bspwm"
|
||||||
|
#
|
||||||
|
# To extract the name, everything before '_NET_WM_NAME = \"'
|
||||||
|
# is removed and everything after the next '"' is removed.
|
||||||
|
wm=$(xprop -id "$id" -notype -len 25 -f _NET_WM_NAME 8t)
|
||||||
|
|
||||||
|
# Handle cases of a window manager _not_ populating the
|
||||||
|
# '_NET_WM_NAME' atom. Display nothing in this case.
|
||||||
|
case $wm in
|
||||||
|
*'_NET_WM_NAME = '*)
|
||||||
|
wm=${wm##*_NET_WM_NAME = \"}
|
||||||
|
wm=${wm%%\"*}
|
||||||
|
;;
|
||||||
|
|
||||||
|
*) wm= ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
log wm "$wm" >&6
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
get_de() {
|
||||||
|
# This only supports Xorg related desktop environments though
|
||||||
|
# this is fine as knowing the desktop envrionment on Windows,
|
||||||
|
# macOS etc is useless (they'll always report the same value).
|
||||||
|
#
|
||||||
|
# Display the value of '$XDG_CURRENT_DESKTOP', if it's empty,
|
||||||
|
# display the value of '$DESKTOP_SESSION'.
|
||||||
|
log de "${XDG_CURRENT_DESKTOP:-$DESKTOP_SESSION}" >&6
|
||||||
|
}
|
||||||
|
|
||||||
|
get_shell() {
|
||||||
|
# Display the basename of the '$SHELL' environment variable.
|
||||||
|
log shell "${SHELL##*/}" >&6
|
||||||
|
}
|
||||||
|
|
||||||
|
get_editor() {
|
||||||
|
# Display the value of '$VISUAL', if it's empty, display the
|
||||||
|
# value of '$EDITOR'.
|
||||||
|
log editor "${VISUAL:-$EDITOR}" >&6
|
||||||
|
}
|
||||||
|
|
||||||
get_palette() {
|
get_palette() {
|
||||||
# Print the first 8 terminal colors. This uses the existing
|
# Print the first 8 terminal colors. This uses the existing
|
||||||
# sequences to change text color with a sequence prepended
|
# sequences to change text color with a sequence prepended
|
||||||
@@ -726,15 +936,26 @@ get_ascii() {
|
|||||||
EOF
|
EOF
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
[Aa]ndroid*)
|
||||||
|
read_ascii 2 <<-EOF
|
||||||
|
${c2} ;, ,;
|
||||||
|
';,.-----.,;'
|
||||||
|
,' ',
|
||||||
|
/ O O \\
|
||||||
|
| |
|
||||||
|
'-----------------'
|
||||||
|
EOF
|
||||||
|
;;
|
||||||
|
|
||||||
[Aa]rch*)
|
[Aa]rch*)
|
||||||
read_ascii 4 <<-EOF
|
read_ascii 4 <<-EOF
|
||||||
${c6} /\\
|
${c6} /\\
|
||||||
/^^\\
|
/ \\
|
||||||
/\\ \\
|
/\\ \\
|
||||||
/${c7} __ \\
|
${c4} / \\
|
||||||
/ ( ) \\
|
/ ,, \\
|
||||||
/ __| |__\\\\
|
/ | | -\\
|
||||||
/// \\\\\\
|
/_-'' ''-_\\
|
||||||
EOF
|
EOF
|
||||||
;;
|
;;
|
||||||
|
|
||||||
@@ -823,13 +1044,12 @@ get_ascii() {
|
|||||||
|
|
||||||
[Ff]ree[Bb][Ss][Dd]*)
|
[Ff]ree[Bb][Ss][Dd]*)
|
||||||
read_ascii 1 <<-EOF
|
read_ascii 1 <<-EOF
|
||||||
${c1} /\\ _____ /\\
|
${c1}/\\,-'''''-,/\\
|
||||||
\\_) (_/
|
\\_) (_/
|
||||||
/ \\
|
|
||||||
| |
|
| |
|
||||||
| |
|
| |
|
||||||
\ /
|
; ;
|
||||||
--_____--
|
'-_____-'
|
||||||
EOF
|
EOF
|
||||||
;;
|
;;
|
||||||
|
|
||||||
@@ -845,7 +1065,7 @@ get_ascii() {
|
|||||||
EOF
|
EOF
|
||||||
;;
|
;;
|
||||||
|
|
||||||
[Gg]uix[Ss][Dd]*|guix*)
|
[Gg]uix[Ss][Dd]*|[Gg]uix*)
|
||||||
read_ascii 3 <<-EOF
|
read_ascii 3 <<-EOF
|
||||||
${c3}|.__ __.|
|
${c3}|.__ __.|
|
||||||
|__ \\ / __|
|
|__ \\ / __|
|
||||||
@@ -882,7 +1102,7 @@ get_ascii() {
|
|||||||
EOF
|
EOF
|
||||||
;;
|
;;
|
||||||
|
|
||||||
[Ll]inux*[Ll]ite*)
|
[Ll]inux*[Ll]ite*|[Ll]ite*)
|
||||||
read_ascii 3 <<-EOF
|
read_ascii 3 <<-EOF
|
||||||
${c3} /\\
|
${c3} /\\
|
||||||
/ \\
|
/ \\
|
||||||
@@ -1016,7 +1236,7 @@ get_ascii() {
|
|||||||
EOF
|
EOF
|
||||||
;;
|
;;
|
||||||
|
|
||||||
openSUSE*|open*SUSE*|SUSE*|suse*)
|
[Oo]penSUSE*|[Oo]pen*SUSE*|SUSE*|suse*)
|
||||||
read_ascii 2 <<-EOF
|
read_ascii 2 <<-EOF
|
||||||
${c2} _______
|
${c2} _______
|
||||||
__| __ \\
|
__| __ \\
|
||||||
@@ -1075,7 +1295,7 @@ get_ascii() {
|
|||||||
EOF
|
EOF
|
||||||
;;
|
;;
|
||||||
|
|
||||||
[Ss]un[Oo][Ss])
|
[Ss]un[Oo][Ss]|[Ss]olaris*)
|
||||||
read_ascii 3 <<-EOF
|
read_ascii 3 <<-EOF
|
||||||
${c3} . .; .
|
${c3} . .; .
|
||||||
. :; :: ;: .
|
. :; :: ;: .
|
||||||
@@ -1143,19 +1363,17 @@ get_ascii() {
|
|||||||
# output without the use of a pipe ('|').
|
# output without the use of a pipe ('|').
|
||||||
# This ensures that any variables defined in the while loop
|
# This ensures that any variables defined in the while loop
|
||||||
# are still accessible in the script.
|
# are still accessible in the script.
|
||||||
|
#
|
||||||
|
# The 'awk' command below used to be a simple 'sed', however
|
||||||
|
# some versions of Android shipped with a totally broken 'sed'
|
||||||
|
# command from 'toybox' and so we're forced to avoid 'sed'.
|
||||||
done <<-EOF
|
done <<-EOF
|
||||||
$(printf %s "$ascii" | sed 's/\[3.m//g')
|
$(printf %s "$ascii" | awk '{gsub("\\[3.m","");print}')
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
# Add a gap between the ascii art and the information.
|
# Add a gap between the ascii art and the information.
|
||||||
ascii_width=$((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
|
# Print the ascii art and position the cursor back where we
|
||||||
# started prior to printing it.
|
# started prior to printing it.
|
||||||
# '[1m': Print the ascii in bold.
|
# '[1m': Print the ascii in bold.
|
||||||
@@ -1165,11 +1383,6 @@ get_ascii() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
# Leave the terminal how we found it on exit or Ctrl+C.
|
|
||||||
# '[?7h': Enable line-wrapping.
|
|
||||||
# '[?25h': Un-hide the cursor.
|
|
||||||
trap 'printf [?7h[?25h >&6' EXIT
|
|
||||||
|
|
||||||
# Hide 'stderr' unless the first argument is '-v'. This saves
|
# Hide 'stderr' unless the first argument is '-v'. This saves
|
||||||
# polluting the script with '2>/dev/null'.
|
# polluting the script with '2>/dev/null'.
|
||||||
[ "$1" = -v ] || exec 2>/dev/null
|
[ "$1" = -v ] || exec 2>/dev/null
|
||||||
@@ -1178,6 +1391,11 @@ main() {
|
|||||||
# This gives full control over what it displayed on the screen.
|
# This gives full control over what it displayed on the screen.
|
||||||
exec 6>&1 >/dev/null
|
exec 6>&1 >/dev/null
|
||||||
|
|
||||||
|
# Ensure that the 'TMPDIR' is writable as heredocs use it and
|
||||||
|
# fail without the write permission. This was found to be the
|
||||||
|
# case on Android where the temporary directory requires root.
|
||||||
|
[ -w "${TMPDIR:-/tmp}" ] || export TMPDIR=~
|
||||||
|
|
||||||
# Generic color list.
|
# Generic color list.
|
||||||
# Disable warning about unused variables.
|
# Disable warning about unused variables.
|
||||||
# shellcheck disable=2034
|
# shellcheck disable=2034
|
||||||
@@ -1188,6 +1406,26 @@ main() {
|
|||||||
c7='[37m'; c8='[38m'
|
c7='[37m'; c8='[38m'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Avoid text-wrapping from wrecking the program output
|
||||||
|
# and hide the cursor to hide its moving around during
|
||||||
|
# the printing process.
|
||||||
|
#
|
||||||
|
# Some terminals don't support these sequences, nor do they
|
||||||
|
# silently conceal them if they're printed resulting in
|
||||||
|
# partial sequences being printed to the terminal!
|
||||||
|
[ "$TERM" = dumb ] ||
|
||||||
|
[ "$TERM" = minix ] ||
|
||||||
|
[ "$TERM" = cons25 ] || {
|
||||||
|
# '[?7l': Disable line-wrapping.
|
||||||
|
# '[?25l': Hide the cursor.
|
||||||
|
printf '[?7l[?25l' >&6
|
||||||
|
|
||||||
|
# Leave the terminal how we found it on exit or Ctrl+C.
|
||||||
|
# '[?7h': Enable line-wrapping.
|
||||||
|
# '[?25h': Show the cursor.
|
||||||
|
trap 'printf [?7h[?25h >&6' EXIT
|
||||||
|
}
|
||||||
|
|
||||||
# Store the output of 'uname' to avoid calling it multiple times
|
# Store the output of 'uname' to avoid calling it multiple times
|
||||||
# throughout the script. 'read <<EOF' is the simplest way of reading
|
# throughout the script. 'read <<EOF' is the simplest way of reading
|
||||||
# a command into a list of variables.
|
# a command into a list of variables.
|
||||||
@@ -1233,7 +1471,7 @@ main() {
|
|||||||
# N lines.
|
# N lines.
|
||||||
#
|
#
|
||||||
# This was a ternary operation but they aren't supported in Minix's shell.
|
# This was a ternary operation but they aren't supported in Minix's shell.
|
||||||
[ "$info_height" -lt "$ascii_height" ] &&
|
[ "${info_height:-0}" -lt "${ascii_height:-0}" ] &&
|
||||||
cursor_pos=$((ascii_height - info_height))
|
cursor_pos=$((ascii_height - info_height))
|
||||||
|
|
||||||
# Print '$cursor_pos' amount of newlines to correctly position the
|
# Print '$cursor_pos' amount of newlines to correctly position the
|
||||||
|
|||||||
Reference in New Issue
Block a user