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 |
@@ -32,10 +32,9 @@ _/\ __)/_) pkgs 130
|
||||
|
||||
- [ ] 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.
|
||||
- [ ] Solaris ([#5](https://github.com/dylanaraps/pfetch/issues/5))
|
||||
@@ -47,7 +46,7 @@ _/\ __)/_) pkgs 130
|
||||
- [ ] CYGWIN
|
||||
- [ ] MSYS
|
||||
- [ ] MINGW
|
||||
- [x] WSL (*this is fairly simple*)
|
||||
- [ ] WSL (*this is fairly simple*)
|
||||
|
||||
## Configuration
|
||||
|
||||
@@ -59,7 +58,7 @@ _/\ __)/_) pkgs 130
|
||||
# Default: first example below
|
||||
# Valid: space separated string
|
||||
#
|
||||
# OFF by default: shell palette
|
||||
# OFF by default: shell
|
||||
PF_INFO="ascii title distro host kernel uptime pkgs memory"
|
||||
|
||||
# Example: Only ASCII.
|
||||
|
||||
190
pfetch
190
pfetch
@@ -154,12 +154,6 @@ get_os() {
|
||||
if command -v lsb_release; then
|
||||
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
|
||||
# Disable warning about shellcheck not being able
|
||||
# to read '/etc/os-release'. This is fine.
|
||||
@@ -171,19 +165,6 @@ get_os() {
|
||||
# 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"
|
||||
;;
|
||||
|
||||
Darwin*)
|
||||
@@ -259,10 +240,6 @@ get_kernel() {
|
||||
esac
|
||||
}
|
||||
|
||||
get_shell() {
|
||||
log shell "${SHELL##*/}" >&6
|
||||
}
|
||||
|
||||
get_host() {
|
||||
case $os in
|
||||
Linux*)
|
||||
@@ -375,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.
|
||||
@@ -399,27 +372,27 @@ get_pkgs() {
|
||||
case $os in
|
||||
Linux*)
|
||||
# Commands which print packages one per line.
|
||||
has kiss && kiss l
|
||||
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
|
||||
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 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.
|
||||
has guix && {
|
||||
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
|
||||
}
|
||||
@@ -427,11 +400,11 @@ 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*)
|
||||
@@ -599,19 +572,128 @@ get_memory() {
|
||||
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() {
|
||||
@@ -1088,7 +1170,7 @@ 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
|
||||
|
||||
Reference in New Issue
Block a user