fig os becomes more code-oriented

ive been using the command line since my underwear had cartoons on them, so if theres a difference between using a command line interface (cli) and coding, i probably know what it is.

nonetheless, let me show you what im working on, and extend an invitation to anyone reading this to join me at the official/unofficial fig os forums, where you can learn about fig or the gnu/linux distro remastered with a fig program: (“mkfigos.”)

here is the latest feature:

fxf7kay

 

thats a program designed to do a few things:

  • give the user an immediate message about ssh running
  • enable the user to configure that setting and perhaps others
  • get the user introduced to the keyboard straight away
  • drop right to bash if the user types in “sh”

 

if the user closes that window, they have the following icons:

  • connect
  • console
  • help
  • leafpad

 

those will open wicd-gtk to get connected to the network, xterm as root, help documentation, and leafpad (which is similar to notepad in windows.)

there are graphical applications for the following functions in fig os:

  • web browsing (iceweasel, possibly switching to palemoon)
  • image editing (gimp, mtpaint)
  • text editing (leafpad, geany– libreoffice isnt installed on the live cd but can be added)
  • file management (pcmanfm)
  • image browsing (geeqie)

 

but graphical applications, while supported, arent the main point of fig os, which is based on refracta and devuan and uses the devuan repos–

fig os exists to demonstrate and support fig, to help people learn to get more comfortable with (some) command line features, and to help people learn to code.

fig os also includes some utilities written in fig:

  • the welcome program, /root/welcome.fig.py
  • /usr/bin/once.fig — like uniq except buffers input instead of requiring it to be sorted
  • /usr/bin/dircmp.fig — shows file listings unique to one folder but not the other
  • /usr/bin/arrlen.fig — shows multiline text with the line length next to each line
  • /usr/bin/arrname.fig — piping a list to | arrname 1 shows path, arrname 2 shows filename without extension, and arrname 3 shows the extension

 

suppose you want to know while files you have the most of. the first thing you need to do (at least in this version of fig os) is compile the fig programs– this is very fast!

for p in /usr/bin/*.fig ; do fig31.py $p ; done

you can also compile any of them individually like this:

fig31.py /usr/bin/once.fig
fig31.py /usr/bin/dircmp.fig
fig31.py /usr/bin/arrlen.fig
fig31.py /usr/bin/arrname.fig

 

unlike mkfigos, some of the fig utils in /usr/bin require fig 3.1 (included) instead of fig 2.9 (this is pretty easy to fix and lately ive been avoiding the one or two extra features of 3.1)

anyway, you use

find /

 

to get a list of the files on your system, then you just pipe the output of that command to the others:

find / | arrname.fig.py 3

that gives you just the extensions. this:

find / | arrname.fig.py 3 | sort

sorts the list of extensions– then this:

find / | arrname.fig.py 3 | sort | uniq -c

counts the repeats, which you can sort numerically with sort -n:

find / | arrname.fig.py 3 | sort | uniq -c | sort -n

 

according to that i have tens of thousands of .png files on my system. why so many? icons. thats pretty funny, many are for applications but there are only 4 on the desktop.

that | sort | command in there means you have to wait for the sort to complete before you can count the repeats. but if you just want an unsorted list of extensions, you can use once.fig.py:

find / | arrname.fig.py 3 | once.fig.py

or pipe it to

cat -n

to count the total number of extensions as they are found:

find / | arrname.fig.py 3 | once.fig.py | cat -n

 

there are fewer than 2000 extension types on the computer im trying this on. that includes any file that starts with a dot, like /root/.config is counted as a file with the extension “.config” …this is a limitation/design choice of arrname, which could certainly weed out any files that begin with . if i wanted it to.

you dont have to pipe these fig programs together on the command line, its just easier. if you wanted to pipe

find /

into once.fig without the command line, you could just take this line of fig code:

linesoffind "find /"  arrshell

 

and add the code from /usr/bin/once.fig, like this:

linesoffind "find /"  arrshell

function re z p 
    f = z ; split f p ; join f "" ; return f
    fig

l ; arr

forin p stdin
    cr = 13 ; chr
    lf = 10 ; chr
     z = p  ; re z cr ; re z lf

    inl = instr l z
    iftrue inl
        pass
    else
        p = z ; print
        l plus z
        fig
    next

 

now instead of having the forin line loop through stdin, have it loop through the linesoffind array instead: (change “stdin” to “linesoffind”)

linesoffind "find /"  arrshell

function re z p 
    f = z ; split f p ; join f "" ; return f
    fig

l ; arr

forin p linesoffind
    cr = 13 ; chr
    lf = 10 ; chr
     z = p  ; re z cr ; re z lf

    inl = instr l z
    iftrue inl
        pass
    else
        p = z ; print
        l plus z
        fig
    next

save as /usr/bin/findonce.fig and compile. its pretty useless because

find /

will not give you the same line twice anyway.

instead of dropping in the code for arrname, we will just add it to the first line of findonce.fig:

linesoffind "find / | arrname.fig.py 3"  arrshell

function re z p 
    f = z ; split f p ; join f "" ; return f
    fig

l ; arr

forin p linesoffind
    cr = 13 ; chr
    lf = 10 ; chr
     z = p  ; re z cr ; re z lf

    inl = instr l z
    iftrue inl
        pass
    else
        p = z ; print
        l plus z
        fig
    next

 

now it will do what our single-line shell example did, as will our original example made into a fig program:

now "find / | arrname.fig.py 3 | once.fig.py | cat -n"  shell

 

with fig, you can create easier-to-use (less complex) shell tools than the ones that come with bash– they can start with bash commands, they can include the output of bash commands, but putting fig programs together | in | a | pipeline is great.

suppose of course, you dont want to type out (or even tab complete) once.fig.py or arrname.fig.py …thats fine, do this at the command line:

cp /usr/bin/arrname.fig.py /usr/bin/arrname
cp /usr/bin/once.fig.py /usr/bin/once

 

now you can use fig utils like any other shell commands:

find /  |  arrname 3  |  once  |  cat -n