Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

windows support + disk #187

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ picture"!
- DragonflyBSD, FreeBSD, NetBSD and OpenBSD.
- **Windows**
- Windows subsystem for Linux.
- Windows Powershell (Requires extra tinkering for easy use)
- Windows CMD (Requires extra tinkering for easy use)
- **Haiku**
- **MacOS**
- **Minix**
Expand All @@ -42,6 +44,31 @@ picture"!

## Configuration

For users using pwsh on Windows, add this to your $Profile

```powershell
# I would just git clone the repo in the home directoy
Function pfetch {sh $env:UserProfile\pfetch\pfetch}
```

For users using cmd on Windows, do this:
- Make a doskey macro file, preferablly in `C:\bat\macros.doskey` <-- macros file
- Go to Registry Editor
- Go to Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Conmand Processor
- Make a new string value called `Autorun`
- Right click on it and click `Modify...`
- Change the value path to:
```cmd
DOSKEY /MACROFILE="C:\bat\macros.doskey"
```
- Edit the macros.doskey file to something like this:
```cmd
pfetch=sh %UserProfile%\pfetch\pfetch
```

- Tada! Just run a new instance of cmd!


`pfetch` is configured through environment variables.

```sh
Expand Down
128 changes: 120 additions & 8 deletions pfetch
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#
# pfetch - Simple POSIX sh fetch script.

#PF_ASCII="arch"

# Wrapper around all escape sequences used by pfetch to allow for
# greater control over which sequences are used (if any at all).
esc() {
Expand Down Expand Up @@ -293,6 +295,19 @@ get_os() {
fi
;;

(CYGWIN*|MSYS*|MINGW*)
# Grab everything after the first instance of
# white-space in the command output of 'wmic'.
#
# The format of 'wmic' is as follows:
# Caption=Microsoft Windows 7 Enterprise
#
# This extracts: ^^^^^^^^^^^^^^^^^^^^
read -r _ distro <<-EOF
$(wmic os get Caption | head -n 2 | tail -n +2)
EOF
;;

(Darwin*)
# Parse the SystemVersion.plist file to grab the macOS
# version. The file is in the following format:
Expand Down Expand Up @@ -400,6 +415,10 @@ get_kernel() {
(*BSD*|Haiku|Minix)
return
;;
# Use wmic to get the OS version
(CYGWIN*|MSYS*|MINGW*)
kernel=$(wmic os get Version)
kernel=$(echo $kernel | awk '{print $3}')
esac

# '$kernel' is the cached output of 'uname -r'.
Expand Down Expand Up @@ -435,6 +454,12 @@ get_host() {
(*BSD* | Minix)
host=$(sysctl -n hw.vendor hw.product)
;;
(CYGWIN*|MSYS*|MINGW*)
host=$(wmic computersystem get model \
| tail -n +2 \
| sed 's/.*=//g'
)
;;
esac

# Turn the host string into an argument list so we can iterate
Expand Down Expand Up @@ -485,7 +510,7 @@ get_uptime() {
# converting that data into days, hours and minutes using simple
# math.
case $os in
(Linux* | Minix* | SerenityOS*)
(Linux* | Minix* | SerenityOS*|CYGWIN*|MSYS*|MINGW*)
IFS=. read -r s _ < /proc/uptime
;;

Expand Down Expand Up @@ -564,7 +589,7 @@ get_pkgs() {
# managers are installed.
packages=$(
case $os in
(Linux*)
(Linux*|CYGWIN*|MSYS*|MINGW*)
# Commands which print packages one per line.
has bonsai && bonsai list
has crux && pkginfo -i
Expand All @@ -575,6 +600,7 @@ get_pkgs() {
has apk && apk info
has guix && guix package --list-installed
has opkg && opkg list-installed
has scoop && scoop list

# Directories containing packages.
has kiss && printf '%s\n' /var/db/kiss/installed/*/
Expand Down Expand Up @@ -679,6 +705,9 @@ get_pkgs() {
(OpenBSD)
packages=$((packages))
;;
(CYGWIN*|MSYS*|MINGW*)
packages=$((packages - 3))
;;
esac

case $packages in
Expand All @@ -693,7 +722,7 @@ get_memory() {
# Used memory is calculated using the following "formula":
# MemUsed = MemTotal + Shmem - MemFree - Buffers - Cached - SReclaimable
# Source: https://github.com/KittyKatt/screenFetch/issues/386
(Linux*)
(Linux*|CYGWIN*|MSYS*|MINGW*)
# 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'.
Expand Down Expand Up @@ -939,10 +968,81 @@ get_memory() {
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
#
# probably a better way to do this, but a simple fixs
case $os in
CYGWIN*|MSYS*|MINGW*)
windisk=$(df -h | tail -n +2 | awk 'NR==1{print $4" / "$3,"("$6")"}')
log disk "$windisk" >&6
;;
*)
log disk "$used / $full ($perc)" >&6
;;
esac
done

}

get_wm() {
case $os in
(Darwin*)
# Don't display window manager on macOS.
(Darwin*|CYGWIN*|MSYS*|MINGW*)
# Don't display window manager on macOS and Windows.
;;

(*)
Expand Down Expand Up @@ -1257,6 +1357,19 @@ get_ascii() {
${c5} .//.
EOF
;;

CYGWIN*|MSYS*|MINGW*)
read_ascii 4 <<-EOF
${c4}
###### ######
###### ######
###### ######

###### ######
###### ######
###### ######
EOF
;;

([Dd]ahlia*)
read_ascii 1 <<-EOF
Expand Down Expand Up @@ -1824,7 +1937,7 @@ get_ascii() {
# This ensures that any variables defined in the while loop
# are still accessible in the script.
done <<-EOF
$(printf %s "$ascii" | sed 's/\[3.m//g')
$(printf %s "$ascii" | awk '{gsub("\\[3.m","");print}')
EOF

# Add a gap between the ascii art and the information.
Expand Down Expand Up @@ -1914,8 +2027,7 @@ EOF
# 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 uptime pkgs memory disk}
# Iterate over the info functions to determine the lengths of the
# "info names" for output alignment. The option names and subtitles
# match 1:1 so this is thankfully simple.
Expand Down
Binary file added pfetch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.