Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
c9c870d
global overhaul
Rexxt Aug 16, 2022
b1c69c0
readme update
Rexxt Aug 16, 2022
e05b6c0
Colour, feature and config update
Rexxt Aug 16, 2022
5cd41e0
woops i fucked up
Rexxt Aug 16, 2022
237d91f
aeration
Rexxt Aug 16, 2022
b6e6ae0
readme update
Rexxt Aug 16, 2022
b4adc19
made characters configurable
Rexxt Aug 16, 2022
b649a70
unhealthy amounts of customizability
Rexxt Aug 16, 2022
a875b51
extensions wip
Rexxt Aug 16, 2022
95b7d20
after quite a bit of fixing, extensions work!
Rexxt Aug 17, 2022
83f4892
little tweaks, also working on a git extension
Rexxt Aug 17, 2022
78ae6fa
improving extension support and working on git extension
Rexxt Aug 17, 2022
4a108ef
quick gitignore update cause i'm testing extensions
Rexxt Aug 17, 2022
883fa98
git extension update
Rexxt Aug 17, 2022
01cfd72
more events
Rexxt Aug 17, 2022
1e86a61
this commit was made using the G* command of git.sh
Rexxt Aug 17, 2022
b1b0c3a
docs 'n' tweaking
Rexxt Aug 17, 2022
a487740
docs for events
Rexxt Aug 18, 2022
264caf0
tweaks to help command
Rexxt Aug 18, 2022
7b4e7bf
editing git extension
Rexxt Aug 18, 2022
35de3f5
quick git.sh update
Rexxt Aug 18, 2022
b335ba1
docs
Rexxt Aug 18, 2022
c4876bd
can now view git remote in git extension
Rexxt Aug 18, 2022
d95dce3
changed `;` command and added extension manager
Rexxt Aug 18, 2022
32f33a4
quick fix
Rexxt Aug 18, 2022
d30e261
extensions can now use helpstrings
Rexxt Aug 18, 2022
f883335
treated case for when no extensions are loaded
Rexxt Aug 18, 2022
e2f02ff
added case for when the command is empty
Rexxt Aug 18, 2022
29491d1
added save folder
Rexxt Aug 18, 2022
60595fa
ok you may now use the clock extension
Rexxt Aug 18, 2022
839e218
install script draft, will test it later
Rexxt Aug 18, 2022
4415c88
docs
Rexxt Aug 18, 2022
0eb9202
fix installer 1
Rexxt Aug 18, 2022
7ea53a9
fix installer 2
Rexxt Aug 18, 2022
b4ca446
fix installer 3
Rexxt Aug 18, 2022
4c8aefc
oopsie
Rexxt Aug 24, 2022
16c255b
added GC = git commit to git extension
Rexxt Sep 16, 2022
2e32503
Update installer.sh
Rexxt Oct 7, 2022
2091129
New features!!…
Rexxt Nov 21, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .gitignore
Empty file.
225 changes: 225 additions & 0 deletions EXTENSIONS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
# tifmx - extend tifm to your liking
we call the extension framework bundled with tifm, `tifmx`, short for `tiny file manager extensions` (creative naming!).

tifmx automatically loads extensions placed in the `extensions` folder, allowing you to drop in extensions to add them in.

it also provides a couple of functions for tifm to adapt its behaviour to your extension.

## guide
here we will create a very simple greeter extension to show you how easy it is to write an extension for tifm.

### init event
we'll start by creating a `greeter.sh` file in the `extensions` folder.<br>
then, we'll listen for the `init` event which is called when the extension is loaded.<br>
events are function definitions of this format: `ext_name.event_name`. tifmx automatically figures out the extension's name by reading the file name, so we will create our init event like this:
```bash
greeter.init() {
# code here
}
```
then, we will simply print "Hello, $USERNAME!" to the console:
```bash
greeter.init() {
echo "Hello, $USERNAME!"
}
```
you can test it out by launching tifm now.

### simple command
simple commands are when you press a key and a function gets executed. we'll bind our `h` key to say `Hey all!` when it is pressed.

we'll first start by defining our function. it can be named anything, because we will bind it using its name later; we'll call it `greet_all`:
```sh
greeter.init() {
echo "Hello, $USERNAME!"
}

# NEW
greet_all() {
echo "Hey all!"
}
```
awesome. but now, if you reload tifm and press the `h` key, you will get an error. this is because we haven't told tifm to listen to the key.

we will need to use the `tifmx.bind` command to create a binding and link it to our function. you create a binding this way:
```sh
tifmx.bind char func
```
so to bind our new `greet_all` function to the `h` key:
```sh
tifmx.bind h greet_all
```
now your file should look like this:
```sh
greeter.init() {
echo "Hello, $USERNAME!"
}

greet_all() {
echo "Hey all!"
}
# NEW
tifmx.bind h greet_all
```
you can now reload tifm and press `h` to see a nice greeting!

### long command
long commands are when you press a key to access a group, and then press another key to run a sub command. examples include `rd` (remove directory) and `nf` (new file).

we'll make two commands: `gu` to greet the user and `gw` to greet the world. we can do this using the `tifmx.add_long` and `tifmx.bind_sub` commands. you create a binding this way:
```sh
tifmx.add_long char1
tifmx.bind_sub char1 char2 func
# you can add infinite subcommands to a group
```
we have already defined a function that greets the user: `greeter.init`, so in our case we can use it. but we'll create a greet world function first:
```sh
greeter.init() {
echo "Hello, $USERNAME!"
}

greet_all() {
echo "Hey all!"
}
tifmx.bind h greet_all

# NEW
greet_world() {
echo "Hello, world!"
}
```

and now we'll create our long command:
```sh
greeter.init() {
echo "Hello, $USERNAME!"
}

greet_all() {
echo "Hey all!"
}
tifmx.bind h greet_all

greet_world() {
echo "Hello, world!"
}
# NEW
tifmx.add_long g
tifmx.bind_sub g u greeter.init
tifmx.bind_sub g w greet_world
```
you can now reload and test your long command out!

## documentation
extensions have access to everything defined in the configuration file and pretty much every aspect of tifm.
### events
events are functions defined in your extension that get called when a specific action happens inside of tifm. you define them this way: `extension.event` where extension is the name of your extension file (without `.sh`) and `event` is the name of your event. see below for all available events.
> **Note:** parameters are passed without name and are accessible via `$1`, `$2` and so on, or `"${@[n]}"` where `n` is a number.
#### `extension.init()`
called when your extension is loaded.

#### `extension.display()` (provided you're using the default `__TIFM_DISPLAY` in `config.sh`)
called when the display (top part of the command input) is displayed. whatever it echoes last will be added as a widget in the display.

example: quick clock extension:
```sh
# file: extensions/clock.sh
clock.display() {
# display clock
echo -e "$CYAN$(date +"%H:%M")$NORMAL"
}
```

#### `extension.nav(directory)`
called when the user changes directories, at the very end of the `N` command.

parameters:
* `directory`: the directory the user travelled to

#### `extension.edit(file)`
called when the user edits a file, at the very end of the `e` command.

parameters:
* `file`: the file the user edited

#### `extension.copy(from, to)`
called when the user copies a file, at the very end of the `c` command.

parameters:
* `from`: the file the user copied
* `to`: the location the file was copied to

#### `extension.move(from, to)`
called when the user moves a file, at the very end of the `m` command.

parameters:
* `from`: the file the user moved
* `to`: the location the file was moved to

#### `extension.mkdir(dir)` / `extension.mkfile(file)`
called when the user creates a directory/file, at the very end of the `n(d/f)` command.

parameters (`mkdir`):
* `dir`: the directory the user created

parameters (`mkfile`):
* `file`: the file the user created

#### `extension.rmdir(dir)` / `extension.rmfile(file)`
called when the user deletes a directory/file, at the very end of the `r(d/f)` command.

parameters (`rmdir`):
* `dir`: the directory the user deleted

parameters (`rmfile`):
* `file`: the file the user deleted

#### `extension.fperms(item, permissions)`
called when the user changes the permissions of a file, at the very end of the `P` command.

parameters:
* `item`: the file or directory for which the permissions were modified
* `permissions`: the permission arguments given to the file (in chmod format)

### functions
you have access to multiple functions that change the behaviour of tifm.
#### `tifmx.bind(char, func)`
tells tifm to listen to when `char` is pressed, and in that case call `func`.
example:
```sh
go_home() { # navigate to the home directory
cd ~
}
tifmx.bind "~" go_home
```

#### `tifmx.add_long(char)`
tells tifm to listen to when `char` is pressed, and in that case wait for another keypress and find a command associated to that combination. must be used with `tifmx.bind_sub(char1, char2, func)`.

#### `tifmx.bind_sub(char1, char2, func)`
tells tifmx to associate the combination `char1 + char2` to call `func`.
example:
```sh
go_home() {
cd ~
}
go_parent() {
cd ..
}
tifmx.add_long "~"
tifmx.bind_sub "~" "~" go_home # pressing ~ then ~ will return home
tifmx.bind_sub "~" "<" go_parent # pressing ~ then < will return to the parent directory
```

#### `tifmx.add_help(char, helpstring)`
adds a custom line in the `?` command to show the usage of your custom command.
example:
```sh
go_home() {
cd ~
}
tifmx.bind "~" go_home
tifmx.add_help "~" "return to the parent directory"
# will show like this:
# ~ - return to the parent directory
```
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# linfm
Some sort of File Manager, made in the bash interpreter

![Available on Paque](https://media.discordapp.net/attachments/655093392187064360/994649858810052668/InstallOnPaque.png)

Package name: linfm
# tifm
a really **ti**ny **f**ile **m**anager
mostly meant for personal use and contribution to the parent project
31 changes: 31 additions & 0 deletions config.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
__TIFM_PAGER="less" # [p]eek command
__TIFM_EDITOR="nano" # [e]dit command
__ANGLE_UP_RIGHT="╭"
__ANGLE_UP_LEFT="╮"
__ANGLE_DOWN_RIGHT="╰"
__ANGLE_DOWN_LEFT="╯"
__VBAR="│"
__TIFM_DECO_COLOUR="$CYAN"
__TIFM_CONFIRM_RETURN=true
__TIFM_DISPLAY() {
local stat=""
if [ "$STATUS" == "0" ]; then
stat="${GREEN}✔$NORMAL"
else
stat="${RED}✘ $STATUS$NORMAL"
fi
local string="$GREEN$BRIGHT$PWD$NORMAL $stat "
# for each extension, if it has a display function, call it
for ext_name in "${tifm_extensions[@]}"; do
if type "$ext_name".display &> /dev/null; then
string="$string$( "$ext_name".display )$NORMAL "
fi
done
echo "$string"
}
__TIFM_LS_COLOUR_FILE="$BLUE"
__TIFM_LS_COLOUR_DIRECTORY="$LIME_YELLOW"
__TIFM_PROMPT() {
user=$(whoami)
echo "$CYAN$user>"
}
Empty file added extension_ignore
Empty file.
4 changes: 4 additions & 0 deletions extensions/clock.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
clock.display() {
# display clock
echo -e "$CYAN$(date +"%H:%M")$NORMAL"
}
Loading