8 Commits
term ... 0.1

Author SHA1 Message Date
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
2 changed files with 59 additions and 140 deletions

View File

@@ -32,9 +32,10 @@ _/\ __)/_) pkgs 130
- [ ] 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))
@@ -46,7 +47,7 @@ _/\ __)/_) pkgs 130
- [ ] CYGWIN
- [ ] MSYS
- [ ] MINGW
- [ ] WSL (*this is fairly simple*)
- [x] WSL (*this is fairly simple*)
## Configuration
@@ -58,7 +59,7 @@ _/\ __)/_) pkgs 130
# Default: first example below
# Valid: space separated string
#
# OFF by default: shell
# OFF by default: shell palette
PF_INFO="ascii title distro host kernel uptime pkgs memory"
# Example: Only ASCII.

190
pfetch
View File

@@ -154,6 +154,12 @@ 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.
@@ -165,6 +171,19 @@ 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*)
@@ -240,6 +259,10 @@ get_kernel() {
esac
}
get_shell() {
log shell "${SHELL##*/}" >&6
}
get_host() {
case $os in
Linux*)
@@ -352,6 +375,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.
@@ -372,27 +399,27 @@ 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 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
# 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/*
has brew && printf '%s\n' "$(brew --cellar)/"*
has emerge && printf '%s\n' /var/db/pkg/*/*/
has pkgtool && printf '%s\n' /var/log/packages/*
# GUIX requires two commands.
command -v guix && {
has guix && {
guix package -p /run/current-system/profile -I
guix package -I
}
# 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
}
@@ -400,11 +427,11 @@ 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*)
@@ -572,128 +599,19 @@ get_memory() {
log memory "${mem_used:-?}M / ${mem_full:-?}M" >&6
}
get_term() {
# Workaround for macOS systems that don't support the
# "algorithm" of obtaining the terminal program name.
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 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
# This allows us to save hardcoding a second set of sequences
# for background colors.
palette=" $c1 $c2 $c3 $c4 $c5 $c6 $c7 "
# 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
# 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() {
@@ -1170,7 +1088,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 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
# "info names" for output alignment. The option names and subtitles