最初コミット

This commit is contained in:
2026-01-16 22:40:50 +09:00
commit 81fa554b36
60 changed files with 4914 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
farfetch
*.o
*.core

40
CHANGELOG.md Normal file
View File

@@ -0,0 +1,40 @@
# 0.3.1
* SunOS: 「;」を忘れた
# 0.3.0
* macOSでOS情報の修正
* macOS: 解像度の追加
* コンフィグのエラーの修正osとhostのコンフリクト
* Linux: 全てのケースに解像度を受け取る様に
* Linux: 「/proc/cpuinfo」で使ってCPU速さの受け取る様に
* Kubuntu、Xubuntu、Lubuntu、Arco、Hyperbola、Parabola、とPop OSロゴの追加
* Ubuntu MATE、Ubuntu Budgie、Ubuntu Lomiri、Ubuntu Unity、とUbuntu Cinnamonロゴの追加
* Linux: 「hostname」コマンドがなければ、「cat /etc/hostname」を実効する様に
* Linux: pacman、rpm対応
* LinuxとBSD: 今から、静的リンクがデフォルトになりました動的リンクには「make LDFLAGS=-lc」をご利用下さい
* 色コンフィグの追加
* カスタムロゴコンフィグの追加
* モジュールのキャッシングの追加(それでスピードアップする)
* コンフィグでロゴの設定の追加隠し・表示、大・小、カスタムロゴ、LinuxとIllumosの場合ディストロロゴ
* マンページの英訳
# 0.2.0
* Manjaroのロゴの追加
* OpenSUSEのロゴの追加
* Linux Mintのロゴの追加
* Ubuntuのロゴの追加
* Linuxロゴの修正今も元気ハツラツ太郎さん
* Fedoraロゴの追加
* 他のディストリビューションのロゴの表示オプションの追加LinuxとIllumosのみ
* Rocky Linuxロゴの追加
* CentOSロゴの追加
* Red Hatロゴの追加
* コンフィグファイル機能性の追加
# 0.1.1
* ストレージ情報の修正(今も元気ハツラツ太郎さん)
* VultrのFreeBSDでのGPUとCPUの修正
* ディストロの情報の修正
# 0.1.0
* 開始

32
LICENSE.md Normal file
View File

@@ -0,0 +1,32 @@
Copyright (c) 2023-2026 テクニカル諏訪子
Permission is hereby granted to any person obtaining a copy of the software
Farfetch (the "Software") to use, modify, merge, copy, publish, distribute,
sublicense, and/or sell copies of the Software, subject to the following conditions:
1. **Origin Attribution**:
- You must not misrepresent the origin of the Software; you must not claim
you created the original Software.
- If the Software is used in a product, you must either:
a. Provide clear attribution in the product's documentation, user interface,
or other visible areas, **OR**
b. Pay the original developers a fee they specify in writing.
2. **Usage Restriction**:
- The Software, or any derivative works, dependencies, or libraries
incorporating it, must not be used for censorship or to suppress freedom of
speech, expression, or creativity. Prohibited uses include, but are not
limited to:
- Censorship of so-called "hate speech", visuals, non-mainstream opinions,
ideas, or objective reality.
- Tools or systems designed to restrict access to information or
artistic works.
3. **Notice Preservation**:
- This license and the above copyright notice must remain intact in all copies
of the source code.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

110
Makefile Normal file
View File

@@ -0,0 +1,110 @@
UNAME_S != uname -s
UNAME_M != uname -m
OS = ${UNAME_S}
.if ${UNAME_S} == "OpenBSD"
OS = openbsd
.elif ${UNAME_S} == "NetBSD"
OS = netbsd
.elif ${UNAME_S} == "FreeBSD"
OS = freebsd
.elif ${UNAME_S} == "Linux"
OS = linux
.endif
.if ${UNAME_M} == "x86_64"
UNAME_M = amd64
.endif
NAME != cat main.c | grep "const char \*sofname" | awk '{print $$5}' |\
sed "s/\"//g" | sed "s/;//"
VERSION != cat main.c | grep "const char \*version" | awk '{print $$5}' |\
sed "s/\"//g" | sed "s/;//"
PREFIX = /usr/local
.if ${UNAME_S} == "Linux"
PREFIX = /usr
.elif ${UNAME_S} == "Haiku"
PREFIX = /boot/home/config/non-packaged
.endif
MANPREFIX = ${PREFIX}/share/man
.if ${UNAME_S} == "OpenBSD"
MANPREFIX = ${PREFIX}/man
.elif ${UNAME_S} == "Haiku"
MANPREFIX = ${PREFIX}/documentation/man
.endif
CNFPREFIX = /etc
.if ${UNAME_S} == "FreeBSD" || ${UNAME_S} == "NetBSD" || ${UNAME_S} == "Dragonfly"
CNFPREFIX = ${PREFIX}/etc
.elif ${UNAME_S} == "Haiku"
CNFPREFIX = /boot/home/config/settings
.endif
CC = cc
FILES = main.c src/*.c src/logo/*.c
CFLAGS = -Wall -Wextra -O3
LDFLAGS = -static -lc
.if ${UNAME_S} == "Haiku" || ${UNAME_S} == "Darwin" || ${UNAME_S} == "SunOS"\
|| ${UNAME_S} == "Minix"
LDFLAGS = -lc
.endif
all:
${CC} ${CFLAGS} -o ${NAME} ${FILES} ${LDFLAGS}
strip ${NAME}
clean:
rm -rf ${NAME}
dist:
mkdir -p ${NAME}-${VERSION} release/src
cp -R LICENSE.txt Makefile README.md CHANGELOG.md\
${NAME}.conf ${NAME}.1 ${NAME}-en.1 ${NAME}.conf.5 ${NAME}.conf-en.5\
main.c src ${NAME}-${VERSION}
tar zcfv release/src/${NAME}-${VERSION}.tar.gz ${NAME}-${VERSION}
rm -rf ${NAME}-${VERSION}
man:
mkdir -p release/man/${VERSION}
sed "s/VERSION/${VERSION}/g" < ${NAME}.1 > release/man/${VERSION}/${NAME}.1
sed "s/VERSION/${VERSION}/g" < ${NAME}-en.1 > release/man/${VERSION}/${NAME}-en.1
sed "s/VERSION/${VERSION}/g" < ${NAME}.conf.5 >\
release/man/${VERSION}/${NAME}.conf.5
sed "s/VERSION/${VERSION}/g" < ${NAME}.conf-en.5 >\
release/man/${VERSION}/${NAME}.conf-en.5
release:
mkdir -p release/bin/${VERSION}/${OS}/${UNAME_M}
${CC} ${CFLAGS} -o release/bin/${VERSION}/${OS}/${UNAME_M}/${NAME} ${FILES}\
-static ${LDFLAGS}
strip release/bin/${VERSION}/${OS}/${UNAME_M}/${NAME}
install:
mkdir -p ${DESTDIR}${PREFIX}/bin ${DESTDIR}${MANPREFIX}/man1\
${DESTDIR}${MANPREFIX}/man5
cp -rf ${NAME} ${DESTDIR}${PREFIX}/bin
cp -rf ${NAME}.conf ${DESTDIR}${CNFPREFIX}
chmod 755 ${DESTDIR}${PREFIX}/bin/${NAME}
sed "s/VERSION/${VERSION}/g" < ${NAME}.1 > ${DESTDIR}${MANPREFIX}/man1/${NAME}.1
chmod 644 ${DESTDIR}${MANPREFIX}/man1/${NAME}.1
sed "s/VERSION/${VERSION}/g" < ${NAME}-en.1 >\
${DESTDIR}${MANPREFIX}/man1/${NAME}-en.1
chmod 644 ${DESTDIR}${MANPREFIX}/man1/${NAME}-en.1
sed "s/VERSION/${VERSION}/g" < ${NAME}.conf.5 >\
${DESTDIR}${MANPREFIX}/man5/${NAME}.conf.5
chmod 644 ${DESTDIR}${MANPREFIX}/man5/${NAME}.conf.5
sed "s/VERSION/${VERSION}/g" < ${NAME}.conf-en.5 >\
${DESTDIR}${MANPREFIX}/man5/${NAME}.conf-en.5
chmod 644 ${DESTDIR}${MANPREFIX}/man5/${NAME}.conf-en.5
uninstall:
rm -rf ${DESTDIR}${PREFIX}/bin/${NAME}
rm -rf ${DESTDIR}${MANPREFIX}/man1/${NAME}.1
rm -rf ${DESTDIR}${MANPREFIX}/man1/${NAME}-en.1
rm -rf ${DESTDIR}${MANPREFIX}/man5/${NAME}.conf.5
rm -rf ${DESTDIR}${MANPREFIX}/man5/${NAME}-en.conf.5
.PHONY: all clean dist man release install uninstall

59
README.md Normal file
View File

@@ -0,0 +1,59 @@
# farfetch
![](https://this.is.very.dangerous.software/2024-06-20-114921_1920x1080_scrot.png)
## インストールする方法 | Installation
### OpenBSD
```sh
make
doas make install
```
### NetBSD | FreeBSD | Dragonfly BSD
```sh
make
sudo make install
```
### CRUX
```sh
sudo prt-get bmake
bmake
sudo bmake install
```
### Void
```sh
sudo xbps-install bmake
bmake
sudo bmake install
```
### Artix
```sh
sudo pacman -S base-devel bmake
bmake
sudo bmake install
```
### OmniOS
```sh
gcc -Wall -Wextra -O3 -I/usr/include -o farfetch main.c src/*.c src/logo/*.c -L/usr/lib -lc
sudo cp farfetch /usr/bin
sudo cp farfetch.1 /usr/bin/share/man/man1
```
### Debian | Devuan | Ubuntu | Linux Mint | PopOS
[Kazuhikoさん](https://social.076.moe/conversation/1127279#notice-2122922)
```sh
sudo apt install -y build-essential bmake git pciutils
bmake
sudo bmake install
```
### Fedora | Red Hat | CentOS | Rocky Linux
```sh
sudo dnf install bmake clang
bmake
sudo bmake install
```

23
farfetch-en.1 Normal file
View File

@@ -0,0 +1,23 @@
.TH FARFETCH 1 VERSION
.SH NAME
farfetch - system info
.br
.B farfetch
[-rs] [-l distro]
.SH DESCRIPTION
.PP
System Information
.TP
\fB\,-r\fR
Delete from cache and run (except Haiku)
.TP
\fB\,-s\fR
Small logo display
.TP
\fB\,-l\fR [\fI\,distro\fR]
Displaying different distribution logos (Linux and Illumos only)
.SH AUTHORS
.PP
TechnicalSuwako (Developer)
.br
Hatuhatu Taro (Developer)

23
farfetch.1 Normal file
View File

@@ -0,0 +1,23 @@
.TH FARFETCH 1 VERSION
.SH NAME
farfetch - system info
.br
.B farfetch
[-rs] [-l distro]
.SH DESCRIPTION
.PP
システム情報
.TP
\fB\,-r\fR
キャッシュから削除して、実効Haiku以外
.TP
\fB\,-s\fR
小さいロゴの表示
.TP
\fB\,-l\fR [\fI\,distro\fR]
違うディストリビューションのロゴの表示LinuxとIllumosのみ
.SH AUTHORS
.PP
テクニカル諏訪子(開発者)
.br
ハツラツ太郎(開発者)

51
farfetch.conf Normal file
View File

@@ -0,0 +1,51 @@
show logo big
#hide logo
#show logo small
#show logo big custom
#show logo small custom
#show logo big crux
#show logo small alpine
show os
show host
show distro
show uptime
show recording
#hide recording
show libc
show packages
show resolution
#hide resolution
show wm
show shell
show cpu
show gpu
show memory
show storage all
#show storage /dev/sd0a
#show storage zroot and xroot
#show storage /dev/sda0, /dev/sda1 and /dev/sda2
#set color yellow # red|green|blue|yellow|magenta|white|grey|cyan
#set titlecolor magenta # red|green|blue|yellow|magenta|white|grey|cyan
#define custom big logo:
#[MAGENTA] ⢀⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀⣠⠾⠛⠶⣄⢀⣠⣤⠴⢦⡀⠀⠀⠀⠀ [RESET]
#[MAGENTA]⠀⠀⠀⢠⡿⠉⠉⠉⠛⠶⠶⠖⠒⠒⣾⠋⠀⢀⣀⣙⣯⡁⠀⠀⠀⣿⠀⠀⠀⠀ [RESET]
#[MAGENTA]⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⢸⡏⠀⠀⢯⣼⠋⠉⠙⢶⠞⠛⠻⣆⠀⠀⠀ [RESET]
#[MAGENTA]⠀⠀⠀⢸⣧⠆⠀⠀⠀⠀⠀⠀⠀⠀⠻⣦⣤⡤⢿⡀⠀⢀⣼⣷⠀⠀⣽⠀⠀⠀ [RESET]
#[MAGENTA]⠀⠀⠀⣼⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠙⢏⡉⠁⣠⡾⣇⠀⠀⠀ [RESET]
#[MAGENTA]⠀⠀⢰⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠋⠉⠀⢻⡀⠀⠀ [RESET]
#[MAGENTA]⣀⣠⣼⣧⣤⠀⠀[WHITE]⠀⣀⡀[MAGENTA][CYAN]⣀⡀[MAGENTA]⠀⠀⠐⠖⢻⡟⠓⠒ [RESET]
#[MAGENTA]⠀⠀⠈⣷⣀⡀⠀[WHITE]⠘⠿⠇[MAGENTA]⠀⠀⠀⢀⣀⣀⠀⠀⠀⠀[CYAN]⠿⠟[MAGENTA]⠀⠀⠀⠲⣾⠦⢤⠀ [RESET]
#[MAGENTA]⠀⠀⠋⠙⣧⣀⡀⠀⠀⠀⠀⠀⠀⠘⠦⠼⠃⠀⠀⠀⠀⠀⠀⠀⢤⣼⣏⠀⠀⠀ [RESET]
#[MAGENTA]⠀⠀⢀⠴⠚⠻⢧⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣤⠞⠉⠉⠓⠀⠀ [RESET]
#[MAGENTA]⠀⠀⠀⠀⠀⠀⠀⠈⠉⠛⠛⠶⠶⠶⣶⣤⣴⡶⠶⠶⠟⠛⠉⠀⠀⠀⠀⠀⠀⠀ [RESET]
#EOL
#define custom small logo:
#[WHITE] |\____/| [RESET]
#[WHITE] | | [RESET]
#[WHITE] | [GREY]0 0[WHITE] | [RESET]
#[WHITE] | [RED]ω[WHITE] | [RESET]
#[WHITE] \_____/ [RESET]
#EOL

82
farfetch.conf-en.5 Normal file
View File

@@ -0,0 +1,82 @@
.TH FARFETCH.CONF 5 VERSION
.SH NAME
.B farfetch.conf
.SH DESCRIPTION
.PP
To use it, run `cp /etc/farfetch.conf ~/.config`.
.br
This is not necessary for Haiku.
.SH GLOBAL CONFIGURATION
.TP
\fB\,hide\fR [\fI\,context\fR]
hide
.TP
\fB\,show\fR [\fI\,context\fR]
express
.TP
\fB\,set color\fR [\fI\,red|green|blue|yellow|magenta|white|grey|cyan\fR]
Change module color
.TP
\fB\,set titlecolor\fR [\fI\,red|green|blue|yellow|magenta|white|grey|cyan\fR]
Change title color
.TP
\fB\,define custom\fR [\fI\,big|small\fR] \fB,logo:\fR
Custom logo can be displayed until EOL
.br
You can also set the color, but it must end with "[RESET]".
.SH EXAMPLES
hide packages
show os
set color magenta
define custom big logo:
.br
[RED]⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠛⢉⢉⠉⠉⠻⣿⣿⣿⣿⣿⣿ [RESET]
.br
[RED]⣿⣿⣿⣿⣿⣿⣿⠟⠠⡰⣕⣗⣷⣧⣀⣅⠘⣿⣿⣿⣿⣿ [RESET]
.br
[RED]⣿⣿⣿⣿⣿⣿⠃⣠⣳⣟⣿⣿⣷⣿⡿⣜⠄⣿⣿⣿⣿⣿ [RESET]
.br
[RED]⣿⣿⣿⣿⡿⠁⠄⣳⢷⣿⣿⣿⣿⡿⣝⠖⠄⣿⣿⣿⣿⣿ [RESET]
.br
[CYAN]⣿⣿⣿⣿⠃⠄⢢⡹⣿⢷⣯⢿⢷⡫⣗⠍⢰⣿⣿⣿⣿⣿ [RESET]
.br
[CYAN]⣿⣿⣿⡏⢀⢄⠤⣁⠋⠿⣗⣟⡯⡏⢎⠁⢸⣿⣿⣿⣿⣿ [RESET]
.br
[CYAN]⣿⣿⣿⠄⢔⢕⣯⣿⣿⡲⡤⡄⡤⠄⡀⢠⣿⣿⣿⣿⣿⣿ [RESET]
.br
[CYAN]⣿⣿⠇⠠⡳⣯⣿⣿⣾⢵⣫⢎⢎⠆⢀⣿⣿⣿⣿⣿⣿⣿ [RESET]
.br
[GREEN]⣿⣿⠄⢨⣫⣿⣿⡿⣿⣻⢎⡗⡕⡅⢸⣿⣿⣿⣿⣿⣿⣿ [RESET]
.br
[GREEN]⣿⣿⠄⢜⢾⣾⣿⣿⣟⣗⢯⡪⡳⡀⢸⣿⣿⣿⣿⣿⣿⣿ [RESET]
.br
[GREEN]⣿⣿⠄⢸⢽⣿⣷⣿⣻⡮⡧⡳⡱⡁⢸⣿⣿⣿⣿⣿⣿⣿ [RESET]
.br
[GREEN]⣿⣿⡄⢨⣻⣽⣿⣟⣿⣞⣗⡽⡸⡐⢸⣿⣿⣿⣿⣿⣿⣿ [RESET]
.br
[YELLOW]⣿⣿⡇⢀⢗⣿⣿⣿⣿⡿⣞⡵⡣⣊⢸⣿⣿⣿⣿⣿⣿⣿ [RESET]
.br
[YELLOW]⣿⣿⣿⡀⡣⣗⣿⣿⣿⣿⣯⡯⡺⣼⠎⣿⣿⣿⣿⣿⣿⣿ [RESET]
.br
[YELLOW]⣿⣿⣿⣧⠐⡵⣻⣟⣯⣿⣷⣟⣝⢞⡿⢹⣿⣿⣿⣿⣿⣿ [RESET]
.br
[YELLOW]⣿⣿⣿⣿⡆⢘⡺⣽⢿⣻⣿⣗⡷⣹⢩⢃⢿⣿⣿⣿⣿⣿ [RESET]
.br
[MAGENTA]⣿⣿⣿⣿⣷⠄⠪⣯⣟⣿⢯⣿⣻⣜⢎⢆⠜⣿⣿⣿⣿⣿ [RESET]
.br
[MAGENTA]⣿⣿⣿⣿⣿⡆⠄⢣⣻⣽⣿⣿⣟⣾⡮⡺⡸⠸⣿⣿⣿⣿ [RESET]
.br
[MAGENTA]⣿⣿⡿⠛⠉⠁⠄⢕⡳⣽⡾⣿⢽⣯⡿⣮⢚⣅⠹⣿⣿⣿ [RESET]
.br
[MAGENTA]⡿⠋⠄⠄⠄⠄⢀⠒⠝⣞⢿⡿⣿⣽⢿⡽⣧⣳⡅⠌⠻⣿ [RESET]
.br
[GREY]⠁⠄⠄⠄⠄⠄⠐⡐⠱⡱⣻⡻⣝⣮⣟⣿⣻⣟⣻⡺⣊ [RESET]
.br
EOL
.SH AUTHORS
.PP
TechnicalSuwako (Developer)
.br
Hatuhatu Taro (Developer)

82
farfetch.conf.5 Normal file
View File

@@ -0,0 +1,82 @@
.TH FARFETCH.CONF 5 VERSION
.SH NAME
.B farfetch.conf
.SH DESCRIPTION
.PP
利用するには、`cp /etc/farfetch.conf ~/.config`を実効して下さい。
.br
Haikuの場合は不要です。
.SH GLOBAL CONFIGURATION
.TP
\fB\,hide\fR [\fI\,context\fR]
隠す
.TP
\fB\,show\fR [\fI\,context\fR]
表示
.TP
\fB\,set color\fR [\fI\,red|green|blue|yellow|magenta|white|grey|cyan\fR]
モジュール色の変更
.TP
\fB\,set titlecolor\fR [\fI\,red|green|blue|yellow|magenta|white|grey|cyan\fR]
タイトル色の変更
.TP
\fB\,define custom\fR [\fI\,big|small\fR] \fB,logo:\fR
EOLまでカスタムロゴを表示出来る
.br
色の設置も可能ですが、「[RESET]」で終わる事が必須
.SH EXAMPLES
hide packages
show os
set color magenta
define custom big logo:
.br
[RED]⣿⣿⣿⣿⣿⣿⣿⣿⣿⠟⠛⢉⢉⠉⠉⠻⣿⣿⣿⣿⣿⣿ [RESET]
.br
[RED]⣿⣿⣿⣿⣿⣿⣿⠟⠠⡰⣕⣗⣷⣧⣀⣅⠘⣿⣿⣿⣿⣿ [RESET]
.br
[RED]⣿⣿⣿⣿⣿⣿⠃⣠⣳⣟⣿⣿⣷⣿⡿⣜⠄⣿⣿⣿⣿⣿ [RESET]
.br
[RED]⣿⣿⣿⣿⡿⠁⠄⣳⢷⣿⣿⣿⣿⡿⣝⠖⠄⣿⣿⣿⣿⣿ [RESET]
.br
[CYAN]⣿⣿⣿⣿⠃⠄⢢⡹⣿⢷⣯⢿⢷⡫⣗⠍⢰⣿⣿⣿⣿⣿ [RESET]
.br
[CYAN]⣿⣿⣿⡏⢀⢄⠤⣁⠋⠿⣗⣟⡯⡏⢎⠁⢸⣿⣿⣿⣿⣿ [RESET]
.br
[CYAN]⣿⣿⣿⠄⢔⢕⣯⣿⣿⡲⡤⡄⡤⠄⡀⢠⣿⣿⣿⣿⣿⣿ [RESET]
.br
[CYAN]⣿⣿⠇⠠⡳⣯⣿⣿⣾⢵⣫⢎⢎⠆⢀⣿⣿⣿⣿⣿⣿⣿ [RESET]
.br
[GREEN]⣿⣿⠄⢨⣫⣿⣿⡿⣿⣻⢎⡗⡕⡅⢸⣿⣿⣿⣿⣿⣿⣿ [RESET]
.br
[GREEN]⣿⣿⠄⢜⢾⣾⣿⣿⣟⣗⢯⡪⡳⡀⢸⣿⣿⣿⣿⣿⣿⣿ [RESET]
.br
[GREEN]⣿⣿⠄⢸⢽⣿⣷⣿⣻⡮⡧⡳⡱⡁⢸⣿⣿⣿⣿⣿⣿⣿ [RESET]
.br
[GREEN]⣿⣿⡄⢨⣻⣽⣿⣟⣿⣞⣗⡽⡸⡐⢸⣿⣿⣿⣿⣿⣿⣿ [RESET]
.br
[YELLOW]⣿⣿⡇⢀⢗⣿⣿⣿⣿⡿⣞⡵⡣⣊⢸⣿⣿⣿⣿⣿⣿⣿ [RESET]
.br
[YELLOW]⣿⣿⣿⡀⡣⣗⣿⣿⣿⣿⣯⡯⡺⣼⠎⣿⣿⣿⣿⣿⣿⣿ [RESET]
.br
[YELLOW]⣿⣿⣿⣧⠐⡵⣻⣟⣯⣿⣷⣟⣝⢞⡿⢹⣿⣿⣿⣿⣿⣿ [RESET]
.br
[YELLOW]⣿⣿⣿⣿⡆⢘⡺⣽⢿⣻⣿⣗⡷⣹⢩⢃⢿⣿⣿⣿⣿⣿ [RESET]
.br
[MAGENTA]⣿⣿⣿⣿⣷⠄⠪⣯⣟⣿⢯⣿⣻⣜⢎⢆⠜⣿⣿⣿⣿⣿ [RESET]
.br
[MAGENTA]⣿⣿⣿⣿⣿⡆⠄⢣⣻⣽⣿⣿⣟⣾⡮⡺⡸⠸⣿⣿⣿⣿ [RESET]
.br
[MAGENTA]⣿⣿⡿⠛⠉⠁⠄⢕⡳⣽⡾⣿⢽⣯⡿⣮⢚⣅⠹⣿⣿⣿ [RESET]
.br
[MAGENTA]⡿⠋⠄⠄⠄⠄⢀⠒⠝⣞⢿⡿⣿⣽⢿⡽⣧⣳⡅⠌⠻⣿ [RESET]
.br
[GREY]⠁⠄⠄⠄⠄⠄⠐⡐⠱⡱⣻⡻⣝⣮⣟⣿⣻⣟⣻⡺⣊ [RESET]
.br
EOL
.SH AUTHORS
.PP
テクニカル諏訪子(開発者)
.br
ハツラツ太郎(開発者)

379
main.c Normal file
View File

@@ -0,0 +1,379 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "src/user.h"
#include "src/os.h"
#if defined(__linux__) || defined(__sun)
#include "src/distro.h"
#endif
#if !defined(__HAIKU__)
#include "src/host.h"
#endif
#include "src/uptime.h"
#if defined(__OpenBSD__)
#include "src/recording.h"
#endif
#include "src/packages.h"
#include "src/resolution.h"
#include "src/wm.h"
#include "src/shell.h"
#include "src/libc.h"
#include "src/cpu.h"
#include "src/gpu.h"
#include "src/memory.h"
#include "src/storage.h"
#include "src/config.h"
#include "src/common.h"
const char *sofname = "farfetch";
const char *version = "0.3.0";
#if defined(__linux__) || defined(__sun)
const char *avalopt = "lrs";
#elif defined(__HAIKU__)
const char *avalopt = "s";
#else
const char *avalopt = "rs";
#endif
int opt;
#if defined(__linux__) || defined(__sun)
int islogo = 0;
#endif
int issmall = 0;
int iserr = 0;
void usage() {
#if defined(__linux__) || defined(__sun)
printf("%s-%s\nusage: %s [-rs] [-l distro]\n", sofname, version, sofname);
#else
printf("%s-%s\nusage: %s [-%s]\n", sofname, version, sofname, avalopt);
#endif
}
void flags(int opt) {
switch (opt) {
#if defined(__linux__) || defined(__sunos)
case 'l':
islogo = 1;
islogodistro = 0;
islogocustom = 0;
break;
#endif
#if !defined(__HAIKU__)
case 'r':
delete_cache();
break;
#endif
case 's':
issmall = 1;
break;
default:
iserr = 1;
usage();
break;
}
}
int main(int argc, char *argv[]) {
int lc = 0;
while ((opt = getopt(argc, argv, avalopt)) != -1) {
flags(opt);
}
if (iserr == 1) {
return 1;
}
getconf();
#if defined(__OpenBSD__)
#include "src/logo/openbsd.h"
getOS();
#elif defined(__NetBSD__)
#include "src/logo/netbsd.h"
getOS();
#elif defined(__FreeBSD__)
#include "src/logo/freebsd.h"
getOS();
#elif defined(__linux__)
get_distro();
#include "src/logo/linux.h"
getDistro(distroname);
#elif defined(__sun)
get_distro();
#include "src/logo/sunos.h"
getDistro(distroname);
#elif defined(__APPLE__)
#include "src/logo/macos.h"
getOS();
#elif defined(__HAIKU__)
#include "src/logo/haiku.h"
getOS();
#else
#include "src/logo/colors.h"
const char *color = MAGENTA;
const char *titlecolor = MAGENTA;
size_t logosize = 11;
char *LOGO[] = {
" ⢀⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀⣠⠾⠛⠶⣄⢀⣠⣤⠴⢦⡀ ",
"⠀⠀⠀⢠⡿⠉⠉⠉⠛⠶⠶⠖⠒⠒⣾⠋⠀⢀⣀⣙⣯⡁⠀⠀⠀⣿⠀⠀⠀ ",
"⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⢸⡏⠀⠀⢯⣼⠋⠉⠙⢶⠞⠛⠻⣆ ",
"⠀⠀⠀⢸⣧⠆⠀⠀⠀⠀⠀⠀⠀⠀⠻⣦⣤⡤⢿⡀⠀⢀⣼⣷⠀⠀⣽ ",
"⠀⠀⠀⣼⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠙⢏⡉⠁⣠⡾⣇⠀⠀⠀ ",
"⠀⠀⢰⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠋⠉⠀⢻⡀ ",
"⣀⣠⣼⣧⣤⠀⠀⠀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡀⠀⠀⠐⠖⢻⡟⠓⠒ ",
"⠀⠀⠈⣷⣀⡀⠀⠘⠿⠇⠀⠀⠀⢀⣀⣀⠀⠀⠀⠀⠿⠟⠀⠀⠀⠲⣾⠦⢤ ",
"⠀⠀⠋⠙⣧⣀⡀⠀⠀⠀⠀⠀⠀⠘⠦⠼⠃⠀⠀⠀⠀⠀⠀⠀⢤⣼⣏ ",
"⠀⠀⢀⠴⠚⠻⢧⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣤⠞⠉⠉⠓⠀⠀ ",
"⠀⠀⠀⠀⠀⠀⠀⠈⠉⠛⠛⠶⠶⠶⣶⣤⣴⡶⠶⠶⠟⠛⠉⠀⠀⠀⠀⠀⠀⠀ "
};
char *LOGO_SMALL[] = {
"|\____/| ",
"| | ",
"| 0 0 | ",
"| ω | ",
"\_____/ "
};
#endif
int minsize = MIN_SIZE;
if (isresolution) {
const char *res = display_resolution();
if (!res) minsize--;
else free((void *)res);
} else minsize--;
if (iswm) {
const char *winman = display_wm();
if (!winman) minsize--;
#if !defined(__APPLE__) && !defined(__HAIKU__)
else free((void *)winman);
#endif
} else minsize--;
if (islibc) {
const char *clang = display_libc();
if (clang) minsize++;
}
if (isstorage) {
const char *store = display_storage();
if (!store) minsize--;
else free((void *)store);
} else minsize--;
if (isgpu) {
const char *graph = display_gpu();
if (!graph) minsize--;
else free((void *)graph);
} else minsize--;
const char *reset = RESET;
size_t ls = logosize <= (size_t)minsize ? (size_t)minsize : logosize;
#if defined(__linux__) || defined(__sun)
if (islogo) {
logoname = argv[2];
getDistro(logoname);
} else if (islogodistro) {
logoname = distrostring;
getDistro(logoname);
free(distrostring);
}
#endif
bool smol = false;
if (issmall && !islogos) smol = true;
else if (!issmall && islogos) smol = true;
if (smol) {
size_t ne = sizeof(LOGO_SMALL) / sizeof(LOGO_SMALL[0]);
for (size_t i = 0; i < ne; i++) {
LOGO[i] = LOGO_SMALL[i];
}
ls = ne >= (size_t)minsize ? (size_t)minsize : ne;
}
const char *name = display_user_name();
const char *host = display_user_host();
if (name || host) {
printf("%s ", LOGO[lc]);
if (name) printf("%s%s%s",titlecolor, name, reset);
if (name && host) printf("@");
if (host) printf("%s%s%s", titlecolor, host, reset);
printf("\n");
if (name) free((void *)name);
if (host) free((void *)host);
lc++;
}
printf("%s ", LOGO[lc]);
printf("------------------\n");
lc++;
if (isos) {
const char *os = display_os();
if (os) {
printf("%s ", LOGO[lc]);
printf("%sOS%s: %s\n", color, reset, os);
free((void *)os);
lc++;
}
} else minsize--;
#if defined(__linux__) || defined(__sun)
if (isdistro) {
const char *distroo = display_distro();
if (distroo) {
printf("%s ", LOGO[lc]);
printf("%sDistro%s: %s\n", color, reset, distroo);
lc++;
free((void *)distroo);
}
} else minsize--;
#endif
#if !defined(__HAIKU__)
const char *machine = display_host();
if (ishost) {
printf("%s ", LOGO[lc]);
printf("%sHost%s: %s\n", color, reset, machine);
lc++;
} else minsize--;
#endif
if (isuptime) {
const char *days = display_days();
const char *time = display_time();
if (days || time) {
printf("%s ", LOGO[lc]);
printf("%s%s%s%s", color, "Uptime", reset, ": ");
if (days) {
printf("%s", days);
if (time) printf(" ");
}
if (time) {
printf("%s", time);
}
printf("\n");
if (days) free((void *)days);
if (time) free((void *)time);
lc++;
}
} else minsize--;
#if defined(__OpenBSD__)
if (isrecording) {
const char *audio = display_recording_audio();
const char *video = display_recording_video();
if (audio || video) {
printf("%s ", LOGO[lc]);
printf("%sRecording%s: ", color, reset);
if (audio) {
printf("audio = %s", audio);
if (video) printf(", ");
}
if (video) {
printf("video = %s", video);
}
printf("\n");
if (audio) free((void *)audio);
if (video) free((void *)video);
lc++;
}
} else minsize--;
#endif
if (ispackages) {
const char *packages = display_packages();
if (packages) {
printf("%s ", LOGO[lc]);
printf("%sPackages%s: %s\n", color, reset, packages);
lc++;
free((void *)packages);
}
} else minsize--;
if (isresolution) {
const char *resolution = display_resolution();
if (resolution) {
printf("%s ", LOGO[lc]);
printf("%sResolution%s: %s\n", color, reset, resolution);
lc++;
free((void *)resolution);
}
}
if (iswm) {
const char *wm = display_wm();
if (wm) {
printf("%s ", LOGO[lc]);
printf("%sWM%s: %s\n", color, reset, wm);
#if !defined(__APPLE__) && !defined(__HAIKU__)
free((void *)wm);
#endif
lc++;
}
}
if (isshell) {
const char *shell = display_shell();
if (shell) {
printf("%s ", LOGO[lc]);
printf("%sShell%s: %s\n", color, reset, shell);
free((void *)shell);
lc++;
}
} else minsize--;
if (islibc) {
const char *libc = display_libc();
if (libc) {
printf("%s ", LOGO[lc]);
printf("%slibc%s: %s\n", color, reset, libc);
lc++;
}
}
if (iscpu) {
const char *cpu = display_cpu();
if (cpu) {
printf("%s ", LOGO[lc]);
printf("%sCPU%s: %s\n", color, reset, cpu);
lc++;
free((void *)cpu);
}
} else minsize--;
if (isgpu) {
const char *gpu = display_gpu();
if (gpu) {
printf("%s ", LOGO[lc]);
printf("%sGPU%s: %s\n", color, reset, gpu);
lc++;
free((void *)gpu);
}
}
if (ismemory) {
printf("%s ", LOGO[lc]);
printf("%s%s%s%s", color, "Memory", reset, ": ");
display_memory();
printf("\n");
lc++;
} else minsize--;
if (isstorage) {
const char *storage = display_storage();
if (storage) {
printf("%s ", LOGO[lc]);
printf("%sStorage%s: %s\n", color, reset, storage);
lc++;
free((void *)storage);
}
}
for (size_t i = lc; i < ls; i++) {
printf("%s\n", LOGO[i]);
}
return 0;
}

126
src/common.c Normal file
View File

@@ -0,0 +1,126 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
#include "common.h"
long long int run_command_lld(const char *command) {
char buf[128];
long long int res = 0;
FILE *p = popen(command, "r");
if (!p) {
fprintf(stderr, "コマンドを実効に失敗: %s", command);
return 0;
}
while (fgets(buf, sizeof(buf), p) != NULL) {
buf[strcspn(buf, "\n")] = '\0';
}
res = atoll(buf);
pclose(p);
return res;
}
const char *run_command_s(const char *command) {
char buf[128];
char *out = NULL;
size_t outsize = 0;
FILE *p = popen(command, "r");
if (!p) {
fprintf(stderr, "コマンドを実効に失敗: %s", command);
return NULL;
}
while (fgets(buf, sizeof(buf), p) != NULL) {
buf[strcspn(buf, "\n")] = '\0';
size_t len = strlen(buf);
char *nout = realloc(out, outsize + len + 1);
if (nout == NULL) {
perror("メモリの役割に失敗");
free(out);
pclose(p);
return NULL;
}
out = nout;
memccpy(out + outsize, buf, sizeof(buf), len);
outsize += len;
out[outsize] = '\0';
}
pclose(p);
return out;
}
#if !defined(__HAIKU__)
const char *from_cache(const char *file) {
struct stat st;
if (stat(file, &st) != 0) {
return NULL;
}
FILE *f = fopen(file, "r");
if (!f) {
return NULL;
}
char *cmd = (char *)malloc(128 * sizeof(char));
if (!cmd) {
fclose(f);
return NULL;
}
if (fgets(cmd, 128, f) == NULL) {
free(cmd);
fclose(f);
return NULL;
}
fclose(f);
cmd[strcspn(cmd, "\n")] = '\0';
return cmd;
}
int to_cache(const char *file, const char *res) {
char dir[256];
snprintf(dir, sizeof(dir), "%s", "/tmp/farfetch");
struct stat st;
if (stat(dir, &st) != 0) {
if (mkdir(dir, 0755) != 0 && errno != EEXIST) return -1;
}
FILE *f = fopen(file, "w");
if (!f) return -1;
fprintf(f, "%s", res);
fclose(f);
return 0;
}
void delete_cache() {
struct stat st;
if (stat("/tmp/farfetch/os", &st) == 0) remove("/tmp/farfetch/os");
if (stat("/tmp/farfetch/host", &st) == 0) remove("/tmp/farfetch/host");
#if defined(__linux__) || defined(__sunos)
if (stat("/tmp/farfetch/distro", &st) == 0) remove("/tmp/farfetch/distro");
#endif
if (stat("/tmp/farfetch/cpu", &st) == 0) remove("/tmp/farfetch/cpu");
if (stat("/tmp/farfetch/gpu", &st) == 0) remove("/tmp/farfetch/gpu");
}
#endif

12
src/common.h Normal file
View File

@@ -0,0 +1,12 @@
#ifndef COMMON_H
#define COMMON_H
long long int run_command_lld(const char *command);
const char *run_command_s(const char *command);
#if !defined(__HAIKU__)
const char *from_cache(const char *file);
int to_cache(const char *file, const char *res);
void delete_cache();
#endif
#endif

297
src/config.c Normal file
View File

@@ -0,0 +1,297 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
#include "config.h"
#include "logo/colors.h"
#if defined(__OpenBSD__)
#include "logo/openbsd.h"
#elif defined(__NetBSD__)
#include "logo/netbsd.h"
#elif defined(__FreeBSD__)
#include "logo/freebsd.h"
#elif defined(__linux__)
#include "logo/linux.h"
#include "distro.h"
#elif defined(__sun)
#include "logo/sunos.h"
#elif defined(__APPLE__)
#include "logo/macos.h"
#elif defined(__HAIKU__)
#include "logo/haiku.h"
#endif
bool islogob = true;
bool islogos = false;
bool islogod = true;
bool islogocustom = false;
#if defined(__linux__) || defined(__sunos)
bool islogodistro = false;
char *distrostring;
#endif
bool isos = true;
bool ishost = true;
#if defined(__linux__) || defined(__sunos)
bool isdistro = true;
#endif
bool isuptime = true;
#if defined(__OpenBSD__)
bool isrecording = true;
#endif
bool ispackages = true;
bool islibc = true;
bool isresolution = true;
bool iswm = true;
bool isshell = true;
bool iscpu = true;
bool isgpu = true;
bool ismemory = true;
bool isstorage = true;
bool isbiglogo = false;
bool issmalllogo = false;
bool mkbiglogo = false;
bool mksmalllogo = false;
size_t biglogoi = 0;
size_t smalllogoi = 0;
const char *customcolor;
const char *customtitlecolor;
const char *customlogobig;
const char *customlogosmall;
void rmstr(char *str, const char *sub) {
char *pos;
size_t len = strlen(sub);
while ((pos = strstr(str, sub)) != NULL) {
memmove(pos, pos + len, strlen(pos + len) + 1);
}
}
const char *applycolor(const char *color) {
if (strncmp(color, "grey", 4) == 0) return GREY;
else if (strncmp(color, "red", 3) == 0) return RED;
else if (strncmp(color, "green", 5) == 0) return GREEN;
else if (strncmp(color, "yellow", 6) == 0) return YELLOW;
else if (strncmp(color, "blue", 4) == 0) return BLUE;
else if (strncmp(color, "magenta", 7) == 0) return MAGENTA;
else if (strncmp(color, "cyan", 4) == 0) return CYAN;
else if (strncmp(color, "white", 5) == 0) return WHITE;
return RESET;
}
char *colrep(const char *str, const char *old, const char *new) {
char *res;
int i, count = 0;
int nlen = strlen(new);
int olen = strlen(old);
for (i = 0; str[i] != '\0'; i++) {
if (strstr(&str[i], old) == &str[i]) {
count++;
i += olen - 1;
}
}
res = (char *)malloc(i + count * (nlen - olen) + 1);
if (!res) {
return NULL;
}
i = 0;
while (*str) {
if (strstr(str, old) == str) {
memcpy(&res[i], new, strlen(new));
i += nlen;
str += olen;
} else {
res[i++] = *str++;
}
}
res[i] = '\0';
return res;
}
bool containvocab(const char *line, const char *word) {
const char *p = line;
size_t len = strlen(word);
while ((p = strstr(p, word)) != NULL) {
if (
(p == line || !isalnum((unsigned char)p[-1])) &&
!isalnum((unsigned char)p[len])
) return true;
p += len;
}
return false;
}
void getconf() {
char *homedir = getenv("HOME");
if (homedir == NULL) {
perror("ホームディレクトリを受取に失敗");
return;
}
#if defined(__HAIKU__)
char *basedir = "/config/settings/";
#else
char *basedir = "/.config/";
#endif
int alllen = snprintf(NULL, 0, "%s%s%s", homedir, basedir, "farfetch.conf") + 1;
char *cnfpath = malloc(alllen);
if (cnfpath == NULL) {
perror("メモリを割当に失敗");
return;
}
snprintf(cnfpath, alllen, "%s%s%s", homedir, basedir, "farfetch.conf");
if (access(cnfpath, F_OK) != 0) {
free(cnfpath);
return;
}
FILE *file = fopen(cnfpath, "r");
free(cnfpath);
if (!file) {
return;
}
char line[256];
while (fgets(line, sizeof(line), file)) {
if (line[0] == '#' || line[0] == '\n') continue;
if (strstr(line, "hide ") != NULL) {
if (containvocab(line, "logo")) islogod = false;
if (containvocab(line, "os")) isos = false;
if (containvocab(line, "host")) ishost = false;
#if defined(__linux__) || defined(__sunos)
if (containvocab(line, "distro")) isdistro = false;
#endif
if (containvocab(line, "uptime")) isuptime = false;
#if defined (__OpenBSD__)
if (containvocab(line, "recording")) isrecording = false;
#endif
if (containvocab(line, "packages")) ispackages = false;
if (containvocab(line, "libc")) islibc = false;
if (containvocab(line, "resolution")) isresolution = false;
if (containvocab(line, "wm")) iswm = false;
if (containvocab(line, "shell")) isshell = false;
if (containvocab(line, "cpu")) iscpu = false;
if (containvocab(line, "gpu")) isgpu = false;
if (containvocab(line, "memory")) ismemory = false;
if (containvocab(line, "storage")) isstorage = false;
}
// 色
if (strstr(line, "set color") != NULL) {
char color[10];
sscanf(line, "set color %s", color);
customcolor = applycolor(color);
}
if (strstr(line, "set titlecolor") != NULL) {
char color[10];
sscanf(line, "set titlecolor %s", color);
customtitlecolor = applycolor(color);
}
// デフォルトは大きいロゴ
if (strstr(line, "show logo") != NULL) {
if (containvocab(line, "small")) {
islogob = false;
islogos = true;
} else {
islogob = true;
islogos = false;
}
if (containvocab(line, "custom")) {
islogocustom = true;
#if defined(__linux__) || defined(__sunos)
} else {
distrostring = strdup(line);
if (!distrostring) {
perror("メモリの役割に失敗");
return;
}
rmstr(distrostring, "show logo");
if (containvocab(line, "small")) rmstr(distrostring, "small");
else rmstr(distrostring, "big");
rmstr(distrostring, "\n");
rmstr(distrostring, " ");
if (is_distro(distrostring)) islogodistro = true;
else distrostring = NULL;
#endif
}
}
// カスタムロゴ
if (strstr(line, "define custom big logo:") != NULL) {
mkbiglogo = true;
}
if (strstr(line, "define custom small logo:") != NULL) {
mksmalllogo = true;
}
if (mkbiglogo && islogocustom && islogob) {
isbiglogo = true;
if (strstr(line, "define custom big logo:") != NULL) {
continue;
} else if (strstr(line, "EOL") != NULL) {
mkbiglogo = false;
} else if (biglogoi < logosize) {
LOGO[biglogoi] = strdup(line);
LOGO[biglogoi] = colrep(LOGO[biglogoi], "[GREY]", GREY);
LOGO[biglogoi] = colrep(LOGO[biglogoi], "[RED]", RED);
LOGO[biglogoi] = colrep(LOGO[biglogoi], "[GREEN]", GREEN);
LOGO[biglogoi] = colrep(LOGO[biglogoi], "[YELLOW]", YELLOW);
LOGO[biglogoi] = colrep(LOGO[biglogoi], "[BLUE]", BLUE);
LOGO[biglogoi] = colrep(LOGO[biglogoi], "[MAGENTA]", MAGENTA);
LOGO[biglogoi] = colrep(LOGO[biglogoi], "[CYAN]", CYAN);
LOGO[biglogoi] = colrep(LOGO[biglogoi], "[WHITE]", WHITE);
LOGO[biglogoi] = colrep(LOGO[biglogoi], "[RESET]", RESET);
size_t len = strlen(LOGO[biglogoi]);
if (len > 0 && LOGO[biglogoi][len - 1] == '\n') {
LOGO[biglogoi][len - 1] = '\0';
}
biglogoi++;
free(LOGO[biglogoi]);
}
}
if (mksmalllogo && islogocustom && islogos) {
issmalllogo = true;
if (strstr(line, "define custom small logo:") != NULL) {
continue;
} else if (strstr(line, "EOL") != NULL) {
mksmalllogo = false;
} else if (smalllogoi < MIN_SIZE) {
LOGO_SMALL[smalllogoi] = strdup(line);
LOGO_SMALL[smalllogoi] = colrep(LOGO_SMALL[smalllogoi], "[GREY]", GREY);
LOGO_SMALL[smalllogoi] = colrep(LOGO_SMALL[smalllogoi], "[RED]", RED);
LOGO_SMALL[smalllogoi] = colrep(LOGO_SMALL[smalllogoi], "[GREEN]", GREEN);
LOGO_SMALL[smalllogoi] = colrep(LOGO_SMALL[smalllogoi], "[YELLOW]", YELLOW);
LOGO_SMALL[smalllogoi] = colrep(LOGO_SMALL[smalllogoi], "[BLUE]", BLUE);
LOGO_SMALL[smalllogoi] = colrep(LOGO_SMALL[smalllogoi], "[MAGENTA]", MAGENTA);
LOGO_SMALL[smalllogoi] = colrep(LOGO_SMALL[smalllogoi], "[CYAN]", CYAN);
LOGO_SMALL[smalllogoi] = colrep(LOGO_SMALL[smalllogoi], "[WHITE]", WHITE);
LOGO_SMALL[smalllogoi] = colrep(LOGO_SMALL[smalllogoi], "[RESET]", RESET);
size_t len = strlen(LOGO_SMALL[smalllogoi]);
if (len > 0 && LOGO_SMALL[smalllogoi][len - 1] == '\n') {
LOGO_SMALL[smalllogoi][len - 1] = '\0';
}
smalllogoi++;
free(LOGO[smalllogoi]);
}
}
}
fclose(file);
return;
}

44
src/config.h Normal file
View File

@@ -0,0 +1,44 @@
#ifndef CONFIG_H
#define CONFIG_H
#include <stdbool.h>
#include <unistd.h>
extern bool islogob;
extern bool islogos;
extern bool islogod;
extern bool islogocustom;
#if defined(__linux__) || defined(__sunos)
extern bool islogodistro;
extern char *distrostring;
#endif
extern bool isos;
extern bool ishost;
#if defined(__linux__) || defined(__sunos)
extern bool isdistro;
#endif
extern bool isuptime;
#if defined(__OpenBSD__)
extern bool isrecording;
#endif
extern bool ispackages;
extern bool islibc;
extern bool isresolution;
extern bool iswm;
extern bool isshell;
extern bool iscpu;
extern bool isgpu;
extern bool ismemory;
extern bool isstorage;
extern bool isbiglogo;
extern bool issmalllogo;
extern size_t biglogoi;
extern size_t smalllogoi;
extern const char *customcolor;
extern const char *customtitlecolor;
extern const char *customlogobig;
extern const char *customlogosmall;
void getconf();
#endif

137
src/cpu.c Normal file
View File

@@ -0,0 +1,137 @@
#include "cpu.h"
#include "common.h"
#include <stdio.h>
#include <stdlib.h>
#if defined(__OpenBSD__)
#include <string.h>
#include <sys/types.h>
#include <sys/sysctl.h>
void rm_junk(char *str, const char *sub) {
char *pos;
size_t len = strlen(sub);
while ((pos = strstr(str, sub)) != NULL)
memmove(pos, pos + len, strlen(pos + len) + 1);
}
const char *display_cpu() {
char *out = NULL;
char *model = NULL;
model = malloc(1024);
if (!model) return NULL;
long long ncpu = 0;
int mib[2];
size_t len = 1024;
// hw.model
mib[0] = CTL_HW;
mib[1] = HW_MODEL;
if (sysctl(mib, 2, model, &len, NULL, 0) != 0) {
perror("sysctl");
free(model);
return NULL;
}
// ゴミ文字の消し
rm_junk(model, "CPU ");
rm_junk(model, "Processor ");
rm_junk(model, "(R)");
rm_junk(model, "(TM)");
// hw.ncpu
mib[1] = HW_NCPU;
len = sizeof(ncpu);
if (sysctl(mib, 2, &ncpu, &len, NULL, 0) != 0) {
perror("sysctl");
free(model);
return NULL;
}
out = malloc(strlen(model) + 20);
if (!out) {
free(model);
return NULL;
}
snprintf(out, strlen(model) + 20, "%s (%lld core)", model, ncpu);
free(model);
return out;
}
#else
const char *display_cpu() {
#if !defined(__HAIKU__)
const char *out = from_cache("/tmp/farfetch/cpu");
if (out) return out;
#else
const char *out = NULL;
#endif
char *cmd = NULL;
#if defined(__NetBSD__)
cmd = malloc(256);
if (!cmd) return NULL;
snprintf(cmd, 256, "sysctl -n machdep.cpu_brand | sed 's/(R)//' | "
"sed 's/(TM)//' | sed 's/CPU //' | sed 's/Processor//' && "
"echo \" (\" && sysctl -n hw.ncpu && echo \" core)\"");
#elif defined(__FreeBSD__)
cmd = malloc(1024);
if (!cmd) return NULL;
snprintf(cmd, 1024, "sysctl -n hw.model | sed 's/(R)//' | "
"sed 's/(TM)//' | sed 's/CPU //' | sed 's/ Processor//' && "
"echo \" (\" && sysctl -n hw.ncpu && echo \" core)\"");
#elif defined(__sun)
cmd = malloc(1024);
if (!cmd) return NULL;
snprintf(cmd, 1024, "psrinfo -pv | tail -1 | "
"sed 's/(r)//g; s/ CPU//; s/^ *//; s/ $//' | awk '{$1=$1};1' && "
"echo \" (\" && psrinfo -p && echo \" core)\"");
#elif defined(__linux__)
cmd = "cat /proc/cpuinfo | awk -F '\\\\s*: | @' "
"'/model name|Hardware|Processor|^cpu model|chip type|^cpu type/ { "
"cpu=$2; if ($1 == \"Hardware\") exit } END { print cpu }' | "
"sed 's/(R)//' | sed 's/(TM)//' | sed 's/CPU //' | sed 's/ Processor//' | "
"sed 's/ [0-9]-Core//' && echo \" @ \" && "
"cat /proc/cpuinfo | grep \"cpu MHz\" | sort -nr | head -1 | "
"sed 's/^.*: //' | awk '{printf \"%.2f\", $1/1000}' && "
"echo \"GHz (\" && nproc && echo \" core)\"";
#elif defined(__HAIKU__)
const char *cpuname = run_command_s("sysinfo | grep \"CPU #0:\" | "
"sed 's/CPU #0: \"'// | sed 's/\"//' | sed 's/(R)//' | sed 's/(TM)//' | "
"sed 's/^.* Gen //' | sed 's/CPU //' | sed 's/ Processor//'");
const char *freq = run_command_s("sysinfo | grep -A1 \"CPU #0\" | tail -1 | "
"sed 's/^.*: //' | awk '{ printf \"%.2f\", $1 / 1000 }'");
long long int proc = run_command_lld("nproc");
cmd = (char *)malloc(128 * sizeof(char));
if (!cmd) return NULL;
snprintf(cmd, 128, "%s @ %sGHz (%lld core)", cpuname, freq, proc);
free((void *)cpuname);
free((void *)freq);
#elif defined(__APPLE__)
cmd = malloc(1024);
if (!cmd) return NULL;
snprintf(cmd, 1024, "sysctl -n machdep.cpu.brand_string | sed 's/(R)//' | "
"sed 's/(TM)//' | sed 's/CPU //' | sed 's/ Processor//' && "
"echo \" (\" && sysctl -n hw.logicalcpu_max && echo \" core)\"");
#else
return NULL;
#endif
if (!cmd) return NULL;
out = run_command_s(cmd);
#if !defined(__linux__)
free(cmd);
#endif
#if !defined(__HAIKU__)
to_cache("/tmp/farfetch/cpu", out);
#endif
return out;
}
#endif

6
src/cpu.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef CPU_H
#define CPU_H
const char *display_cpu();
#endif

180
src/distro.c Normal file
View File

@@ -0,0 +1,180 @@
#if defined(__linux__) || defined(__sun)
#include "distro.h"
#include "common.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
const char *distroname;
bool is_distro(const char *buf) {
#if defined(__sunos)
if (strncmp(buf, "openindiana") == 0) return 1;
else if (strncmp(buf, "omnios") == 0) return 1;
else if (strncmp(buf, "solaris") == 0) return 1;
#else
if (strncmp(buf, "alpine", sizeof("alpine")) == 0) return 1;
else if (strncmp(buf, "arch", sizeof("arch")) == 0) return 1;
else if (strncmp(buf, "arco", sizeof("arco")) == 0) return 1;
else if (strncmp(buf, "artix", sizeof("artix")) == 0) return 1;
else if (strncmp(buf, "centos", sizeof("centos")) == 0) return 1;
else if (strncmp(buf, "crux", sizeof("crux")) == 0) return 1;
else if (strncmp(buf, "debian", sizeof("debian")) == 0) return 1;
else if (strncmp(buf, "devuan", sizeof("devuan")) == 0) return 1;
else if (strncmp(buf, "fedora", sizeof("fedora")) == 0) return 1;
else if (strncmp(buf, "gentoo", sizeof("gentoo")) == 0) return 1;
else if (strncmp(buf, "hyperbola", sizeof("hyperbola")) == 0) return 1;
else if (strncmp(buf, "linuxmint", sizeof("linuxmint")) == 0) return 1;
else if (strncmp(buf, "manjaro", sizeof("manjaro")) == 0) return 1;
else if (strncmp(buf, "opensuse", sizeof("opensuse")) == 0) return 1;
else if (strncmp(buf, "parabola", sizeof("parabola")) == 0) return 1;
else if (strncmp(buf, "popos", sizeof("popos")) == 0) return 1;
else if (strncmp(buf, "postmarketos", sizeof("postmarketos")) == 0) return 1;
else if (strncmp(buf, "redhat", sizeof("redhat")) == 0) return 1;
else if (strncmp(buf, "rocky", sizeof("rocky")) == 0) return 1;
else if (strncmp(buf, "ubuntu", sizeof("ubuntu")) == 0) return 1;
else if (strncmp(buf, "void", sizeof("void")) == 0) return 1;
else if (strncmp(buf, "linux", sizeof("linux"))) return 1;
#endif
return 0;
}
const char *display_distro() {
char buf[1288];
char *out = NULL;
size_t outsize = 0;
const char *cmd = from_cache("/tmp/farfetch/distro");
if (cmd) {
return cmd;
}
if (access("/bedrock/etc/bedrock-release", F_OK) != -1) {
cmd = "cat /bedrock/etc/bedrock-release | grep '^PRETTY_NAME' | "
"cut -d '=' -f2 | tr -d '\"'";
} else if (access("/etc/redstar-release", F_OK) != -1) {
cmd = "echo \"Red Star OS\" && cat /etc/redstar-release | "
"awk -F'[^0-9]' '$0=$2'";
} else if (access("/etc/siduction-version", F_OK) != -1) {
cmd = "echo \"Siduction\" && lsb_release -sic | "
"grep '^PRETTY_NAME' | cut -d '=' -f2 | tr -d '\"'";
} else if (access("/etc/mcst_version", F_OK) != -1) {
cmd = "echo \"OS Elbrus\" && cat /etc/mcst_version | "
"grep '^PRETTY_NAME' | cut -d '=' -f2 | tr -d '\"'";
} else if (access("/etc/GoboLinuxVersion", F_OK) != -1) {
cmd = "echo \"GoboLinux\" && cat /etc/GoboLinuxVersion | "
"grep '^PRETTY_NAME' | cut -d '=' -f2 | tr -d '\"'";
} else if (access("/etc/os-release", F_OK) != -1) {
cmd = "if grep -q \"^PRETTY_NAME=\" /etc/os-release; then "
"grep '^PRETTY_NAME=' /etc/os-release | cut -d \"=\" -f2 | tr -d '\"'; "
"else "
"grep '^NAME=' /etc/os-release | cut -d \"=\" -f2 | tr -d '\"'; "
"fi";
} else if (access("/usr/lib/os-release", F_OK) != -1) {
cmd = "cat /usr/lib/os-release | "
"grep '^PRETTY_NAME' | cut -d '=' -f2 | tr -d '\"'";
} else if (access("/etc/openwrt_release", F_OK) != -1) {
cmd = "cat /etc/openwrt_release | "
"grep '^PRETTY_NAME' | cut -d '=' -f2 | tr -d '\"'";
} else if (access("/etc/lsb-release", F_OK) != -1) {
cmd = "cat /etc/lsb-release | "
"grep '^DISTRIB_DESCRIPTION' | cut -d '=' -f2 | tr -d '\"'";
} else {
perror("不明なディストリビューション。");
}
FILE *p = popen(cmd, "r");
if (!p) {
fprintf(stderr, "ディストロを見つけられるコマンドを実効に失敗: %s", cmd);
return NULL;
}
while (fgets(buf, sizeof(buf), p) != NULL) {
buf[strcspn(buf, "\n")] = '\0';
size_t len = strlen(buf);
char *nout = realloc(out, outsize + len + 1);
if (nout == NULL) {
perror("メモリの役割に失敗");
free(out);
pclose(p);
return NULL;
}
out = nout;
memccpy(out + outsize, buf, sizeof(buf), len);
outsize += len;
out[outsize] = '\0';
}
to_cache("/tmp/farfetch/distro", out);
pclose(p);
return out;
}
void get_distro() {
const char *buf = display_distro();
if (!buf) {
#if defined(__sunos)
distroname = "solaris";
#else
distroname = "linux";
#endif
return;
}
if (strstr(buf, "Alpine") != NULL) distroname = "alpine";
else if (strstr(buf, "Arch Linux") != NULL) distroname = "arch";
else if (strstr(buf, "ArcoLinux") != NULL) distroname = "arco";
else if (strstr(buf, "Artix Linux") != NULL) distroname = "artix";
else if (strstr(buf, "CentOS") != NULL) distroname = "centos";
else if (strstr(buf, "CRUX") != NULL) distroname = "crux";
else if (strstr(buf, "Debian") != NULL) distroname = "debian";
else if (strstr(buf, "Devuan") != NULL) distroname = "devuan";
else if (strstr(buf, "Fedora") != NULL) distroname = "fedora";
else if (strstr(buf, "Gentoo") != NULL) distroname = "gentoo";
else if (strstr(buf, "Hyperbola") != NULL) distroname = "hyperbola";
else if (strstr(buf, "Linux Mint") != NULL) distroname = "linuxmint";
else if (strstr(buf, "Manjaro") != NULL) distroname = "manjaro";
else if (strstr(buf, "OpenIndiana") != NULL) distroname = "openindiana";
else if (strstr(buf, "openSUSE") != NULL) distroname = "opensuse";
else if (strstr(buf, "OmniOS") != NULL) distroname = "omnios";
else if (strstr(buf, "Parabola") != NULL) distroname = "parabola";
else if (strstr(buf, "Pop!_OS") != NULL) distroname = "popos";
else if (strstr(buf, "postmarketOS") != NULL) distroname = "postmarketos";
else if (strstr(buf, "Red Hat") != NULL) distroname = "redhat";
else if (strstr(buf, "Rocky") != NULL) distroname = "rocky";
else if (strstr(buf, "Ubuntu") != NULL) distroname = "ubuntu";
else if (strstr(buf, "Void Linux") != NULL) distroname = "void";
#if defined(__sunos)
else distroname = "solaris";
#else
else distroname = "linux";
#endif
if (strncmp(distroname, "ubuntu", strlen("ubuntu")) == 0) {
const char *desktop = run_command_s("echo $XDG_CURRENT_DESKTOP");
if (strncmp(desktop, "KDE", strlen("KDE")) == 0) distroname = "kubuntu";
else if (strncmp(desktop, "XFCE", strlen("XFCE")) == 0) distroname = "xubuntu";
else if (strncmp(desktop, "LXQt", strlen("LXQt")) == 0) distroname = "lubuntu";
else if (strncmp(desktop, "MATE", strlen("MATE")) == 0) distroname = "ubuntumate";
else if (strncmp(desktop, "X-Cinnamon", strlen("X-Cinnamon")) == 0)
distroname = "ubuntucinnamon";
else if (strncmp(desktop, "Budgie:GNOME", strlen("Budgie:GNOME")) == 0)
distroname = "ubuntubudgie";
else if (strncmp(desktop, "Lomiri", strlen("Lomiri")) == 0)
distroname = "ubuntulomiri";
else if (strncmp(
desktop,
"Unity:Unity7:ubuntu",
strlen("Unity:Unity7:ubuntu")
) == 0)
distroname = "ubuntuunity";
}
}
#endif

14
src/distro.h Normal file
View File

@@ -0,0 +1,14 @@
#if defined(__linux__) || defined(__sun)
#ifndef DISTRO_H
#define DISTRO_H
#include <stdbool.h>
bool is_distro(const char *buf);
const char *display_distro();
void get_distro();
extern const char *distroname;
#endif
#endif

143
src/gpu.c Normal file
View File

@@ -0,0 +1,143 @@
#include "gpu.h"
#include "common.h"
#include <stdio.h>
#include <stdlib.h>
#if !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__FreeBSD__) &&\
!defined(__linux__) && !defined(__DragonFly__) && !defined(__APPLE__) &&\
!defined(__HAIKU__)
#include <unistd.h>
#endif
#if defined(__FreeBSD__) || defined(__Dragonfly__) || defined(__HAIKU__)
#include <string.h>
#endif
const char *display_gpu() {
#if !defined(__HAIKU__)
const char *out = from_cache("/tmp/farfetch/gpu");
if (out) return out;
#else
const char *out = NULL;
#endif
char *cmd = NULL;
#if defined(__OpenBSD__) || defined(__NetBSD__)
cmd = malloc(2048);
if (!cmd) return NULL;
snprintf(cmd, 2048, "dmesg | "
"if [ \"$(dmesg | grep \"radeondrm.* at pci.*\")\" ]; "
"then grep -i \"radeondrm.* at pci.*\"; "
"elif [ \"$(dmesg | grep \"inteldrm.* at pci.*\")\" ]; "
"then grep -i \"inteldrm.* at pci.*\"; "
"elif [ \"$(dmesg | grep \"amdgpu.* at pci.*\")\" ]; "
"then grep -i \"amdgpu.* at pci.*\"; "
"elif [ \"$(dmesg | grep \"agp.* at intagp.*\")\" ]; "
"then grep -i \"agp.* at intagp.*\"; "
"elif [ \"$(dmesg | grep \"intagp.* at inteldrm.*\")\" ]; "
"then grep -i \"intagp.* at inteldrm.*\"; "
"elif [ \"$(dmesg | grep \"drm.* at inteldrm.*\")\" ]; "
"then grep -i \"drm.* at inteldrm.*\"; "
"elif [ \"$(dmesg | grep \"drm.* at radeondrm.*\")\" ]; "
"then grep -i \"drm.* at radeondrm.*\"; "
"elif [ \"$(dmesg | grep \"drm.* at amdgpu.*\")\" ]; "
"then grep -i \"drm.* at amdgpu.*\"; "
"elif [ \"$(dmesg | grep \"wsdisplay.* at amdgpu.*\")\" ]; "
"then grep -i \"wsdisplay.* at amdgpu.*\"; "
"elif [ \"$(dmesg | grep \"i915drmkms.* at pci.*\")\" ]; "
"then grep -i \"i915drmkms.* at pci.*\"; "
"elif [ \"$(dmesg | grep \"nouveau.* at pci.*\")\" ]; "
"then grep -i \"nouveau.* at pci.*\"; "
"elif [ \"$(dmesg | grep \"radeon.* at pci.*\")\" ]; "
"then grep -i \"radeon.* at pci.*\"; "
"elif [ \"$(dmesg | grep \"rkdrm.* at fdt.*\")\" ]; "
"then grep -i \"rkdrm.* at fdt.*\"; "
"elif [ \"$(dmesg | grep \"sunxidrm.* at fdt.*\")\" ]; "
"then grep -i \"sunxidrm.* at fdt.*\"; "
"elif [ \"$(dmesg | grep \"tegradrm.* at fdt.*\")\" ]; "
"then grep -i \"tegradrm.* at fdt.*\"; "
"elif [ \"$(dmesg | grep \"viadrmums.* at drm.*\")\" ]; "
"then grep -i \"viadrmums.* at drm.*\"; "
"else grep -i \"graphics\"; fi | "
"sed 's/^.*: //' | "
"sed 's/^.* \"//' | "
"sed 's/\".*$//' | head -1");
#elif defined(__FreeBSD__) || defined(__DragonFly__)
const char *test = run_command_s("pciconf -lv | grep -B 4 -F \"VGA\" | head -1");
if (!strstr(test, "vgapci")) {
free((void *)test);
return NULL;
}
free((void *)test);
cmd = malloc(256);
if (!cmd) return NULL;
snprintf(cmd, 256, "pciconf -lv | grep -B 4 -F \"VGA\" | "
"grep -F \"device\" | sed 's/^.* device//' | "
"sed \"s/^.* '//\" | sed \"s/'//\" | tail -1 | "
"sed 's/ Core Processor Integrated Graphics Controller//'");
#elif defined(__sun)
cmd = malloc(512);
if (!cmd) return NULL;
snprintf(cmd, 512, "prtconf -v | grep -A 30 \"value='display'\" | "
"grep -A 1 vendor-name | tail -1 | sed 's/^.*value=//' | sed \"s/'//g\" | "
"sed 's/ Corporation//' && echo \" \" && prtconf -v | "
"grep -A 30 \"value='display'\" | grep -A 1 device-name | tail -1 | "
"sed 's/^.*value=//' | sed \"s/'//g\"");
#elif defined(__linux__)
cmd = malloc(256);
if (!cmd) return NULL;
snprintf(cmd, 256, "lspci | grep VGA | sed 's/^.*: //' | "
"sed 's/Corporation //' | sed 's/ (.*$//' | "
"sed 's/Advanced Micro Devices//' | "
"sed 's/, Inc. //' | sed 's/Navi [0-9]* //' | "
"sed 's/\\[//g' | sed 's/\\]//g'");
#elif defined(__APPLE__)
cmd = malloc(128);
if (!cmd) return NULL;
snprintf(cmd, 128, "system_profiler SPDisplaysDataType | "
"awk -F': ' '/^ *Chipset Model:/ {printf $2 \", \"}'");
#elif defined(__HAIKU__)
const char *vendor = run_command_s("listdev | grep -A1 \"device Display\" | "
"tail -1 | sed 's/^.*: //' | sed 's/ Corporation//'");
const char *device = run_command_s("listdev | grep -A2 \"device Display\" | "
"tail -1 | sed 's/^.*: //'");
char *cmd = (char *)malloc(128 * sizeof(char));
if (!cmd) return NULL;
if (strncmp(vendor, device, strlen(device)) == 0) {
snprintf(cmd, 128, "%s", device);
free((void *)device);
} else {
snprintf(cmd, 128, "%s %s", device, vendor);
free((void *)device);
free((void *)vendor);
}
#else
if (
access("/bin/glxinfo", F_OK) == -1 &&
access("/usr/bin/glxinfo", F_OK) == -1 &&
access("/usr/local/bin/glxinfo", F_OK) == -1 &&
access("/usr/X11R6/bin/glxinfo", F_OK) == -1 &&
access("/usr/X11R7/bin/glxinfo", F_OK) == -1 &&
access("/usr/pkg/bin/glxinfo", F_OK) == -1
) return NULL;
cmd = malloc(256);
if (!cmd) return NULL;
snprintf(cmd, 256, "glxinfo -B | grep -F 'OpenGL renderer string' | "
"sed 's/OpenGL renderer string: //' | sed 's/Mesa //' | "
"sed 's/DRI //' | sed 's/(R)//' | sed 's/(.*$//'");
#endif
if (!cmd) return NULL;
out = run_command_s(cmd);
free((void *)cmd);
#if !defined(__HAIKU__)
if (out) to_cache("/tmp/farfetch/gpu", out);
#endif
return out;
}

6
src/gpu.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef GPU_H
#define GPU_H
const char *display_gpu();
#endif

86
src/host.c Normal file
View File

@@ -0,0 +1,86 @@
#include "host.h"
#include "common.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#if defined(__linux__)
#include <unistd.h>
#endif
const char *display_host() {
#if !defined(__HAIKU__)
char *out = (char *)from_cache("/tmp/farfetch/host");
if (out) return out;
#else
char *out = NULL;
#endif
const char *cmd = NULL;
#if defined(__OpenBSD__)
cmd = "sysctl -n hw.vendor && echo \" \" && "
"if [ \"$(sysctl -n hw.version 2>&1)\" != "
"\"sysctl: hw.version: value is not available\" ]; then "
"sysctl -n hw.version && echo \" \"; fi && "
"sysctl -n hw.product";
#elif defined(__FreeBSD__)
cmd = "kenv | grep smbios.system.family | sed 's/\"//g' | "
"sed 's/smbios.system.family=//' && "
"kenv | grep smbios.system.version | sed 's/\"//g' | "
"sed 's/smbios.system.version=//' && "
"kenv | grep smbios.system.product | sed 's/\"//g' | "
"sed 's/smbios.system.product=//' && "
"kenv | grep smbios.system.maker | sed 's/\"//g' | "
"sed 's/smbios.system.maker=//'";
#elif defined(__NetBSD__)
cmd = "sysctl -n machdep.dmi.system-vendor && "
"echo \" \" && sysctl -n machdep.dmi.system-version && "
"echo \" \" && sysctl -n machdep.dmi.system-product";
#elif defined(__sun)
cmd = "smbios | grep \"Product\" | "
"sed 's/ Product: //' | awk '{$1=$1};1' | head -1";
#elif defined(__linux__)
const char *pre_cmd = NULL;
if (access("/system/app/", F_OK) != -1) {
pre_cmd = "getprop ro.product.brand && echo \" \" && getprop ro.product.model";
} else if (
access("/sys/devices/virtual/dmi/id/product_name", F_OK) != -1 &&
access("/sys/devices/virtual/dmi/id/product_version", F_OK) != 1
) {
pre_cmd = "cat /sys/devices/virtual/dmi/id/product_name && echo \" \" && "
"cat /sys/devices/virtual/dmi/id/product_version";
} else if (access("/sys/firmware/devicetree/base/model", F_OK) != -1) {
pre_cmd = "cat /sys/firmware/devicetree/base/model";
} else if (access("/tmp/sysinfo/model", F_OK) != 1) {
pre_cmd = "cat /tmp/sysinfo/model";
} else {
return "Unknown";
}
size_t cmdlen = 1024;
cmd = malloc(cmdlen);
if (!cmd) return "Unknown";
snprintf((char *)cmd, cmdlen, "%s | sed '/To be filled by O.E.M./d; "
"/To Be Filled By O.E.M./d; /OEM/d; /Not Applicable/d; "
"/System Product Name/d; /System Version/d; /Undefined/d; /Default string/d; "
"/Not Specified/d; /Type1ProductConfigId/d; /INVALID/d; "
"/All Series/d' ", pre_cmd);
#elif defined(__APPLE__)
cmd = "sysctl -n hw.model";
#endif
if (!cmd) return "Unknown";
out = (char *)run_command_s(cmd);
#if defined(__linux__)
free((void *)cmd);
#endif
#if !defined(__HAIKU__)
to_cache("/tmp/farfetch/host", out);
#endif
return out;
}

6
src/host.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef HOST_H
#define HOST_H
const char *display_host();
#endif

24
src/libc.c Normal file
View File

@@ -0,0 +1,24 @@
#include "libc.h"
#include "common.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
const char *display_libc() {
#if defined(__linux__)
const char *musl = run_command_s("ldd $(which ls) | grep libc | grep musl");
if (musl != NULL && strlen(musl) != 0) {
free((void *)musl);
return "musl";
}
const char *glibc = run_command_s("ldd $(which ls) | grep libc | grep gnu");
if (glibc != NULL && strlen(glibc) != 0) {
free((void *)glibc);
return "glibc";
}
#endif
return NULL;
}

6
src/libc.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef LIBC_H
#define LIBC_H
const char *display_libc();
#endif

22
src/logo/colors.h Normal file
View File

@@ -0,0 +1,22 @@
#ifndef LOGO_COLORS_H
#define LOGO_COLORS_H
#if defined(__OpenBSD__) || defined(__linux__) || defined(__sun)
#define MIN_SIZE 15
#else
#define MIN_SIZE 14
#endif
#define LOGO_SIZE 24
#define GREY "\e[1;30m"
#define RED "\e[1;31m"
#define GREEN "\e[1;32m"
#define YELLOW "\e[1;33m"
#define BLUE "\e[1;34m"
#define MAGENTA "\e[1;35m"
#define CYAN "\e[1;36m"
#define WHITE "\e[1;37m"
#define RESET "\e[0m"
#endif

80
src/logo/freebsd.c Normal file
View File

@@ -0,0 +1,80 @@
#if defined(__FreeBSD__)
#include "freebsd.h"
#include "../config.h"
#include "../resolution.h"
#include "../wm.h"
#include <string.h>
#include <stdlib.h>
char *LOGO[23];
char *LOGO_SMALL[23];
const char *color;
const char *titlecolor;
size_t logosize = 16;
int minsize = MIN_SIZE;
void getOS() {
if (!customcolor) color = RED;
else color = customcolor;
if (!customtitlecolor) titlecolor = RED;
else titlecolor = customtitlecolor;
const char *res = display_resolution();
if (!res) minsize--;
else free((void *)res);
const char *wm = display_wm();
if (!wm) minsize--;
else free((void *)wm);
if (!isbiglogo && !issmalllogo) {
for (int i = 0; i < LOGO_SIZE; i++) {
LOGO[i] = NULL;
LOGO_SMALL[i] = NULL;
}
}
if (!isbiglogo) {
LOGO[0] = WHITE "``` " RED "` " RESET;
LOGO[1] = WHITE " ` `.....---..." RED "....--.``` -/ " RESET;
LOGO[2] = WHITE " +o .--` " RED "/y:` +. " RESET;
LOGO[3] = WHITE " yo`:. " RED ":o `+- " RESET;
LOGO[4] = WHITE " y/ " RED "-/` -o/ " RESET;
LOGO[5] = WHITE " .- " RED "::/sy+:. " RESET;
LOGO[6] = WHITE " / " RED "`-- / " RESET;
LOGO[7] = WHITE " `: " RED ":` " RESET;
LOGO[8] = WHITE " `: " RED ":` " RESET;
LOGO[9] = WHITE " / " RED "/ " RESET;
LOGO[10] = WHITE " .- " RED "-. " RESET;
LOGO[11] = WHITE " -- " RED "-. " RESET;
LOGO[12] = WHITE " `:` " RED "`:` " RESET;
LOGO[13] = RED " .-- `--. " RESET;
LOGO[14] = RED " .---.....----. " RESET;
LOGO[15] = RED " " RESET;
} else {
logosize = biglogoi;
if (biglogoi < (size_t)minsize) {
for (size_t i = biglogoi; i < (size_t)minsize; i++) {
LOGO[i] = WHITE " " RESET;
}
}
}
if (!issmalllogo) {
LOGO_SMALL[0] = RED "/\\,-'''''-,/\\ " RESET;
LOGO_SMALL[1] = RED "\\_) (_/ " RESET;
LOGO_SMALL[2] = RED "| | " RESET;
LOGO_SMALL[3] = RED "| | " RESET;
LOGO_SMALL[4] = RED " ; ; " RESET;
LOGO_SMALL[5] = RED " '-_____-' " RESET;
for (int i = 6; i < minsize; i++) {
LOGO_SMALL[i] = RED " " RESET;
}
} else {
if (smalllogoi < (size_t)minsize) {
for (size_t i = smalllogoi; i < (size_t)minsize; i++) {
LOGO_SMALL[i] = WHITE " " RESET;
}
}
}
}
#endif

17
src/logo/freebsd.h Normal file
View File

@@ -0,0 +1,17 @@
#if defined(__FreeBSD__)
#ifndef LOGO_FREEBSD_H
#define LOGO_FREEBSD_H
#include <stdio.h>
#include "colors.h"
extern char *LOGO[23];
extern char *LOGO_SMALL[23];
extern const char *color;
extern const char *titlecolor;
extern size_t logosize;
void getOS();
#endif
#endif

81
src/logo/haiku.c Normal file
View File

@@ -0,0 +1,81 @@
#if defined(__HAIKU__)
#include "haiku.h"
#include "../config.h"
#include "../resolution.h"
#include <string.h>
#include <stdlib.h>
char *LOGO[23];
char *LOGO_SMALL[23];
const char *color;
const char *titlecolor;
size_t logosize = 20;
int minsize = MIN_SIZE;
void getOS() {
if (!customcolor) color = GREEN;
else color = customcolor;
if (!customtitlecolor) titlecolor = RED;
else titlecolor = customtitlecolor;
const char *res = display_resolution();
if (!res) minsize--;
else free((void *)res);
if (!isbiglogo && !issmalllogo) {
for (int i = 0; i < LOGO_SIZE; i++) {
LOGO[i] = NULL;
LOGO_SMALL[i] = NULL;
}
}
if (!isbiglogo) {
LOGO[0] = YELLOW " / " RESET;
LOGO[1] = YELLOW " // " RESET;
LOGO[2] = YELLOW " / \\ " RESET;
LOGO[3] = YELLOW " / - " RESET;
LOGO[4] = YELLOW " / \\ " RESET;
LOGO[5] = YELLOW " \\ \\ " RESET;
LOGO[6] = YELLOW " - / " RESET;
LOGO[7] = YELLOW "/ / " RESET;
LOGO[8] = YELLOW "| \\ " RESET;
LOGO[9] = YELLOW "| \\ " RESET;
LOGO[10] = YELLOW "\\ \\ " RESET;
LOGO[11] = YELLOW "- - " RESET;
LOGO[12] = YELLOW "\\ \\ " RESET;
LOGO[13] = YELLOW " \\ \\ " RESET;
LOGO[14] = YELLOW " \\ / " RESET;
LOGO[15] = YELLOW " \\ / " RESET;
LOGO[16] = YELLOW " \\ / " RESET;
LOGO[17] = YELLOW " | | " RESET;
LOGO[18] = YELLOW " | | " RESET;
LOGO[19] = YELLOW " |_| " RESET;
} else {
logosize = biglogoi;
if (biglogoi < (size_t)minsize) {
for (size_t i = biglogoi; i < (size_t)minsize; i++) {
LOGO[i] = WHITE " " RESET;
}
}
}
if (!issmalllogo) {
LOGO_SMALL[0] = YELLOW " / " RESET;
LOGO_SMALL[1] = YELLOW " / \\ " RESET;
LOGO_SMALL[2] = YELLOW "/ | " RESET;
LOGO_SMALL[3] = YELLOW "| | " RESET;
LOGO_SMALL[4] = YELLOW "\\ / " RESET;
LOGO_SMALL[5] = YELLOW " || " RESET;
LOGO_SMALL[6] = YELLOW " || " RESET;
for (int i = 7; i < minsize; i++) {
LOGO_SMALL[i] = YELLOW " " RESET;
}
} else {
if (smalllogoi < (size_t)minsize) {
for (size_t i = smalllogoi; i < (size_t)minsize; i++) {
LOGO_SMALL[i] = WHITE " " RESET;
}
}
}
}
#endif

17
src/logo/haiku.h Normal file
View File

@@ -0,0 +1,17 @@
#if defined(__HAIKU__)
#ifndef LOGO_HAIKU_H
#define LOGO_HAIKU_H
#include <stdio.h>
#include "colors.h"
extern char *LOGO[23];
extern char *LOGO_SMALL[23];
extern const char *color;
extern const char *titlecolor;
extern size_t logosize;
void getOS();
#endif
#endif

1652
src/logo/linux.c Normal file

File diff suppressed because it is too large Load Diff

19
src/logo/linux.h Normal file
View File

@@ -0,0 +1,19 @@
#if defined(__linux__)
#ifndef LOGO_LINUX_H
#define LOGO_LINUX_H
#include <stdio.h>
#include "../distro.h"
#include "colors.h"
extern char *LOGO[23];
extern char *LOGO_SMALL[23];
extern const char *color;
extern const char *titlecolor;
extern const char *logoname;
extern size_t logosize;
void getDistro(const char *distroname);
#endif
#endif

72
src/logo/macos.c Normal file
View File

@@ -0,0 +1,72 @@
#if defined(__APPLE__)
#include "macos.h"
#include "../config.h"
#include "../packages.h"
#include <string.h>
#include <stdlib.h>
char *LOGO[23];
char *LOGO_SMALL[23];
const char *color;
const char *titlecolor;
size_t logosize = 17;
int minsize = MIN_SIZE;
void getOS() {
if (!customcolor) color = YELLOW;
else color = customcolor;
if (!customtitlecolor) titlecolor = GREEN;
else titlecolor = customtitlecolor;
const char *pac = display_packages();
if (!pac) minsize--;
else free((void *)pac);
if (!isbiglogo) {
LOGO[0] = GREEN " 'c. " RESET;
LOGO[1] = GREEN " ,xNMM. " RESET;
LOGO[2] = GREEN " .OMMMMo " RESET;
LOGO[3] = GREEN " OMMM0, " RESET;
LOGO[4] = GREEN " .;loddo:' loolloddol;. " RESET;
LOGO[5] = GREEN " cKMMMMMMMMMMNWMMMMMMMMMM0: " RESET;
LOGO[6] = YELLOW " .KMMMMMMMMMMMMMMMMMMMMMMMWd. " RESET;
LOGO[7] = YELLOW " XMMMMMMMMMMMMMMMMMMMMMMMX. " RESET;
LOGO[8] = RED ";MMMMMMMMMMMMMMMMMMMMMMMM: " RESET;
LOGO[9] = RED ":MMMMMMMMMMMMMMMMMMMMMMMM: " RESET;
LOGO[10] = RED ".MMMMMMMMMMMMMMMMMMMMMMMMX. " RESET;
LOGO[11] = RED " kMMMMMMMMMMMMMMMMMMMMMMMMWd. " RESET;
LOGO[12] = MAGENTA " .XMMMMMMMMMMMMMMMMMMMMMMMMMMk " RESET;
LOGO[13] = MAGENTA " .XMMMMMMMMMMMMMMMMMMMMMMMMK. " RESET;
LOGO[14] = BLUE " kMMMMMMMMMMMMMMMMMMMMMMd " RESET;
LOGO[15] = BLUE " ;KMMMMMMMWXXWMMMMMMMk. " RESET;
LOGO[16] = BLUE " .cooc,. .,coo:. " RESET;
} else {
logosize = biglogoi;
if (biglogoi < (size_t)minsize) {
for (size_t i = biglogoi; i < (size_t)minsize; i++) {
LOGO[i] = WHITE " " RESET;
}
}
}
if (!issmalllogo) {
LOGO_SMALL[0] = GREEN " .:' " RESET;
LOGO_SMALL[1] = GREEN " _ :'_ " RESET;
LOGO_SMALL[2] = YELLOW " .'`_`-'_``. " RESET;
LOGO_SMALL[3] = YELLOW ":________.-' " RESET;
LOGO_SMALL[4] = RED ":_______: " RESET;
LOGO_SMALL[5] = RED ":_______: " RESET;
LOGO_SMALL[6] = MAGENTA " :_______`-; " RESET;
LOGO_SMALL[7] = BLUE " `._.-._.' " RESET;
for (int i = 8; i < minsize; i++) {
LOGO_SMALL[i] = RED " " RESET;
}
} else {
if (smalllogoi < (size_t)minsize) {
for (size_t i = smalllogoi; i < (size_t)minsize; i++) {
LOGO_SMALL[i] = WHITE " " RESET;
}
}
}
}
#endif

17
src/logo/macos.h Normal file
View File

@@ -0,0 +1,17 @@
#if defined(__APPLE__)
#ifndef LOGO_MACOS_H
#define LOGO_MACOS_H
#include <stdio.h>
#include "colors.h"
extern char *LOGO[23];
extern char *LOGO_SMALL[23];
extern const char *color;
extern const char *titlecolor;
extern size_t logosize;
void getOS();
#endif
#endif

76
src/logo/netbsd.c Normal file
View File

@@ -0,0 +1,76 @@
#if defined(__NetBSD__)
#include "netbsd.h"
#include "../config.h"
#include "../resolution.h"
#include "../wm.h"
#include <string.h>
#include <stdlib.h>
char *LOGO[23];
char *LOGO_SMALL[23];
const char *color;
const char *titlecolor;
size_t logosize = 18;
int minsize = MIN_SIZE;
void getOS() {
if (!customcolor) color = MAGENTA;
else color = customcolor;
if (!customtitlecolor) titlecolor = MAGENTA;
else titlecolor = customtitlecolor;
const char *res = display_resolution();
if (!res) minsize--;
else free((void *)res);
const char *wm = display_wm();
if (!wm) minsize--;
else free((void *)wm);
if (!isbiglogo) {
LOGO[0] = MAGENTA " `-/oshdmNMNdhyo+:-` " RESET;
LOGO[1] = WHITE "y" MAGENTA "/s+:-`` `.-:+oydNMMMMNhs/-`` " RESET;
LOGO[2] = WHITE "-m+" MAGENTA "NMMMMMMMMMMMMMMMMMMMNdhmNMMMmdhs+/-` " RESET;
LOGO[3] = WHITE " -m+" MAGENTA "NMMMMMMMMMMMMMMMMMMMMmy+:` " RESET;
LOGO[4] = WHITE " -N/" MAGENTA "dMMMMMMMMMMMMMMMds:` " RESET;
LOGO[5] = WHITE " -N/" MAGENTA "hMMMMMMMMMmho:` " RESET;
LOGO[6] = WHITE " -N/" MAGENTA "-:/++/:.` " RESET;
LOGO[7] = WHITE " :M+ " RESET;
LOGO[8] = WHITE " :Mo " RESET;
LOGO[9] = WHITE " :Ms " RESET;
LOGO[10] = WHITE " :Ms " RESET;
LOGO[11] = WHITE " :Ms " RESET;
LOGO[12] = WHITE " :Ms " RESET;
LOGO[13] = WHITE " :Ms " RESET;
LOGO[14] = WHITE " :Ms " RESET;
LOGO[15] = WHITE " :Ms " RESET;
LOGO[16] = WHITE " :Ms " RESET;
LOGO[17] = WHITE " " RESET;
} else {
logosize = biglogoi;
if (biglogoi < (size_t)minsize) {
for (size_t i = biglogoi; i < (size_t)minsize; i++) {
LOGO[i] = WHITE " " RESET;
}
}
}
if (!issmalllogo) {
LOGO_SMALL[0] = "\\\\" MAGENTA "\\`-______,----__ " RESET;
LOGO_SMALL[1] = " \\\\ " MAGENTA "__,---\\`_ " RESET;
LOGO_SMALL[2] = " \\\\ " MAGENTA "\\`.____ " RESET;
LOGO_SMALL[3] = " \\\\" MAGENTA "-______,----\\`- " RESET;
LOGO_SMALL[4] = " \\\\ " RESET;
LOGO_SMALL[5] = " \\\\ " RESET;
LOGO_SMALL[6] = " \\\\ " RESET;
for (int i = 7; i < minsize; i++) {
LOGO_SMALL[i] = MAGENTA " " RESET;
}
} else {
if (smalllogoi < (size_t)minsize) {
for (size_t i = smalllogoi; i < (size_t)minsize; i++) {
LOGO_SMALL[i] = WHITE " " RESET;
}
}
}
}
#endif

17
src/logo/netbsd.h Normal file
View File

@@ -0,0 +1,17 @@
#if defined(__NetBSD__)
#ifndef LOGO_NETBSD_H
#define LOGO_NETBSD_H
#include <stdio.h>
#include "colors.h"
extern char *LOGO[23];
extern char *LOGO_SMALL[23];
extern const char *color;
extern const char *titlecolor;
extern size_t logosize;
void getOS();
#endif
#endif

89
src/logo/openbsd.c Normal file
View File

@@ -0,0 +1,89 @@
#if defined(__OpenBSD__)
#include "openbsd.h"
#include "../config.h"
#include "../resolution.h"
#include "../wm.h"
#include <string.h>
#include <stdlib.h>
char *LOGO[23];
char *LOGO_SMALL[23];
const char *color;
const char *titlecolor;
size_t logosize = 23;
int minsize = MIN_SIZE;
void getOS() {
if (!customcolor) color = YELLOW;
else color = customcolor;
if (!customtitlecolor) titlecolor = YELLOW;
else titlecolor = customtitlecolor;
const char *res = display_resolution();
if (!res) minsize--;
else free((void *)res);
const char *wm = display_wm();
if (!wm) minsize--;
else free((void *)wm);
if (!isbiglogo && !issmalllogo) {
for (int i = 0; i < LOGO_SIZE; i++) {
LOGO[i] = NULL;
LOGO_SMALL[i] = NULL;
}
}
if (!isbiglogo) {
LOGO[0] = CYAN " _ " RESET;
LOGO[1] = CYAN " (_) " RESET;
LOGO[2] = YELLOW " | . " RESET;
LOGO[3] = YELLOW " . |L /| . " CYAN "_ " RESET;
LOGO[4] = YELLOW " _ . |\\ _| \\--+._/| . " CYAN " (_) " RESET;
LOGO[5] = YELLOW " / ||\\| Y J ) / |/| ./ " RESET;
LOGO[6] = YELLOW " J |)'( | ` F`.'/ " CYAN " _ " RESET;
LOGO[7] = YELLOW " -<| F __ .-< " CYAN " (_) " RESET;
LOGO[8] = YELLOW " | / .-'" CYAN "." YELLOW " `. /" CYAN "-. " YELLOW "L___ " RESET;
LOGO[9] = YELLOW " J \\ < " CYAN "\\ " YELLOW " | |" GREY " O" CYAN "\\" YELLOW "|.-' " CYAN " _ " RESET;
LOGO[10] = YELLOW " _J \\ .- \\" CYAN "/" GREY " O " CYAN "|" YELLOW" | \\ |F " CYAN " (_) " RESET;
LOGO[11] = YELLOW " '-F -<_. \\ .-' `-' L__ " RESET;
LOGO[12] = YELLOW "__J _ _. >-' )" RED "._." YELLOW " |-' " RESET;
LOGO[13] = YELLOW " `-|.' /_. " RED "\\_|" YELLOW " F " RESET;
LOGO[14] = YELLOW " /.- . _.< " RESET;
LOGO[15] = YELLOW " /' /.' .' `\\ " RESET;
LOGO[16] = YELLOW " /L /' |/ _.-'-\\ " RESET;
LOGO[17] = YELLOW " /'J ___.---'\\| " RESET;
LOGO[18] = YELLOW " |\\ .--' V | `. ` " RESET;
LOGO[19] = YELLOW " |/`. `-. `._) " RESET;
LOGO[20] = YELLOW " / .-.\\ " RESET;
LOGO[21] = YELLOW " \\ ( `\\ " RESET;
LOGO[22] = YELLOW " `.\\ " RESET;
LOGO[22] = YELLOW " " RESET;
} else {
logosize = biglogoi;
if (biglogoi < (size_t)minsize) {
for (size_t i = biglogoi; i < (size_t)minsize; i++) {
LOGO[i] = WHITE " " RESET;
}
}
}
if (!issmalllogo) {
LOGO_SMALL[0] = YELLOW " _____ " RESET;
LOGO_SMALL[1] = YELLOW " \\- -/ " RESET;
LOGO_SMALL[2] = YELLOW " \\_/ \\ " RESET;
LOGO_SMALL[3] = YELLOW " | " WHITE "O O" YELLOW" | " RESET;
LOGO_SMALL[4] = YELLOW " |_ < ) 3 ) " RESET;
LOGO_SMALL[5] = YELLOW " / \\ / " RESET;
LOGO_SMALL[6] = YELLOW " /-_____-\\ " RESET;
for (int i = 7; i < minsize; i++) {
LOGO_SMALL[i] = YELLOW " " RESET;
}
} else {
if (smalllogoi < (size_t)minsize) {
for (size_t i = smalllogoi; i < (size_t)minsize; i++) {
LOGO_SMALL[i] = WHITE " " RESET;
}
}
}
}
#endif

17
src/logo/openbsd.h Normal file
View File

@@ -0,0 +1,17 @@
#if defined(__OpenBSD__)
#ifndef LOGO_OPENBSD_H
#define LOGO_OPENBSD_H
#include <stdio.h>
#include "colors.h"
extern char *LOGO[23];
extern char *LOGO_SMALL[23];
extern const char *color;
extern const char *titlecolor;
extern size_t logosize;
void getOS();
#endif
#endif

128
src/logo/sunos.c Normal file
View File

@@ -0,0 +1,128 @@
#if defined(__sun)
#include "sunos.h"
#include "../config.h"
#include "../resolution.h"
#include "../wm.h"
#include <string.h>
#include <string.h>
#include <stdlib.h>
char *LOGO[23];
char *LOGO_SMALL[23];
const char *color;
const char *titlecolor;
const char *logoname;
size_t logosize;
int minsize = MIN_SIZE;
void getDistro(const char *distroname) {
const char *res = display_resolution();
if (!res) minsize--;
else free((void *)res);
const char *wm = display_wm();
if (!wm) minsize--;
else free((void *)wm);
if (logoname == NULL) distroname = logoname;
else {
for (size_t i = 0; i < logosize; i++) {
LOGO[i] = "";
}
for (int i = 0; i < minsize; i++) {
LOGO_SMALL[i] = "";
}
}
if (!isbiglogo && !issmalllogo) {
for (int i = 0; i < LOGO_SIZE; i++) {
LOGO[i] = NULL;
LOGO_SMALL[i] = NULL;
}
}
if (strncmp((char *)logoname, "omnios", strlen("omnios")) == 0) {
if (!customcolor) color = YELLOW;
else color = customcolor;
if (!customtitlecolor) titlecolor = GREY;
else titlecolor = customtitlecolor;
logosize = 13;
if (!isbiglogo) {
LOGO[0] = GREY " ###### " RESET;
LOGO[1] = GREY " ### ### " RESET;
LOGO[2] = GREY " ## ## " RESET;
LOGO[3] = GREY "## ## " RESET;
LOGO[4] = GREY "## " YELLOW "###### " RESET;
LOGO[5] = GREY " ## " YELLOW "### " GREY "## " YELLOW "### " RESET;
LOGO[6] = GREY " ### " YELLOW "## " GREY "### " YELLOW "## " RESET;
LOGO[7] = GREY " " YELLOW "##" GREY "#### " YELLOW "## " RESET;
LOGO[8] = YELLOW " ## ## " RESET;
LOGO[9] = YELLOW " ## ## " RESET;
LOGO[10] = YELLOW " ### ### " RESET;
LOGO[11] = YELLOW " ###### " RESET;
for (size_t i = 12; i < logosize; i++) {
LOGO[i] = YELLOW " " RESET;
}
} else {
logosize = biglogoi;
if (biglogoi < (size_t)minsize) {
for (size_t i = biglogoi; i < (size_t)minsize; i++) {
LOGO[i] = WHITE " " RESET;
}
}
}
if (!issmalllogo) {
LOGO_SMALL[0] = GREY " __ " RESET;
LOGO_SMALL[1] = GREY " / \\ " RESET;
LOGO_SMALL[2] = GREY "| " YELLOW "__ " RESET;
LOGO_SMALL[3] = GREY " \\_" YELLOW "/" GREY "/ " YELLOW "\\ " RESET;
LOGO_SMALL[4] = YELLOW " | | " RESET;
LOGO_SMALL[5] = YELLOW " \\__/ " RESET;
for (int i = 6; i < minsize; i++) {
LOGO_SMALL[i] = YELLOW " " RESET;
}
} else {
if (smalllogoi < (size_t)minsize) {
for (size_t i = smalllogoi; i < (size_t)minsize; i++) {
LOGO_SMALL[i] = WHITE " " RESET;
}
}
}
} else {
if (!customcolor) color = BLUE;
else color = customcolor;
if (!customtitlecolor) titlecolor = BLUE;
else titlecolor = customtitlecolor;
logosize = 17;
if (!isbiglogo) {
LOGO[0] = WHITE " .sy/ " RESET;
LOGO[1] = WHITE " .yh+ " RESET;
LOGO[2] = WHITE " " RESET;
LOGO[3] = BLUE " " BLUE "-+syyyo+-" WHITE " /+. " RESET;
LOGO[4] = BLUE " " BLUE "+ddo/---/sdh/" WHITE " ym- " RESET;
LOGO[5] = BLUE " " BLUE "`hm+ `sms" WHITE " ym-```````.-. " RESET;
LOGO[6] = BLUE " " BLUE "sm+ sm/" WHITE " ym- +s " RESET;
LOGO[7] = BLUE " " BLUE "hm. /mo" WHITE " ym- /h " RESET;
LOGO[8] = BLUE " " BLUE "omo ym:" WHITE " ym- `os` " RESET;
LOGO[9] = BLUE " " BLUE "smo` .ym+" WHITE " ym- .os- " RESET;
LOGO[10] = WHITE " `` " BLUE ":ymy+///oyms-" WHITE " ym- .+s+. " RESET;
LOGO[11] = WHITE " ..` " BLUE "`:+oo+/-`" WHITE " -//oyo- " RESET;
LOGO[12] = WHITE " -:` .:oys/. " RESET;
LOGO[13] = WHITE "+- `./oyys/. " RESET;
LOGO[14] = WHITE "h+` `.-:+oyyyo/-` " RESET;
LOGO[15] = WHITE "`/ossssysso+/-.` " RESET;
LOGO[16] = WHITE " " RESET;
} else {
logosize = biglogoi;
if (biglogoi < (size_t)minsize) {
for (size_t i = biglogoi; i < (size_t)minsize; i++) {
LOGO[i] = WHITE " " RESET;
}
}
}
}
}
#endif

19
src/logo/sunos.h Normal file
View File

@@ -0,0 +1,19 @@
#if defined(__sun)
#ifndef LOGO_SUNOS_H
#define LOGO_SUNOS_H
#include <stdio.h>
#include "../distro.h"
#include "colors.h"
extern char *LOGO[23];
extern char *LOGO_SMALL[23];
extern const char *color;
extern const char *titlecolor;
extern const char *logoname;
extern size_t logosize;
void getDistro(const char *distroname);
#endif
#endif

89
src/memory.c Normal file
View File

@@ -0,0 +1,89 @@
#include "memory.h"
#include "common.h"
#include <stdio.h>
#if defined(__OpenBSD__)
#include <sys/types.h>
#include <sys/sysctl.h>
void display_memory() {
int mib[2];
long long memtotal;
size_t len = sizeof(memtotal);
mib[0] = CTL_HW;
mib[1] = HW_PHYSMEM64;
if (sysctl(mib, 2, &memtotal, &len, NULL, 0) != 0) {
perror("sysctl");
return;
}
struct uvmexp uvm;
mib[0] = CTL_VM;
mib[1] = VM_UVMEXP;
len = sizeof(uvm);
if (sysctl(mib, 2, &uvm, &len, NULL, 0) != 0) {
perror("sysctl");
return;
}
#define pgtok(a) ((a) * ((unsigned int)uvm.pagesize >> 10))
unsigned int memused = pgtok(uvm.active + uvm.swpginuse) / 1024;
printf("%u MiB / %lld MiB", memused, memtotal / 1024LL / 1024LL);
}
#else
void display_memory() {
long long int memused = 0;
long long int memtotal = 0;
#if defined(__FreeBSD__) || defined(__DragonFly__)
// 13M Active, 200M Inact, 184M Laundry,
long long int used1 = run_command_lld("top | grep \"Mem:\" | awk '{print $2}' | "
"sed 's/M//'");
long long int used2 = run_command_lld("top | grep \"Mem:\" | awk '{print $4}' | "
"sed 's/M//'");
long long int used3 = run_command_lld("top | grep \"Mem:\" | awk '{print $6}' | "
"sed 's/M//'");
long long int used4 = run_command_lld("top | grep \"ARC:\" | awk '{print $6}' | "
"sed 's/M//'");
memused = used1 + used2 + used3 + used4;
memtotal = run_command_lld("sysctl -n hw.physmem") / 1024LL / 1024LL;
#elif defined(__NetBSD__)
memused = run_command_lld("top | grep \"Memory:\" | awk '{print $2}' | "
"sed 's/M//'");
memtotal = run_command_lld("sysctl -n hw.physmem64") / 1024LL / 1024LL;
#elif defined(__sun)
// Memory: 3993M phys mem, 504M free mem,
memused = run_command_lld("top | grep \"Memory:\" | awk '{print $5}' | "
"sed 's/M//'");
memtotal = run_command_lld("top | grep \"Memory:\" | awk '{print $2}' | "
"sed 's/M//'");
/* memtotal = run_command_lld("sysctl -n hw.physmem64") / 1024LL / 1024LL; */
#elif defined(__minix)
memtotal = run_command_lld("sysctl -n hw.physmem") / 1024LL / 1024LL;
#elif defined(__linux__)
long long int memaval = run_command_lld("cat /proc/meminfo | grep MemAvailable | "
"awk '{print $2}'") / 1024LL;
memtotal = run_command_lld("cat /proc/meminfo | grep MemTotal | "
"awk '{print $2}'") / 1024LL;
memused = memtotal - memaval;
/* memused = run_command_lld("cat /proc/meminfo | grep MemFree | "
"awk '{print $2}'") / 1024LL; */
#elif defined(__APPLE__)
memtotal = run_command_lld("sysctl -n hw.memsize") / 1024LL / 1024LL;
long long int memwired = run_command_lld("vm_stat | awk '/ wired/ { print $4 }'");
long long int memactive = run_command_lld("vm_stat | awk '/ active/ { printf $3 }'");
long long int memcompressed = run_command_lld("vm_stat | "
"awk '/ occupied/ { printf $5 }'");
memused = (memwired + memactive + memcompressed) * 4LL / 1024LL;
#elif defined(__HAIKU__)
memtotal = run_command_lld("vmstat | awk '/max memory:/ {max=$3} END {print max/1024/1024}'");
long long int memfree = run_command_lld("vmstat | awk '/free memory:/ {free=$3} END {print free/1024/1024}'");
memused = memtotal - memfree;
#endif
printf("%lld MiB / %lld MiB", memused, memtotal);
}
#endif

6
src/memory.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef MEMORY_H
#define MEMORY_H
void display_memory();
#endif

74
src/os.c Normal file
View File

@@ -0,0 +1,74 @@
#include "os.h"
#include "common.h"
#include <stdio.h>
#include <stdlib.h>
const char *display_os() {
const char *osname = NULL;
const char *osversion = NULL;
const char *osarch = NULL;
char *cmd;
#if defined(__APPLE__)
if (!from_cache("/tmp/farfetch/os")) {
osname = run_command_s("sw_vers | grep \"ProductName\" | awk '{print $2}'");
osversion = run_command_s("sw_vers | grep \"ProductVersion\" | awk '{print $2}'");
osarch = run_command_s("uname -m");
cmd = (char *)malloc(128 * sizeof(char));
if (!cmd) {
perror("malloc");
free((void *)osname);
free((void *)osversion);
free((void *)osarch);
return NULL;
}
snprintf(cmd, 128, "%s %s %s", osname, osversion, osarch);
to_cache("/tmp/farfetch/os", cmd);
} else {
cmd = (char *)from_cache("/tmp/farfetch/os");
}
#elif defined(__HAIKU__)
osname = run_command_s("uname -s");
osversion = run_command_s("uname -r");
osarch = run_command_s("uname -m");
cmd = (char *)malloc(128 * sizeof(char));
if (!cmd) {
perror("malloc");
free((void *)osname);
free((void *)osversion);
free((void *)osarch);
return NULL;
}
snprintf(cmd, 128, "%s %s %s", osname, osversion, osarch);
#else
if (!from_cache("/tmp/farfetch/os")) {
osname = run_command_s("uname -s");
osversion = run_command_s("uname -r");
osarch = run_command_s("uname -m");
cmd = (char *)malloc(128 * sizeof(char));
if (!cmd) {
perror("malloc");
free((void *)osname);
free((void *)osversion);
free((void *)osarch);
return NULL;
}
snprintf(cmd, 128, "%s %s %s", osname, osversion, osarch);
to_cache("/tmp/farfetch/os", cmd);
} else {
cmd = (char *)from_cache("/tmp/farfetch/os");
}
#endif
free((void *)osname);
free((void *)osversion);
free((void *)osarch);
return cmd;
}

6
src/os.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef OS_H
#define OS_H
const char *display_os();
#endif

49
src/packages.c Normal file
View File

@@ -0,0 +1,49 @@
#include "packages.h"
#include "common.h"
#if defined(__linux__)
#include "distro.h"
#elif defined(__sun)
#include <stdio.h>
#endif
#include <unistd.h>
const char *display_packages() {
#if defined(__OpenBSD__) || defined(__NetBSD__)
return run_command_s("pkg_info -a | wc -l | sed \"s/ //g\" && "
"echo \" (pkg_info)\"");
#elif defined(__FreeBSD__) || defined(__DragonFly__)
return run_command_s("pkg info -a | wc -l | sed \"s/ //g\" && "
"echo \" (pkg info)\"");
#elif defined(__sun)
return run_command_s("pkg list | wc -l | sed 's/ *//' && echo \" (pkg list)\"");
#elif defined(__linux__)
if (access("/bin/xbps-query", F_OK) != -1) {
return run_command_s("xbps-query -l | wc -l | sed \"s/ //g\" && "
"echo \" (xbps-query)\"");
} else if (access("/usr/bin/dpkg-query", F_OK) != -1) {
return run_command_s("dpkg-query -f '.\n' -W | wc -l | sed \"s/ //g\" && "
"echo \" (dpkg-query)\"");
} else if (access("/usr/bin/pacman", F_OK) != -1) {
return run_command_s("pacman -Qq | wc -l | sed \"s/ //g\" && "
"echo \" (pacman)\"");
} else if (access("/usr/bin/rpm", F_OK) != -1) {
return run_command_s("rpm -qa | wc -l | sed \"s/ //g\" && "
"echo \" (rpm)\"");
}
return NULL;
#elif defined(__APPLE__)
const char *command = "";
// TODO: macportとpkgin対応
if (access("/usr/local/bin/brew", F_OK) != -1) {
command = "ls -l /usr/local/Cellar | wc -l | sed \"s/ //g\" && echo \" (brew)\"";
}
return run_command_s(command);
#elif defined(__HAIKU__)
return run_command_s("find /boot/system/packages -type f -name \"*.hpkg\" | "
"wc -l && echo \" (pkgman)\"");
#endif
return NULL;
}

6
src/packages.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef PACKAGES_H
#define PACKAGES_H
const char *display_packages();
#endif

12
src/recording.c Normal file
View File

@@ -0,0 +1,12 @@
#if defined(__OpenBSD__)
#include "recording.h"
#include "common.h"
const char *display_recording_audio() {
return run_command_s("sysctl -n kern.audio.record");
}
const char *display_recording_video() {
return run_command_s("sysctl -n kern.video.record");
}
#endif

9
src/recording.h Normal file
View File

@@ -0,0 +1,9 @@
#if defined(__OpenBSD__)
#ifndef RECORDING_H
#define RECORDING_H
const char *display_recording_audio();
const char *display_recording_video();
#endif
#endif

96
src/resolution.c Normal file
View File

@@ -0,0 +1,96 @@
#include "resolution.h"
#include "common.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
const char *usingxrandr() {
return run_command_s("xrandr --nograb --current | "
"awk -F 'connected |\\\\+|\\\\(' '/ "
"connected.*[0-9]+x[0-9]+\\+/ && $2 {printf $2 "
"\", \"}' | sed 's/primary //' | "
"sed 's/,\\([^,]*\\)$/\\1/'");
}
const char *usingxwininfo() {
return run_command_s("xwininfo -root | awk '/Width/ {width=$2} /Height/ "
"{height=$2} END {printf \"%dx%d\\n\", width, height}'");
}
const char *usingxdpyinfo() {
return run_command_s("xdpyinfo | awk '/dimensions:/ {printf $2}'");
}
const char *usingdrm() {
return run_command_s("for dev in /sys/class/drm/card*-*/status; do "
"if grep -q \"connected\" \"$dev\"; then "
"dir=$(dirname \"$dev\"); "
"modefile=\"$dir/modes\"; "
"dis=$(echo \"$dir\" | sed -e 's/^.*drm\\///'); "
"if [ -f \"$modefile\" ]; then "
"mode=$(head -n 1 \"$modefile\"); "
"if [ -n \"$mode\" ]; then "
"echo \"$mode, \"; "
"fi "
"fi "
"fi "
"done | sed '$s/,//'");
}
const char *display_resolution() {
#if defined(__HAIKU__)
return run_command_s("screenmode | sed 's/Resolution: //' | sed 's/,.*$//' | "
"sed 's/ /x/'");
#elif defined(__APPLE__)
return run_command_s("system_profiler SPDisplaysDataType | grep Resolution | "
"sed 's/^.*: //' | sed 's/ Retina//' | sed 's/ //g'");
#else
if (access("/sys/class/drm", F_OK) == 0) {
return usingdrm();
}
const char *display = run_command_s("echo $DISPLAY");
if (display == NULL || strlen(display) == 0) return NULL;
else free((void *)display);
const char *isxrandr = run_command_s("which xrandr");
if (
isxrandr != NULL &&
strlen(isxrandr) != 0 &&
strncmp(isxrandr, "xrandr not found", strlen("xrandr not found")) != 0 &&
!strstr(isxrandr, "which: no xrandr in")
) {
free((void *)isxrandr);
return usingxrandr();
}
free((void *)isxrandr);
const char *isxwininfo = run_command_s("which xwininfo");
if (
isxwininfo != NULL &&
strlen(isxwininfo) != 0 &&
strncmp(isxwininfo, "xwininfo not found", strlen("xwininfo not found")) != 0 &&
!strstr(isxwininfo, "which: no xwininfo in")
) {
free((void *)isxwininfo);
return usingxwininfo();
}
free((void *)isxwininfo);
const char *isxdpyinfo = run_command_s("which xdpyinfo");
if (
isxdpyinfo != NULL &&
strlen(isxdpyinfo) != 0 &&
strncmp(isxdpyinfo, "xdpyinfo not found", strlen("xdpyinfo not found")) != 0 &&
!strstr(isxdpyinfo, "which: no xdpyinfo in")
) {
free((void *)isxdpyinfo);
return usingxdpyinfo();
}
free((void *)isxdpyinfo);
return NULL;
#endif
}

6
src/resolution.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef RESOLUTION_H
#define RESOLUTION_H
const char *display_resolution();
#endif

42
src/shell.c Normal file
View File

@@ -0,0 +1,42 @@
#include "shell.h"
#include "common.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
const char *display_shell() {
char *shell = (char *)malloc(64 * sizeof(char));
if (shell == NULL) {
return NULL;
}
const char *ver = NULL;
const char *name = run_command_s("echo ${SHELL##*/}");
if (strncmp(name, "bash", strlen("bash")) == 0) {
ver = run_command_s("echo $BASH_VERSION");
} else if (strncmp(name, "ksh", strlen("ksh")) == 0) {
ver = run_command_s("echo $KSH_VERSION | sed 's/^.*v//' | sed 's/ .*$//'");
} else if (strncmp(name, "zsh", strlen("zsh")) == 0) {
ver = run_command_s("zsh --version | sed 's/ (.*$//' | sed 's/zsh //'");
} else if (strncmp(name, "yash", strlen("yash")) == 0) {
ver = run_command_s("LC_ALL=C yash --version | head -1 | "
"sed 's/Yet another shell, version //'");
} else if (strncmp(name, "tsch", strlen("tsch")) == 0) {
ver = run_command_s("tcsh --version | sed 's/tcsh //' | sed 's/ .*$//'");
} else {
ver = NULL;
}
if (ver != NULL) {
snprintf(shell, 64, "%s %s", name, ver);
} else {
snprintf(shell, 64, "%s", name);
}
free((void *)name);
if (ver != NULL) free((void *)ver);
return shell;
}

6
src/shell.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef SHELL_H
#define SHELL_H
const char *display_shell();
#endif

92
src/storage.c Normal file
View File

@@ -0,0 +1,92 @@
#include "storage.h"
#include "common.h"
#if defined(__HAIKU__)
#include <stdio.h>
#endif
#include <string.h>
#include <stdlib.h>
const char *display_storage() {
const char *excode = run_command_s("zpool list 2>/dev/null || echo $?");
if (excode != NULL && (strncmp(excode, "127", strlen("127")) == 0)) {
free((void *)excode);
#if defined(__HAIKU__)
long long int usedstore = 0;
long long int totalstore = run_command_lld("df -h | "
"awk '/^\\/boot / {printf \"%s\", $3}'");
long long int freestore = run_command_lld("df -h | "
"awk '/^\\/boot / {printf \"%s\", $5}'");
const char *totunit = run_command_s("df -h | "
"awk '/^\\/boot / {printf \"%s\", $4}'");
const char *freunit = run_command_s("df -h | "
"awk '/^\\/boot / {printf \"%s\", $6}'");
char tu[2] = {'\0'};
char uu[2] = {'\0'};
if (strncmp(totunit, "TiB", 3) == 0) tu[0] = 'T';
else if (strncmp(totunit, "GiB", 3) == 0) tu[0] = 'G';
else if (strncmp(totunit, "MiB", 3) == 0) tu[0] = 'M';
else if (strncmp(totunit, "KiB", 3) == 0) tu[0] = 'K';
else tu[0] = 'B';
tu[1] = '\0';
if (strncmp(freunit, "TiB", 3) == 0) uu[0] = 'T';
else if (strncmp(freunit, "GiB", 3) == 0) uu[0] = 'G';
else if (strncmp(freunit, "MiB", 3) == 0) uu[0] = 'M';
else if (strncmp(freunit, "KiB", 3) == 0) uu[0] = 'K';
else uu[0] = 'B';
uu[1] = '\0';
if (strncmp(totunit, freunit, 3) != 0) {
if (strncmp(totunit, "TiB", 3) == 0 && strncmp(freunit, "GiB", 3) == 0)
usedstore = (totalstore - (freestore / 1024));
else if (strncmp(totunit, "GiB", 3) == 0 && strncmp(freunit, "MiB", 3) == 0)
usedstore = (totalstore - (freestore / 1024));
else if (strncmp(totunit, "MiB", 3) == 0 && strncmp(freunit, "KiB", 3) == 0)
usedstore = (totalstore - (freestore / 1024));
else if (strncmp(totunit, "KiB", 3) == 0 && strncmp(freunit, "B", 3) == 0)
usedstore = (totalstore - (freestore / 1024));
else if (strncmp(totunit, "TiB", 3) == 0 && strncmp(freunit, "MiB", 3) == 0)
usedstore = (totalstore - (freestore / 1024 / 1024));
else if (strncmp(totunit, "GiB", 3) == 0 && strncmp(freunit, "KiB", 3) == 0)
usedstore = (totalstore - (freestore / 1024 / 1024));
else if (strncmp(totunit, "MiB", 3) == 0 && strncmp(freunit, "B", 3) == 0)
usedstore = (totalstore - (freestore / 1024 / 1024));
else if (strncmp(totunit, "TiB", 3) == 0 && strncmp(freunit, "KiB", 3) == 0)
usedstore = (totalstore - (freestore / 1024 / 1024 / 1024));
else if (strncmp(totunit, "GiB", 3) == 0 && strncmp(freunit, "B", 3) == 0)
usedstore = (totalstore - (freestore / 1024 / 1024 / 1024));
else if (strncmp(totunit, "TiB", 3) == 0 && strncmp(freunit, "B", 3) == 0)
usedstore = (totalstore - (freestore / 1024 / 1024 / 1024 / 1024));
} else {
usedstore = (totalstore - freestore);
}
char *cmd = (char *)malloc(128 * sizeof(char));
if (!cmd) {
return NULL;
}
snprintf(cmd, 128, "/boot: %lld%s / %lld%s", usedstore, uu, totalstore, tu);
return cmd;
#else
return run_command_s("df -h | "
"awk '/^\\/dev\\// {printf \"%s: %s / %s, \", $1, $3, $2}' | "
"awk '{sub(/, $/, \"\"); print}'");
#endif
}
free((void *)excode);
const char *test = run_command_s("zpool list 2>/dev/null || echo $?");
if (strncmp(test, "1", strlen("1")) == 0) {
free((void *)test);
return NULL;
}
free((void *)test);
return run_command_s("zpool list | "
"awk 'NR>1 {printf \"%s: %s / %s, \", $1, $3, $2}' | "
"awk '{sub(/, $/, \"\"); print}'");
}

6
src/storage.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef STORAGE_H
#define STORAGE_H
const char *display_storage();
#endif

41
src/uptime.c Normal file
View File

@@ -0,0 +1,41 @@
#include "uptime.h"
#include "common.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const char *display_days() {
const char *days = run_command_s("uptime | awk '{for (i=1; i<=NF; i++) "
"if ($i ~ /day/) print $(i-1), $i}'");
if (days == NULL || strlen(days) == 0) {
return strndup("0 days,", 7);
}
return days;
}
const char *display_time() {
const char *uptime = run_command_s("uptime");
if (uptime == NULL) {
return NULL;
}
char *days = strstr(uptime, "day");
int nodays = 0;
if (days == NULL) {
nodays = 1;
days = strstr(uptime, "days");
}
free((void *)uptime);
if (nodays) {
return run_command_s("uptime | awk '{print $3}' | sed 's/,//' | "
"sed 's/:/ hours, /' && echo \" mins\"");
}
return run_command_s("uptime | awk '{print $5}' | sed 's/,//' | "
"sed 's/:/ hours, /' && echo \" mins\"");
}

7
src/uptime.h Normal file
View File

@@ -0,0 +1,7 @@
#ifndef UPTIME_H
#define UPTIME_H
const char *display_days();
const char *display_time();
#endif

11
src/user.c Normal file
View File

@@ -0,0 +1,11 @@
#include "user.h"
#include "common.h"
const char *display_user_name() {
return run_command_s("whoami");
}
const char *display_user_host() {
return run_command_s("command -v hostname >/dev/null 2>&1 && hostname || "
"cat /etc/hostname");
}

7
src/user.h Normal file
View File

@@ -0,0 +1,7 @@
#ifndef USER_H
#define USER_H
const char *display_user_name();
const char *display_user_host();
#endif

49
src/wm.c Normal file
View File

@@ -0,0 +1,49 @@
#include "wm.h"
#include "common.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
const char *display_wm() {
#if defined(__APPLE__)
return "Aqua";
#elif defined(__HAIKU__)
return "Stack & Tile";
#else
const char *display = run_command_s("echo $DISPLAY");
if (display == NULL || strlen(display) == 0) return NULL;
else free((void *)display);
const char *xproptest = run_command_s("xprop -root -notype _NET_SUPPORTING_WM_CHECK");
if (
strncmp(
xproptest,
"xprop: error: Invalid window id format: -notype.",
strlen("xprop: error: Invalid window id format: -notype.")
)
) return NULL;
else free((void *)xproptest);
char cmd[512];
const char *id = run_command_s("xprop -root -notype _NET_SUPPORTING_WM_CHECK | "
"awk '{print $5}'");
snprintf(
cmd,
sizeof(cmd),
"%s%s%s",
"xprop -id ",
id,
" -notype -len 100 -f _NET_WM_NAME 8t | awk '{print $3}' | head -1 | "
"sed 's/\"//g'"
);
free((void *)id);
const char *wm = run_command_s(cmd);
return wm;
#endif
return NULL;
}

6
src/wm.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef WM_H
#define WM_H
const char *display_wm();
#endif