monat -- Modern file system Navigator
Introduction
monat
is a Unix shell auxiliary command focusing on the navigation of the file system, especially for working in big projects. Think of a scenario where you are at the root directory of a big project, and there are files lying in many deep directories. It's common to visit the files, rename or move them, run a command in some sub-directories and come back to the root, etc. It would be tedious to input the long path prefix again and again.
monat
is designed to simplify this process by leveraging a simple syntax to express the long path prefix.
Example
-
Rename:
$ mv path/to/the/foo.txt path/to/the/bar.txt
In
monat
we can input command below, which is shorter:$ mn path/to/the/foo.txt ,/bar.txt
-
Move file up one level:
$ mv path/to/another/foo.txt path/to/
In
monat
we can input:$ mn path/to/another/foo.txt ,/../
-
Use history:
Directory visited by
monat
just now will be stored in the history. Using themn
command without arguments will list the history. When in Bash, you can also press$ mn ,<TAB>
> 1 -- path/to/the 2 -- path/to/another 3 -- path/to Then you can use the number after the comma to represent the path:
$ mn ,1/bar.txt ,2
is equivalent to:
$ mv path/to/the/bar.txt path/to/another/
-
Run another command by leveraging
monat
:$ mn -c vim ,2/bar.txt
is equivalent to:
$ vim path/to/another/bar.txt
-
Dive into a sub-directory and run a command:
$ cd path/to/the/ $ source update.sh $ cd -
Though you can gather them into one line, you can't have filename autocompletion though:
$ cd path/to/the/ && source update.sh; cd -
In
monat
we can input:$ mn -d ,1 -c source update.sh
The advantages are:
-
short command in one line,
-
the
update.sh
filename can be autocompleted by pressing
-
Remember you can always press
to complete the path, command and filename in Bash, including the one represented by comma and number, which is very easy to input the whole command. Support for other shells will be added in future.
Usage
Syntax
The monat
syntax is simple. The path starting with a comma (,) is called Path Epitome.
If inputing two path with the second one starting with a comma, the comma represents the path prefix of the first one. Just like the first example.
If a comma follows a number i
, it means the i
th history record in the history file.
Arguments
monat
's function varies by the number of Path Epitome arguments.
-
0 Path Epitome: list the history for the current directory
-
1 Path Epitome:
monat
serves as thels
command -
2 Path Epitomes:
monat
serves as themv
command -
with
-c
argument: run the command passed by-c
and expand the Path Epitome.
History file
monat
stores a history for each project in the .monat/history
file in the root of the project. Before all the operations, first use mn -l
in the root directory to set the current directory as the root of the project. If no local monat
history is found, then monat
will use the history in home directory ~/.monat/history
.
The number of history records will be limited to 10 and in a First-In-First-Out (FIFO) manner.
Tradeoffs
monat
can only be used when there are no filenames starting with a comma. In the real world this kind of filename will be rare so we consider the design workable.
Contribution
monat
needs more features to be a better tool. Future works:
-
support the same arguments of
ls
andmv
-
For now the
monat
only supports autocompletion for Bash. We need support for other shells (especially zsh).