Compare commits
3 Commits
5bbe703ec1
...
v1.2
| Author | SHA1 | Date | |
|---|---|---|---|
| 497a800ecb | |||
| 64827aa86d | |||
| f90137b4c0 |
@@ -1,25 +1,28 @@
|
||||
# fetchit
|
||||
|
||||
fetchit is a terminal-based system information viewer written in C++. It works like neofetch/fastfetch and consists of a single file (`main.cpp`).
|
||||
`fetchit` is a Linux terminal system information viewer written in C++. It's a single-file program (`main.cpp`) that prints a colored distro logo (when available) alongside system and hardware info, similar to neofetch/fastfetch.
|
||||
|
||||
## Features
|
||||
|
||||
- Displays distro, kernel, uptime, shell, CPU, GPU, RAM, and OS date information.
|
||||
- Detects distro name via `/etc/os-release`.
|
||||
- Shows ASCII logos for supported distros.
|
||||
- Reads `/usr/share/hwdata/pci.ids` for GPU names; prints hex IDs if missing.
|
||||
- Accounts for Unicode character width (for icon alignment).
|
||||
- Shows: distro, kernel, uptime, shell, CPU, GPU, RAM, and "OS Date".
|
||||
- Distro detection via `/etc/os-release` (`PRETTY_NAME` for display, `ID` for logo matching).
|
||||
- Colored ASCII distro logos for supported distros.
|
||||
- GPU detection by scanning PCI devices (`/sys/bus/pci/devices/`) for class `0x03*`.
|
||||
- GPU name resolution via `/usr/share/hwdata/pci.ids` (falls back to hex IDs if missing).
|
||||
- Accounts for Unicode character width for better alignment in terminals.
|
||||
|
||||
## Supported Distro Logos
|
||||
|
||||
Logos are matched against `/etc/os-release` `ID`:
|
||||
|
||||
`arch`, `cachyos`, `debian`, `ubuntu`, `fedora`, `manjaro`, `opensuse`, `pop`, `linuxmint`, `endeavouros`, `void`, `alpine`
|
||||
|
||||
## Requirements
|
||||
|
||||
- Linux
|
||||
- A C++17-capable compiler (e.g., g++)
|
||||
- A UTF-8 terminal with ANSI color support (for icons and colors)
|
||||
- The following files/paths are read:
|
||||
- A C++17-capable compiler (default: `g++`)
|
||||
- UTF-8 locale + ANSI color support (recommended for icons/colors)
|
||||
- Reads the following files/paths:
|
||||
- `/etc/os-release`
|
||||
- `/etc/hostname`
|
||||
- `/proc/uptime`
|
||||
@@ -31,34 +34,94 @@ fetchit is a terminal-based system information viewer written in C++. It works l
|
||||
|
||||
## Build
|
||||
|
||||
```bash
|
||||
g++ -std=c++17 -O2 -o fetchit main.cpp
|
||||
```
|
||||
|
||||
## Run
|
||||
### Using the Makefile (recommended)
|
||||
|
||||
```bash
|
||||
./fetchit
|
||||
make
|
||||
```
|
||||
|
||||
## Sample Output
|
||||
Binary output: `build/fetchit`
|
||||
|
||||
```text
|
||||
--- murat@baklava ---
|
||||
Run:
|
||||
|
||||
/\ distro: Arch Linux
|
||||
/ \ kernel: 7.0.10-arch1-1
|
||||
/ \ uptime: 1 minutes
|
||||
/ \ shell: /usr/bin/bash
|
||||
/ ,, \ CPU: 12th Gen Intel(R) Core(TM) i5-12500H (16) @ 4.5 GHz
|
||||
/ | | \ GPU: AD107M [GeForce RTX 4060 Max-Q / Mobile] / Alder Lake-P GT2 [Iris Xe Graphics]
|
||||
/_-'' ''-_\ RAM: 15.2529 GB
|
||||
OS Date: 6 months 17 days 3 hours 40 minutes
|
||||
```bash
|
||||
make run
|
||||
```
|
||||
|
||||
### Manual build
|
||||
|
||||
```bash
|
||||
g++ -O2 -Wall -Wextra -std=c++17 -pipe -o fetchit main.cpp
|
||||
```
|
||||
|
||||
## Install / Uninstall
|
||||
|
||||
Install:
|
||||
|
||||
```bash
|
||||
sudo make install
|
||||
```
|
||||
|
||||
Defaults:
|
||||
|
||||
- `PREFIX=/usr/local`
|
||||
- `BINDIR=$(PREFIX)/bin`
|
||||
- Installs to: `/usr/local/bin/fetchit`
|
||||
|
||||
Uninstall:
|
||||
|
||||
```bash
|
||||
sudo make uninstall
|
||||
```
|
||||
|
||||
Packaging-friendly variables:
|
||||
|
||||
- `DESTDIR` (staging root)
|
||||
- `PREFIX`, `BINDIR`
|
||||
|
||||
Example:
|
||||
|
||||
```bash
|
||||
make install PREFIX=/usr BINDIR=/usr/bin DESTDIR=/tmp/pkgroot
|
||||
```
|
||||
|
||||
## Distribution Archive
|
||||
|
||||
Create a tar.gz containing the built binary:
|
||||
|
||||
```bash
|
||||
make dist
|
||||
```
|
||||
|
||||
Output: `dist/fetchit-<version>-linux-x86_64-gnu.tar.gz`
|
||||
|
||||
`<version>` is derived from:
|
||||
`git describe --tags --dirty --always` (when available)
|
||||
|
||||
Full release pipeline:
|
||||
|
||||
```bash
|
||||
make release
|
||||
```
|
||||
|
||||
## Notes
|
||||
|
||||
- `OS Date` is based on the creation time of `/etc/hostname`.
|
||||
- If no ASCII logo is found, only the info list is printed.
|
||||
- The distro logo is displayed in color via ANSI escape codes.
|
||||
- This tool targets Linux systems and is not expected to work on non-Linux OSes.
|
||||
- `shell` is taken from `$SHELL` and printed as the basename (e.g. `bash`, not `/usr/bin/bash`).
|
||||
- `OS Date` is computed from `/etc/hostname` file metadata (`ctime`) as an elapsed duration; it may not equal the OS install date.
|
||||
- If `pci.ids` is unavailable, GPU(s) are printed as hex IDs like `0xVVVV:0xDDDD`.
|
||||
- If no distro logo matches, the logo section will be empty and only info lines are shown.
|
||||
|
||||
## Sample Output
|
||||
|
||||
```text
|
||||
--- user@host ---
|
||||
|
||||
/\ distro: Arch Linux
|
||||
/ \ kernel: 7.0.10-arch1-1
|
||||
/ \ uptime: 12 minutes
|
||||
/ \ shell: bash
|
||||
/ ,, \ CPU: ... (N) @ X.XX GHz
|
||||
/ | | \ GPU: ...
|
||||
/_-'' ''-_\ RAM: 15.25 GB
|
||||
OS Date: 6 months 17 days 3 hours 40 minutes
|
||||
```
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include <array>
|
||||
#include <string>
|
||||
#include <sstream>
|
||||
#include <iomanip>
|
||||
#include <unordered_map>
|
||||
#include <cctype>
|
||||
#include <sys/utsname.h>
|
||||
@@ -14,13 +15,13 @@
|
||||
#include <clocale>
|
||||
#include <cwchar>
|
||||
|
||||
using std::string, std::cout;
|
||||
using std::string, std::cout, std::vector;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
string getUser();
|
||||
string getHost();
|
||||
string getDistro();
|
||||
std::vector<string> distroArt();
|
||||
vector<string> distroArt();
|
||||
string getKernel();
|
||||
string getUptime();
|
||||
string getShell();
|
||||
@@ -67,8 +68,8 @@ struct gpuId {
|
||||
string device;
|
||||
};
|
||||
|
||||
std::vector<gpuId> getGpuIds() {
|
||||
std::vector<gpuId> gpus;
|
||||
vector<gpuId> getGpuIds() {
|
||||
vector<gpuId> gpus;
|
||||
std::string pciPath = "/sys/bus/pci/devices/";
|
||||
|
||||
for (const auto& entry : fs::directory_iterator(pciPath)) {
|
||||
@@ -122,7 +123,7 @@ int main () {
|
||||
return color(c) + padded + color(Color::Reset) + value;
|
||||
};
|
||||
|
||||
std::vector<string> infoLines = {
|
||||
vector<string> infoLines = {
|
||||
formatLine(Color::Green, " distro:", getDistro()),
|
||||
formatLine(Color::Magenta, " kernel:", getKernel()),
|
||||
formatLine(Color::Blue, " uptime:", getUptime()),
|
||||
@@ -133,7 +134,7 @@ int main () {
|
||||
formatLine(Color::Blue, " OS Date:", getOsDate())
|
||||
};
|
||||
|
||||
std::vector<string> logoLines = distroArt();
|
||||
vector<string> logoLines = distroArt();
|
||||
size_t logoWidth = 0;
|
||||
for (const auto& line : logoLines) {
|
||||
if (line.size() > logoWidth) logoWidth = line.size();
|
||||
@@ -262,7 +263,7 @@ string color(Color c) {
|
||||
return "\033[0m";
|
||||
}
|
||||
|
||||
std::vector<string> distroArt() {
|
||||
vector<string> distroArt() {
|
||||
std::ifstream readOsRelease("/etc/os-release");
|
||||
|
||||
if(!readOsRelease.is_open()) {
|
||||
@@ -287,7 +288,7 @@ std::vector<string> distroArt() {
|
||||
|
||||
readOsRelease.close();
|
||||
|
||||
const std::vector<DistroLogo> logos = {
|
||||
const vector<DistroLogo> logos = {
|
||||
{
|
||||
"arch",
|
||||
Color::Blue,
|
||||
@@ -451,7 +452,7 @@ std::vector<string> distroArt() {
|
||||
},
|
||||
};
|
||||
|
||||
std::vector<string> out;
|
||||
vector<string> out;
|
||||
for (const auto& logo : logos) {
|
||||
if (logo.id == distroID) {
|
||||
const string prefix = color(logo.color);
|
||||
@@ -508,6 +509,9 @@ string getUptime() {
|
||||
string getShell() {
|
||||
string shell;
|
||||
shell = std::getenv("SHELL");
|
||||
|
||||
while(shell.find('/') < shell.length()) shell.erase(0, shell.find('/') + 1);
|
||||
|
||||
if (!shell.empty()) return shell;
|
||||
|
||||
return "";
|
||||
@@ -581,7 +585,7 @@ string getGPU() {
|
||||
return hex;
|
||||
};
|
||||
|
||||
auto joinWith = [](const std::vector<string>& items, const string& sep) {
|
||||
auto joinWith = [](const vector<string>& items, const string& sep) {
|
||||
string out;
|
||||
for (const auto& item : items) {
|
||||
if (item.empty()) continue;
|
||||
@@ -595,7 +599,7 @@ string getGPU() {
|
||||
|
||||
if(!readPciIds.is_open()) {
|
||||
std::cerr << "Error: Couldn't read /usr/share/hwdata/pci.ids\n";
|
||||
std::vector<string> ids;
|
||||
vector<string> ids;
|
||||
for (const auto& gpu : gpus) {
|
||||
string vendor = normalizeHex(gpu.vendor);
|
||||
string device = normalizeHex(gpu.device);
|
||||
@@ -643,7 +647,7 @@ string getGPU() {
|
||||
|
||||
readPciIds.close();
|
||||
|
||||
std::vector<string> gpuNames;
|
||||
vector<string> gpuNames;
|
||||
for (const auto& gpu : gpus) {
|
||||
string vendor = normalizeHex(gpu.vendor);
|
||||
string device = normalizeHex(gpu.device);
|
||||
@@ -700,7 +704,7 @@ string getRAM() {
|
||||
memkbs /= 1024;
|
||||
float memory = memkbs / 1024.0f;
|
||||
std::stringstream ss;
|
||||
ss << memory << " GB";
|
||||
ss << std::fixed << std::setprecision(2) << memory << " GB";
|
||||
string memGigs = ss.str();
|
||||
|
||||
if (!memGigs.empty()) return memGigs;
|
||||
|
||||
Reference in New Issue
Block a user