You are not logged in.

#1 2013-11-22 04:04:14

dcell
Member
From: U.S.
Registered: 2013-11-17
Posts: 6

Fetter - A lightweight information tool.

https://aur.archlinux.org/packages/fetter/

Fetter is a lightweight utility, to display information about your computer when your terminal opens, or to take screenshots using imagemagick. It's much like screenfetch only it displays less information, and runs quicker. On my system, it runs in 5 milliseconds, while Screenfetch runs in about .8 seconds. The screenshot part of Fetter is much slower, but it's not quite as important in that part of the utility.

https://dl.dropboxusercontent.com/s/pvp … pshot5.png

It currently can display banners for Arch and Arch based distros, and one generic banner that just says "linux".

https://dl.dropboxusercontent.com/s/6xl … pshot3.png

Fetter is a good alternative to Screenfetch if you use your terminal frequently, and don't like the pause that screenfetch creates before you can start typing. It's not a good alternative however, if you don't mind the wait, and like to display more information in your screenshots.

It's still in its infancy and under development, but no issues have gone unresolved yet. You can download the latest C++ source for it here https://www.dropbox.com/s/z5fg063gtxdfhm5/fetter.zip.

I'm always looking for suggestions, or improvements, so if you have any I'd love to hear them.



-- mod edit: read the Forum Etiquette and only post thumbnails http://wiki.archlinux.org/index.php/For … s_and_Code [jwr] --

Last edited by dcell (2013-11-22 04:50:19)

Offline

#2 2013-11-22 04:13:52

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Fetter - A lightweight information tool.

Are you sure that e.g. Manjaro uses the same kernel as Arch?

Edit: I think I get it now: you don't have any Arch-based distros installed and you just wanted to show the pretty text :-)

Last edited by karol (2013-11-22 04:22:13)

Offline

#3 2013-11-22 04:23:52

dcell
Member
From: U.S.
Registered: 2013-11-17
Posts: 6

Re: Fetter - A lightweight information tool.

karol wrote:

Are you sure that e.g. Manjaro uses the same kernel as Arch?

None of the information except the OS is hard coded into Fetter, so when I had Fetter print out information for other distro's it still displayed my Arch information with their banner. Someone running something else would have different information.

Last edited by dcell (2013-11-22 04:24:18)

Offline

#4 2013-11-22 04:26:36

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Fetter - A lightweight information tool.

Yeah, I get it now, sorry.
Maybe it would be possible to scrape it from 'uname -r', but having a switch does the job.

https://www.linuxdistrocommunity.com/fo … p?tid=1448

$ uname -a
Linux manjaro 3.10.13-1-MANJARO #1 SMP Fri Sep 27 22:10:07 UTC 2013 x86_64 GNU/Linux

http://www.chakra-project.org/bbs/viewtopic.php?id=8116

$ name -a
Linux chakra-pc 3.4.3-1-CHAKRA #1 SMP PREEMPT Mon Jun 18 17:39:58 UTC 2012 x86_64 GNU/Linux

Offline

#5 2013-11-22 04:42:46

dcell
Member
From: U.S.
Registered: 2013-11-17
Posts: 6

Re: Fetter - A lightweight information tool.

karol wrote:

Yeah, I get it now, sorry.
Maybe it would be possible to scrape it from 'uname -r', but having a switch does the job.

https://www.linuxdistrocommunity.com/fo … p?tid=1448

$ uname -a
Linux manjaro 3.10.13-1-MANJARO #1 SMP Fri Sep 27 22:10:07 UTC 2013 x86_64 GNU/Linux

http://www.chakra-project.org/bbs/viewtopic.php?id=8116

$ name -a
Linux chakra-pc 3.4.3-1-CHAKRA #1 SMP PREEMPT Mon Jun 18 17:39:58 UTC 2012 x86_64 GNU/Linux

For the main part of Fetter that displays the text, I've tried to not have it rely on other programs, because that makes Fetter dependent on their speed. Since Fetter is written in C++, the way I used to have it look for your OS, was by checking the presence of the /etc/arch-release file. When I added banners for other distro's I made a conditional statement that looks for the variations of that file in other distro's, and it slowed it down quite a bit, so I removed that part of Fetter and just tied the OS part of the information with the banner chosen.

Last edited by dcell (2013-11-22 04:44:48)

Offline

#6 2013-11-22 05:39:28

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Fetter - A lightweight information tool.

My /etc/arch-release is empty, but

$ cat /etc/os-release
NAME="Arch Linux"
ID=arch
PRETTY_NAME="Arch Linux"
ANSI_COLOR="0;36"
HOME_URL="https://www.archlinux.org/"
SUPPORT_URL="https://bbs.archlinux.org/"
BUG_REPORT_URL="https://bugs.archlinux.org/"

Do other distros use other files?

I noticed you get the kernel release info from utsname but the hostname from /etc/hostname - why not use

struct utsname KernelNodename;
uname(&KernelNodename);

Is /etc/hostname the correct way? I know nothing about C++ and I'm not a dev, so excuse me if it's a silly question.

$ diff -Naur fetter.cpp src/fetter.cpp
--- fetter.cpp	2013-11-22 05:33:12.446603599 +0000
+++ src/fetter.cpp	2013-11-22 05:34:47.889938310 +0000
@@ -64,20 +64,6 @@
 
 
 
-  //finds your hostname
-  ifstream HostnameFile( "/etc/hostname" );
-
-  string Hostname;
-  if (HostnameFile.good())
-  {
-    getline(HostnameFile, Hostname);
-  }
-
-  HostnameFile.close();
-
-
-
-
   //finds your CPU information
   char* search = "model name";
   int Offset;
@@ -118,6 +104,8 @@
   struct utsname KernelRelease;
   uname(&KernelRelease);
 
+  struct utsname KernelNodename;
+  uname(&KernelNodename);
 
 
   //finds the system uptime
@@ -148,7 +136,7 @@
   if ( parameter == "arch" )
   {
     cout << "\n";
-    cout << "   ___           _         " << getenv("USER") << "@" << Hostname << "\n";
+    cout << "   ___           _         " << getenv("USER") << "@" << KernelNodename.nodename << "\n";
     cout << "  / _ \\         | |        OS: Arch Linux \n";
     cout << " / /_\\ \\_ __ ___| |__      Kernel: " << KernelRelease.release << "\n";
     cout << " |  _  | '__/ __| '_ \\     CPU: " << Cpu << "\n";
@@ -158,7 +146,7 @@
   else if ( parameter == "manjaro" )
   {
     cout << "\n";
-    cout << "  __  __             _                     " << getenv("USER") << "@" << Hostname << "\n";
+    cout << "  __  __             _                     " << getenv("USER") << "@" << KernelNodename.nodename << "\n";
     cout << " |  \\/  |           (_)                    OS: Manjaro Linux\n";
     cout << " | \\  / | __ _ _ __  _  __ _ _ __ ___      Kernel: " << KernelRelease.release << "\n";
     cout << " | |\\/| |/ _` | '_ \\| |/ _` | '__/ _ \\     CPU: " << Cpu << "\n";
@@ -171,7 +159,7 @@
   else if ( parameter == "chakra" )
   {
     cout << "\n";
-    cout << "   ___ _           _                  " << getenv("USER") << "@" << Hostname << "\n";
+    cout << "   ___ _           _                  " << getenv("USER") << "@" << KernelNodename.nodename << "\n";
     cout << "  / __\\ |__   __ _| | ___ __ __ _     OS: Chakra Linux \n";
     cout << " / /  | '_ \\ / _` | |/ / '__/ _` |    Kernel: " << KernelRelease.release << "\n";
     cout << "/ /___| | | | (_| |   <| | | (_| |    CPU: " << Cpu << "\n";
@@ -183,7 +171,7 @@
     cout << "                    _       \n";
     cout << "                   | |      \n";
     cout << "      __ _ _ __ ___| |__    \n";
-    cout << "     / _` | '__/ __| '_ \\   " << getenv("USER") << "@" << Hostname << "\n";
+    cout << "     / _` | '__/ __| '_ \\   " << getenv("USER") << "@" << KernelNodename.nodename << "\n";
     cout << " _  | (_| | | | (__| | | |  OS: ArchBang Linux \n";
     cout << "| |  \\__,_|_|  \\___|_| |_|  Kernel:" << KernelRelease.release << "\n";
     cout << "| |__   __ _ _ __   __ _    CPU:" << Cpu << "\n";
@@ -197,7 +185,7 @@
   else if ( parameter == "antergos" )
   {
     cout << "              _                              \n";
-    cout << "   __ _ _ __ | |_ ___ _ __ __ _  ___  ___    " << getenv("USER") << "@" << Hostname << "\n";
+    cout << "   __ _ _ __ | |_ ___ _ __ __ _  ___  ___    " << getenv("USER") << "@" << KernelNodename.nodename << "\n";
     cout << "  / _` | '_ \\| __/ _ \\ '__/ _` |/ _ \\/ __|   OS: Antergos Linux \n";
     cout << " | (_| | | | | ||  __/ | | (_| | (_) \\__ \\   Kernel: " << KernelRelease.release << "\n";
     cout << "  \\__,_|_| |_|\\__\\___|_|  \\__, |\\___/|___/   CPU: " << Cpu << "\n";
@@ -207,7 +195,7 @@
   else if ( parameter == "bridge" )
   {
     cout << " _          _     _               \n";
-    cout << "| |__  _ __(_) __| | __ _  ___    " << getenv("USER") << "@" << Hostname << "\n";
+    cout << "| |__  _ __(_) __| | __ _  ___    " << getenv("USER") << "@" << KernelNodename.nodename << "\n";
     cout << "| '_ \\| '__| |/ _` |/ _` |/ _ \\   OS: Bridge Linux \n";
     cout << "| |_) | |  | | (_| | (_| |  __/   Kernel: " << KernelRelease.release << "\n";
     cout << "|_.__/|_|  |_|\\__,_|\\__, |\\___|   CPU: " << Cpu << "\n";
@@ -217,7 +205,7 @@
   else if ( parameter == "linux" )
   {
 cout << " _     _                     \n";
-cout << "| |   (_)                    " << getenv("USER") << "@" << Hostname << "\n";
+cout << "| |   (_)                    " << getenv("USER") << "@" << KernelNodename.nodename << "\n";
 cout << "| |    _ _ __  _   ___  __   OS: Linux \n";
 cout << "| |   | | '_ \\| | | \\ \\/ /   Kernel: " << KernelRelease.release << "\n";
 cout << "| |___| | | | | |_| |>  <    Cpu: " << Cpu << "\n";

Offline

#7 2013-11-22 07:52:12

dcell
Member
From: U.S.
Registered: 2013-11-17
Posts: 6

Re: Fetter - A lightweight information tool.

Most Distros have a file in /etc that has release information about the distro. The file arch-release used to contain information about the current release I believe, but now it's empty, however it's existence can be used to identify Arch. There's actually a list of the variations across linux distro's here http://linuxmafia.com/faq/Admin/release-files.html

Also thank you for the tip. I wasn't aware utsname had that capability. It looks much cleaner than reading directly from /etc/hostname, and there does appear to be a speed increase, although I didn't profile it. I updated fetter with the new code on the AUR.

As far as there being a right and wrong way, I'm not really sure. At the time I figured reading directly from the hostname file would be the most accurate and cross compatible, but the code you gave me seems to be just as accurate.

Last edited by dcell (2013-11-22 09:38:55)

Offline

Board footer

Powered by FluxBB