1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
# bb - An itty bitty browser for command line file management
`bb` (bitty browser) is a TUI console file browser that is:
- Extremely lightweight (currently around 1.2K lines of code)
- Highly interoperable with unix pipelines
- Highly customizable and hackable
- Without any build dependencies other than the C standard library (no ncurses)
- A good proof-of-concept for making a TUI from scratch
The core idea behind `bb` is that almost all actions are performed by piping
selected files to external scripts, rather than having the file manager itself
try to anticipate and hard-code every possible user action. Unix tools are very
good at doing file management, the thing that `bb` adds is immediate visual
feedback and rapid navigation.
For example, instead of using `ls`, then `rm` and typing out file names, you can
just open `bb`, scroll through the list of files, select the ones you want to
delete, and hit `D`. The `D` key's behavior is defined in a single line of code
in `config.h` as piping the selected files to `xargs -0 rm -rf`. That's it! If
you want to add a mapping to upload files to your server, you can just add a
binding for `xargs -0 scp user@example.com`. Want to zip files? Add a mapping for
`xargs -0 zip "$(printf 'Zip file: ' >/dev/tty && head -n1 /dev/tty)"` or, if
you have some complicated one-time task, you can just hit `|` and type in any
arbitrary command and have the selected files piped to it.
## Zero Dependencies
There's a lot of TUI libraries out there like ncurses and termbox, but
essentially all they do is write ANSI escape sequences to the terminal. `bb`
does all of that by itself, just using basic calls to `write()`, with no
external libraries beyond the C standard library. Since `bb` only has to
support the terminal functionality that it uses itself, `bb`'s entire source
code is less than half the size of the source code for an extremely compact
library like termbox, and less than *half a percent* of the size of the source
code for ncurses. I hope anyone checking out this project can see it as a great
example of how you can build a full TUI without ncurses or any external
libraries as long as you're willing to hand-write a few escape sequences.
## Building
`make`
`sudo make install`
## Usage
Just run `bb` to launch the file browser. Press `?` for a full list of
available key bindings. In short: `h`/`j`/`k`/`l` or arrow keys for navigation,
`q` to quit, <space> to toggle selection, `d` to delete, `c` to copy, `m` to
move, `r` to rename, `n` to create a new file, `N` to create a new directory,
and `|` to pipe files to a command.
## Hacking
If you want to customize `bb`, you can add or change the key bindings by
editing `config.h` and recompiling. In [suckless](https://suckless.org/) style,
customizing means editing source code, and compilation is extremely fast.
Key character constants are in `keys.h` and the rest of the code is in `bb.c`.
If you want to get user input during a command (e.g. to get the name of a new file),
you can use `/dev/tty` like so: `touch "$(printf 'New file: ' >/dev/tty && head -n1 /dev/tty)"`
## License
`bb` is released under the MIT license. See the `LICENSE` file for full details.
|