mirror of
https://github.com/dylanaraps/pfetch.git
synced 2026-01-02 16:02:12 +01:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1b37bf9dd2 | ||
|
|
eb9c8a3cfe | ||
|
|
59340ff4ce | ||
|
|
68d2422a1b | ||
|
|
55b78b9e58 | ||
|
|
b7292e0cbc | ||
|
|
ba03cb3cf4 | ||
|
|
d91cd1c0bf |
@@ -32,9 +32,10 @@ _/\ __)/_) pkgs 130
|
|||||||
|
|
||||||
- [ ] Add optional and additional information detection.
|
- [ ] Add optional and additional information detection.
|
||||||
- [ ] CPU
|
- [ ] CPU
|
||||||
- [ ] Terminal Emulator
|
- [ ] Terminal Emulator ([#12](https://github.com/dylanaraps/pfetch/pull/12))
|
||||||
- The way I implement this in `neofetch` is interesting.
|
- 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.
|
- [ ] Expand operating system support.
|
||||||
- [ ] Solaris ([#5](https://github.com/dylanaraps/pfetch/issues/5))
|
- [ ] Solaris ([#5](https://github.com/dylanaraps/pfetch/issues/5))
|
||||||
@@ -46,7 +47,7 @@ _/\ __)/_) pkgs 130
|
|||||||
- [ ] CYGWIN
|
- [ ] CYGWIN
|
||||||
- [ ] MSYS
|
- [ ] MSYS
|
||||||
- [ ] MINGW
|
- [ ] MINGW
|
||||||
- [ ] WSL (*this is fairly simple*)
|
- [x] WSL (*this is fairly simple*)
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
|
||||||
@@ -58,7 +59,7 @@ _/\ __)/_) pkgs 130
|
|||||||
# Default: first example below
|
# Default: first example below
|
||||||
# Valid: space separated string
|
# Valid: space separated string
|
||||||
#
|
#
|
||||||
# OFF by default: shell
|
# OFF by default: shell palette
|
||||||
PF_INFO="ascii title distro host kernel uptime pkgs memory"
|
PF_INFO="ascii title distro host kernel uptime pkgs memory"
|
||||||
|
|
||||||
# Example: Only ASCII.
|
# Example: Only ASCII.
|
||||||
|
|||||||
190
pfetch
190
pfetch
@@ -154,6 +154,12 @@ get_os() {
|
|||||||
if command -v lsb_release; then
|
if command -v lsb_release; then
|
||||||
distro=$(lsb_release -sd)
|
distro=$(lsb_release -sd)
|
||||||
|
|
||||||
|
# lsb_release sometimes adds quotes around the output,
|
||||||
|
# this simply remove quotes from the start/end if they
|
||||||
|
# exist.
|
||||||
|
distro=${distro##\"}
|
||||||
|
distro=${distro%%\"}
|
||||||
|
|
||||||
else
|
else
|
||||||
# Disable warning about shellcheck not being able
|
# Disable warning about shellcheck not being able
|
||||||
# to read '/etc/os-release'. This is fine.
|
# to read '/etc/os-release'. This is fine.
|
||||||
@@ -165,6 +171,19 @@ get_os() {
|
|||||||
# don't follow any os-release/lsb standards whatsoever.
|
# don't follow any os-release/lsb standards whatsoever.
|
||||||
command -v crux && distro=$(crux)
|
command -v crux && distro=$(crux)
|
||||||
command -v guix && distro='Guix System'
|
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*)
|
Darwin*)
|
||||||
@@ -240,6 +259,10 @@ get_kernel() {
|
|||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get_shell() {
|
||||||
|
log shell "${SHELL##*/}" >&6
|
||||||
|
}
|
||||||
|
|
||||||
get_host() {
|
get_host() {
|
||||||
case $os in
|
case $os in
|
||||||
Linux*)
|
Linux*)
|
||||||
@@ -352,6 +375,10 @@ get_uptime() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get_pkgs() {
|
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
|
# This works by first checking for which package managers are
|
||||||
# installed and finally by printing each package manager's
|
# installed and finally by printing each package manager's
|
||||||
# package list with each package one per line.
|
# package list with each package one per line.
|
||||||
@@ -372,27 +399,27 @@ get_pkgs() {
|
|||||||
case $os in
|
case $os in
|
||||||
Linux*)
|
Linux*)
|
||||||
# Commands which print packages one per line.
|
# Commands which print packages one per line.
|
||||||
command -v kiss && kiss l
|
has kiss && kiss l
|
||||||
command -v bonsai && bonsai list
|
has bonsai && bonsai list
|
||||||
command -v pacman-key && pacman -Qq
|
has pacman-key && pacman -Qq
|
||||||
command -v dpkg && dpkg-query -f '.\n' -W
|
has dpkg && dpkg-query -f '.\n' -W
|
||||||
command -v rpm && rpm -qa
|
has rpm && rpm -qa
|
||||||
command -v xbps-query && xbps-query -l
|
has xbps-query && xbps-query -l
|
||||||
command -v apk && apk info
|
has apk && apk info
|
||||||
|
|
||||||
# Directories containing packages.
|
# Directories containing packages.
|
||||||
command -v brew && printf '%s\n' "$(brew --cellar)/"*
|
has brew && printf '%s\n' "$(brew --cellar)/"*
|
||||||
command -v emerge && printf '%s\n' /var/db/pkg/*/*/
|
has emerge && printf '%s\n' /var/db/pkg/*/*/
|
||||||
command -v pkgtool && printf '%s\n' /var/log/packages/*
|
has pkgtool && printf '%s\n' /var/log/packages/*
|
||||||
|
|
||||||
# GUIX requires two commands.
|
# GUIX requires two commands.
|
||||||
command -v guix && {
|
has guix && {
|
||||||
guix package -p /run/current-system/profile -I
|
guix package -p /run/current-system/profile -I
|
||||||
guix package -I
|
guix package -I
|
||||||
}
|
}
|
||||||
|
|
||||||
# NIX requires two commands.
|
# NIX requires two commands.
|
||||||
command -v 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
|
||||||
}
|
}
|
||||||
@@ -400,11 +427,11 @@ get_pkgs() {
|
|||||||
|
|
||||||
Darwin*)
|
Darwin*)
|
||||||
# Commands which print packages one per line.
|
# Commands which print packages one per line.
|
||||||
command -v pkgin && pkgin list
|
has pkgin && pkgin list
|
||||||
command -v port && port installed
|
has port && port installed
|
||||||
|
|
||||||
# Directories containing packages.
|
# Directories containing packages.
|
||||||
command -v brew && printf '%s\n' /usr/local/Cellar/*
|
has brew && printf '%s\n' /usr/local/Cellar/*
|
||||||
;;
|
;;
|
||||||
|
|
||||||
FreeBSD*)
|
FreeBSD*)
|
||||||
@@ -572,128 +599,19 @@ get_memory() {
|
|||||||
log memory "${mem_used:-?}M / ${mem_full:-?}M" >&6
|
log memory "${mem_used:-?}M / ${mem_full:-?}M" >&6
|
||||||
}
|
}
|
||||||
|
|
||||||
get_term() {
|
get_palette() {
|
||||||
# Workaround for macOS systems that don't support the
|
# Print the first 8 terminal colors. This uses the existing
|
||||||
# "algorithm" of obtaining the terminal program name.
|
# sequences to change text color with a sequence prepended
|
||||||
|
# to reverse the foreground and background colors.
|
||||||
#
|
#
|
||||||
# This also doubles as a means of allowing the user to
|
# This allows us to save hardcoding a second set of sequences
|
||||||
# set whatever value they like here through the
|
# for background colors.
|
||||||
# '$TERM_PROGRAM' environment variable.
|
palette=" [7m$c1 $c2 $c3 $c4 $c5 $c6 $c7 "
|
||||||
case $TERM_PROGRAM in
|
|
||||||
iTerm.app) term=iTerm2 ;;
|
|
||||||
Terminal.app) term='Apple Terminal' ;;
|
|
||||||
Hyper) term=HyperTerm ;;
|
|
||||||
*) term=${TERM_PROGRAM%%.app} ;;
|
|
||||||
esac
|
|
||||||
|
|
||||||
# Special case for TosWin2 (FreeMiNT) which doesn't
|
# Print the palette with a newline before and after.
|
||||||
# support the "algorithm" of obtaining the terminal
|
# The '\033[%sC' moves the text to the right, the
|
||||||
# program name.
|
# length of the ascii art.
|
||||||
[ "$TERM" = tw52 ] || [ "$TERM" = tw100 ] &&
|
printf '\n[%sC%s[m\n' "${ascii_width-1}" "$palette" >&6
|
||||||
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() {
|
get_ascii() {
|
||||||
@@ -1170,7 +1088,7 @@ main() {
|
|||||||
# Disable globbing and set the positional parameters to the
|
# Disable globbing and set the positional parameters to the
|
||||||
# contents of 'PF_INFO'.
|
# contents of 'PF_INFO'.
|
||||||
set -f
|
set -f
|
||||||
set +f ${PF_INFO-ascii title os host kernel term uptime pkgs memory}
|
set +f ${PF_INFO-ascii title os host kernel uptime pkgs memory}
|
||||||
|
|
||||||
# Iterate over the info functions to determine the lengths of the
|
# Iterate over the info functions to determine the lengths of the
|
||||||
# "info names" for output alignment. The option names and subtitles
|
# "info names" for output alignment. The option names and subtitles
|
||||||
|
|||||||
Reference in New Issue
Block a user