Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Command methods

This command lists available methods, taking links into account.

irnix e methods
self.logm.log
self.__logger__.logm.log
self.waybar.reload
self.headphones.disconnect
self.headphones.connect
self.build
logm.log
__logger__.log
waybar.reload
headphones.disconnect
headphones.connect

In this case self is a symlink the current namespace.


This command allows you to create very powerful things. For example, let’s add the method build directly into the namespace, and also a link self to that same namespace:

cd ~/.local/share/irnix
ln -s . self
~/.local/share/irnix
├── build
└── self -> .

Also create a .build directory in the namespace:

mkdir ~/.local/share/irnix/.build

Contents of build:

#!/bin/bash

DIR=$HOME/.local/share/irnix/.build/

for method in `irnix methods`; do
  printf "#!/bin/bash\nirnix e $method -- \$*" > "$DIR$method"
  chmod +x "$DIR$method"
done

As you can see, our method build creates scripts of the form:

#!/bin/bash

irnix e object.method -- $*

…with names that correspond to methods, and also gives them execute permissions. Each script internally calls Irnix, passing arguments. If you add this path to PATH (e.g., in .bashrc or .zshenv):

export PATH="$HOME/.local/share/irnix/.build:$PATH"

…and run the method build:

irnix e self.build

…you will be able to call methods directly from the terminal, without having to type irnix e each time!

We can also add a contract for the method build, for safety:

~/.local/share/irnix
├── .self
├── build
└── self -> .

.self:

build:

In the end we get the ability to easily invoke our methods that are located in .build:

~/.local/share/irnix
├── .build
│   ├── __logger__.log
│   ├── headphones.connect
│   ├── headphones.disconnect
│   ├── logm.log
│   ├── self.__logger__.logm.log
│   ├── self.build
│   ├── self.headphones.connect
│   ├── self.headphones.disconnect
│   ├── self.logm.log
│   ├── self.waybar.reload
│   └── waybar.reload
├── .self
├── __logger__
│   ├── .self
│   └── logm -> ../logm
├── build
├── headphones
│   ├── .self
│   ├── connect
│   └── disconnect
├── logm
│   ├── .self
│   └── log -> /bin/logm
├── self -> .
└── waybar
    ├── .self
    └── reload

We can also refine our script to clear the folder before creating scripts:

#!/bin/bash

DIR=$HOME/.local/share/irnix/.build/

rm $DIR*

for method in `irnix methods`; do
  printf "#!/bin/bash\nirnix e $method -- \$*" > "$DIR$method"
  chmod +x "$DIR$method"
done

After that, all methods can be used, for example:

echo message | __logger__.log warn

This approach shortens the call, while implicitly using Irnix under the hood.