Code Monkey home page Code Monkey logo

nitch's Introduction

NiTch

incredibly fast system fetch written in nim๐Ÿ‘‘


Maintenance License Commits

GitHub Repo stars GitHub issues GitHub pull requests

GitHub release (latest by date)

Description ๐Ÿ“–

nitch is a small and incredibly fast system fetch written fully in nim๐Ÿ‘‘ without any dependencies, on my pc it executes in around 1.70 miliseconds.

The source code of nitch is highly documented and I hope it will act as a learning resource for nim and linux systems architecture

If anything in the source code is unclear or is lacking in its explanation, open an issue. Sometimes you get too close to something and you fail to see the "bigger picture"!

btw written in nim๐Ÿ‘‘

why nim๐Ÿ‘‘? because it's fast and simple


Installation โ˜๏ธ

wget https://raw.githubusercontent.com/unxsh/nitch/main/setup.sh && sh setup.sh

Usage ๐Ÿชจ

nitch

flags:

 -f --fetch   | return fetch about system
 -h --help    | return help message
 -v --version | return version of program

Configuration โš™๏ธ

nitch is configured by changing the source code

src/funcs/drawing.nim - config file

import std/terminal       # import standard terminal lib
import getDistroId        # import to get distro id through /etc/os-release
#import ../assets/logos   # uncomment if you use your own logo
import ../nitches/[getUser, getHostname,
                   getDistro, getKernel,
                   getUptime, getShell,
                   getPkgs, getRam,
                   getLogo, getLogoColor]  # import nitches to get info about user system

# the main function for drawing fetch
proc drawInfo*() =
  let  # distro id (arch, manjaro, debian)
    distroId: string = getDistroId()

  let  # logo and it color
    logoColor: ForegroundColor = getLogoColor(distroId)  # color for logo
    defaultLogo: string  = getLogo(distroId)             # default logo from nitch/src/assets/logos

  const  # icons before cotegores
    userIcon: string   = "๏€‡ "  # recomended: "๏€‡ " or "|>"
    hnameIcon: string  = "๎œ” "  # recomended: "๎œ” " or "|>"
    distroIcon: string = "๓ฐป€ "  # recomended: "๓ฐป€ " or "|>"
    kernelIcon: string = "๓ฐŒข "  # recomended: "๓ฐŒข " or "|>"
    uptimeIcon: string = "๏€— "  # recomended: "๏€— " or "|>"
    shellIcon: string  = "๏’‰ "  # recomended: "๏’‰ " or "|>"
    pkgsIcon: string   = "๓ฐ– "  # recomended: "๓ฐ– " or "|>"
    ramIcon: string    = "๓ฐ› "  # recomended: "๓ฐ› " or "|>"
    colorsIcon: string = "๓ฐ˜ "  # recomended: "๓ฐ˜ " or "->"
    # please insert any char after the icon
    # to avoid the bug with cropping the edge of the icon

    dotIcon: string = "๏‘„"  # recomended: "๏‘„" or "โ– "
    # icon for demonstrate colors

  const  # categories
    userCat: string   = " user   โ”‚ "  # recomended: " user   โ”‚ "
    hnameCat: string  = " hname  โ”‚ "  # recomended: " hname  โ”‚ "
    distroCat: string = " distro โ”‚ "  # recomended: " distro โ”‚ "
    kernelCat: string = " kernel โ”‚ "  # recomended: " kernel โ”‚ "-
    uptimeCat: string = " uptime โ”‚ "  # recomended: " uptime โ”‚ "
    shellCat: string  = " shell  โ”‚ "  # recomended: " shell  โ”‚ "
    pkgsCat: string   = " pkgs   โ”‚ "  # recomended: " pkgs   โ”‚ "
    ramCat: string    = " memory โ”‚ "  # recomended: " memory โ”‚ "
    colorsCat: string = " colors โ”‚ "  # recomended: " colors โ”‚ "

  let  # all info about system
    userInfo: string     = getUser()          # get user through $USER env variable
    hostnameInfo: string = getHostname()      # get Hostname hostname through /etc/hostname
    distroInfo: string   = getDistro()        # get distro through /etc/os-release
    kernelInfo: string   = getKernel()        # get kernel through /proc/version
    uptimeInfo: string   = getUptime()        # get Uptime through /proc/uptime file
    shellInfo: string    = getShell()         # get shell through $SHELL env variable
    pkgsInfo: string     = getPkgs(distroId)  # get amount of packages in distro
    ramInfo: string      = getRam()           # get ram through /proc/meminfo

  const  # aliases for colors
    color1: ForegroundColor = fgRed
    color2: ForegroundColor = fgYellow
    color3: ForegroundColor = fgGreen
    color4: ForegroundColor = fgCyan
    color5: ForegroundColor = fgBlue
    color6: ForegroundColor = fgMagenta
    color7: ForegroundColor = fgWhite
    color8: ForegroundColor = fgBlack
    color0: ForegroundColor = fgDefault

  # colored out
  stdout.styledWrite(styleBright, logoColor, defaultLogo)
  stdout.styledWrite(styleBright, "  โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ\n")
  stdout.styledWrite(styleBright, "  โ”‚ ", color1, userIcon, color0, userCat, color1, userInfo, "\n")
  stdout.styledWrite(styleBright, "  โ”‚ ", color2, hnameIcon, color0, hnameCat, color2, hostnameInfo, "\n")
  stdout.styledWrite(styleBright, "  โ”‚ ", color3, distroIcon, color0, distroCat, color3, distroInfo, "\n")
  stdout.styledWrite(styleBright, "  โ”‚ ", color4, kernelIcon, color0, kernelCat, color4, kernelInfo, "\n")
  stdout.styledWrite(styleBright, "  โ”‚ ", color5, uptimeIcon, color0, uptimeCat, color5, uptimeInfo, "\n")
  stdout.styledWrite(styleBright, "  โ”‚ ", color6, shellIcon, color0, shellCat, color6, shellInfo, "\n")
  stdout.styledWrite(styleBright, "  โ”‚ ", color1, pkgsIcon, color0, pkgsCat, color1, pkgsInfo, "\n")
  stdout.styledWrite(styleBright, "  โ”‚ ", color2, ramIcon, color0, ramCat, fgYellow, ramInfo, "\n")
  stdout.styledWrite(styleBright, "  โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค\n")
  stdout.styledWrite(styleBright, "  โ”‚ ", color7, colorsIcon, color0, colorsCat, color7, dotIcon, " ", color1, dotIcon, " ", color2, dotIcon, " ", color3, dotIcon, " ", color4, dotIcon, " ", color5, dotIcon, " ", color6, dotIcon, " ", color8, dotIcon, "\n")
  stdout.styledWrite(styleBright, "  โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ\n\n")

Building ๐Ÿ“ฆ

0) install nim

1) clone repo

git clone https://github.com/unxsh/nitch.git

2) change dir to nitch

cd nitch/

3) build program with nimble

nimble build

After that you will get a ready-made binary file in the root directory of the project.


File architecture ๐Ÿ“

nitch
  โ”œโ”€โ”€ LICENSE
  โ”œโ”€โ”€ nitch
  โ”œโ”€โ”€ nitch.nimble
  โ”œโ”€โ”€ README.md
  โ”œโ”€โ”€ src
  โ”‚   โ”œโ”€โ”€ assets
  โ”‚   โ”‚   โ”œโ”€โ”€ assets.nim
  โ”‚   โ”‚   โ””โ”€โ”€ logos.nim
  โ”‚   โ”œโ”€โ”€ flags
  โ”‚   โ”‚   โ””โ”€โ”€ argParser.nim
  โ”‚   โ”œโ”€โ”€ funcs
  โ”‚   โ”‚   โ”œโ”€โ”€ drawing.nim
  โ”‚   โ”‚   โ”œโ”€โ”€ packages
  โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ getPacmanPkgs.nim
  โ”‚   โ”‚   โ””โ”€โ”€ perform.nim
  โ”‚   โ”œโ”€โ”€ nitches
  โ”‚   โ”‚   โ”œโ”€โ”€ getDistro.nim
  โ”‚   โ”‚   โ”œโ”€โ”€ getHostname.nim
  โ”‚   โ”‚   โ”œโ”€โ”€ getKernel.nim
  โ”‚   โ”‚   โ”œโ”€โ”€ getPkgs.nim
  โ”‚   โ”‚   โ”œโ”€โ”€ getRam.nim
  โ”‚   โ”‚   โ”œโ”€โ”€ getShell.nim
  โ”‚   โ”‚   โ”œโ”€โ”€ getUptime.nim
  โ”‚   โ”‚   โ””โ”€โ”€ getUser.nim
  โ”‚   โ”œโ”€โ”€ nitch.nim
  โ”‚   โ””โ”€โ”€ nitch.nim.cfg
  โ””โ”€โ”€ templates
      โ”œโ”€โ”€ cfgParser
      โ”œโ”€โ”€ cfgParser.nim
      โ”œโ”€โ”€ data.dat
      โ”œโ”€โ”€ listFiles.nim
      โ”œโ”€โ”€ readLine.nim
      โ”œโ”€โ”€ refTest.nim
      โ”œโ”€โ”€ shellCheck.nim
      โ”œโ”€โ”€ test.cfg
      โ”œโ”€โ”€ testFile
      โ””โ”€โ”€ testProc.nim

  7 directories, 30 files

Thanks for ideas & examples ๐Ÿ’ฌ

nitch's People

Contributors

da-strange-boi avatar dadyarri avatar dou2ble avatar emanuelep57 avatar gfidder avatar jabuxas avatar juliusdeboer avatar linuxxx0 avatar prsh11 avatar qazerito avatar sp-xd avatar ssleert avatar teenarp2003 avatar xdream8 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

nitch's Issues

Images in README missing

Images were probably uploaded using GitHub's uploader and for whatever reason have disappeared.

One fix would be to push a branch containing the necessary screenshots and link them from there to the main branch's README. This way the images should be persistent without being checked out by everyone who clones the repo.

Some Nerdfont icons not appearing.

Selection_001
I am using the JetBrains Mono Nerdfont.
Here's the font part of my alacritty config:
`font:
normal:
family: JetBrainsMono Nerd Font Mono
style: Regular

bold:
family: JetBrainsMono Nerd Font Mono
style: Bold

italic:
family: JetBrainsMono Nerd Font Mono
style: Italic`

Wrong packages count on Gentoo

โฏ nitch -v
nitch - 0.1.5

---

โฏ eix -cI | wc -l
1362

---

โฏ ls -d /var/db/pkg/*/* | cut -f "5" -d "/" | wc -l
1241

image

[Feature] Alpine support

Currently alpine doesn't have an ascii art.
I don't particularly need it, I modified the default nitch ascii art so it spells "Alpine" and changed the color, but it would be nice to have by default.
image
The setup script uses sudo, so if you have doas you need to modify it

Building nitch locally uses different font used than official build..

Building locally uses a different font..
image
This is the font with official build ..
image
While this is the font used in local build..

Here is my Alacritty config..
image

Can anyone help me with this? is there any fix for this?

official both builds show with different font than local build

Make the uptime more clear

This might be an intended feature, but I think the uptime is being displayed confusingly. I think you should make it simply display in an HH:MM format.

Add Garuda ASCII Art

I'd love to have the Garuda ASCII Art.

I have trouble finding the config files and logo files to manually add it myself.

Can colors show the 16 colors of terminal?

I want colors to show the 16 ANSI colors of terminal.

I tried to add fgBrightRed in addition to the default fgRed, but it's undeclared identifier.
What is the name for the base08 -- base0F?

pkgs

nitch isn't displaying the packages correctly on gentoo.

it says pkgs: >3

image

using st terminal

Used Memory

Hi,
Just want to say you have an excellent job on nitch, But as you probably already know, there are different versions on how used memory should be displayed, I did notice on nitch that it takes TotalMem - AvailableMem to get UsedMem. I just wanted to make you aware of the formula that htop uses and which has derived from a write up on Kernel.org
https://www.kernel.org/doc/Documentation/filesystems/proc.txt

basically htop originally used MemUsed = MemTotal - MemFree - Cached - Buffers - SReclaimable + Shmem

Then some patches made it in the kernel changed the way SharedMem and Cached are calculated, I haven't personally read the patch notes https://lore.kernel.org/lkml/[email protected]/
but it basically comes down to Shmem being part of cache so the accepted formula and the one htop uses is
MemUsed = MemTotal - MemFree - Cached - Buffers - SReclaimable

I have implemented this is my fetch program written Pascal

// Get Memory and usage
function GetRamUsage(): string;
var
  strTmp, strMemTotal, strMemFree, strShmem, strBuffers, strCached,
  strSRclaimable: string;
  intMemUsage, intTotalMem: single;
  slMemInfo: TStringList;
begin
  Result := 'Error';
  // Set the name of the file that will be read
  slMemInfo := TStringList.Create;
  try
    slMemInfo.LoadFromFile('/proc/meminfo');
    try
      // Process MemTotal
      strTmp := slMemInfo.Strings[0];
      strMemTotal := Trim(ExtractString(strTmp, 'MemTotal:', 'kB'));

      // Process MemFree
      strTmp := slMemInfo.Strings[1];
      strMemFree := Trim(ExtractString(strTmp, 'MemFree:', 'kB'));

      // Process Buffers
      strTmp := slMemInfo.Strings[3];
      strBuffers := Trim(ExtractString(strTmp, 'Buffers:', 'kB'));

      // Process Cached
      strTmp := slMemInfo.Strings[4];
      strCached := Trim(ExtractString(strTmp, 'Cached:', 'kB'));

      // Process Shmem
      strTmp := slMemInfo.Strings[20];
      strShmem := Trim(ExtractString(strTmp, 'Shmem:', 'kB'));

      // Process SReclaimable
      strTmp := slMemInfo.Strings[25];
      strSRclaimable := Trim(ExtractString(strTmp, 'SReclaimable:', 'kB'));

      // Calc Mem Total
      intTotalMem := StrToFloat(strMemTotal);

      // Calc Mem Usage
      intMemUsage := (intTotalMem - StrToFloat(strMemFree) - StrToFloat(strBuffers) - 
        StrToFloat(strCached) - StrToFloat(strSRclaimable));
    finally
      slMemInfo.Free;
    end;

  except
    on E: EInOutError do
      writeln('File handling error occurred. Details: ', E.Message);
  end;

  Result := Format('%.2fGB / %.2fGB', [intMemUsage / (1024 * 1024), intTotalMem / (1024 * 1024)]);
end;

I am not saying you should change your formula, just making you aware of the accepted formula used at htop, everyone seems to have a different opinion on this particular topic, and it goes into a lot more discussion at kernel.org and htop github, hope this helps, if not disregard and deleted the topic.

fyi,
programs like btop uses the same formula as nitch, but they are aware of htop and the kernel.org discription
aristocratos/btop#161

Add a release for the new version

The version in nitch.nimble has been upgraded to 0.2.2, but the release tag is still at 0.1.6. We need to bump the release version, or else people or package maintainers won't know a new version is out.

EOF error

io.nim(156) raiseEOF
Error: unhandled exception: EOF reached [EOFError]

after installing using the script in the readme on opensuse tw (without nerd fonts)

cannot open: /etc/hostname [IOError]

Hi,
After the installation (according to README), I couldn't execute nitch due to the following error:

> nitch
io.nim(759)              open
Error: unhandled exception: cannot open: /etc/hostname [IOError]

FYI, my environment:
os: Arch Linux
kernel: 5.18.15-arch1-1

And, I have etc/hosts on my computer, but not /etc/hostname.

Exec format error

If I run nitch after the quick installation it gives me this error:
-bash: /usr/local/bin/nitch: cannot execute binary file: Exec format error
Has to do with my arm computer. Would be great, if you could make it working for it too!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.