Skip to content

Commit

Permalink
Merge pull request #44 from babarot/babarot/ui
Browse files Browse the repository at this point in the history
Add brand new UI for restore functionality (Bubble Tea integration)
  • Loading branch information
babarot authored Jan 27, 2025
2 parents deb9508 + 6d43bb2 commit 9b84962
Show file tree
Hide file tree
Showing 29 changed files with 3,564 additions and 743 deletions.
5 changes: 3 additions & 2 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ builds:
- darwin
ldflags:
- -s -w
- -X main.Version=v{{.Version}}
- -X main.Revision={{.ShortCommit}}
- -X main.version=v{{.Version}}
- -X main.revision={{.ShortCommit}}
- -X main.date={{.CommitDate}}
main: .

archives:
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2023 Masaki ISHIYAMA
Copyright (c) 2025 Masaki ISHIYAMA

MIT License

Expand Down
214 changes: 134 additions & 80 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,94 +1,57 @@
<p align="center">
<img src="./docs/screenshot.png" width="500" alt="gomi">
</p>

<p align="center">
<a href="https://b4b4r07.mit-license.org">
<img src="https://img.shields.io/github/license/babarot/gomi" alt="License"/>
</a>
<a href="https://github.com/babarot/gomi/releases">
<img
src="https://img.shields.io/github/v/release/babarot/gomi"
alt="GitHub Releases"/>
</a>
<br />
<a href="https://babarot.github.io/gomi/">
<img
src="https://img.shields.io/website?down_color=lightgrey&down_message=donw&up_color=green&up_message=up&url=https%3A%2F%2Fbabarot.me%2Fgomi"
alt="Website"
/>
</a>
<a href="https://github.com/babarot/gomi/actions/workflows/release.yaml">
<img
src="https://github.com/babarot/gomi/actions/workflows/release.yaml/badge.svg"
alt="GitHub Releases"
/>
</a>
<a href="https://github.com/babarot/gomi/blob/master/go.mod">
<img
src="https://img.shields.io/github/go-mod/go-version/babarot/gomi"
alt="Go version"
/>
</a>
</p>

# 🗑️ Replacement for UNIX rm command!

`gomi` (ごみ/go-mi means a trash in Japanese) is a simple trash tool that works on CLI, written in Go

The concept of the trashcan does not exist in Command-line interface ([CLI](http://en.wikipedia.org/wiki/Command-line_interface)). If you have deleted an important file by mistake with the `rm` command, it would be difficult to restore. Then, it's this `gomi`. Unlike `rm` command, it is possible to easily restore deleted files because `gomi` have the trashcan for the CLI.
# 🗑️ A Safer Alternative to the UNIX `rm` Command!

`gomi` (meaning "trash" in Japanese) is a simple CLI tool written in Go that adds trash can functionality to the command line.

In a typical CLI, there’s no "trash" folder like in graphical file managers. This means if you accidentally delete important files using the `rm` command, restoring them can be very difficult. That's where `gomi` comes in. Unlike `rm`, which permanently deletes files, `gomi` moves them to the trash, allowing you to easily restore files whenever necessary. If you’re used to `rm` in the shell, `gomi` works as a more convenient, safer alternative.

![demo](./docs/demo.gif)

[![Go](https://github.com/babarot/gomi/actions/workflows/build.yaml/badge.svg)](https://github.com/babarot/gomi/actions/workflows/build.yaml)
[![Release](https://github.com/babarot/gomi/actions/workflows/release.yaml/badge.svg)](https://github.com/babarot/gomi/actions/workflows/release.yaml)

## Features

- Like a `rm` command but not unlink (delete) in fact (just move to another place)
- Easy to restore, super intuitive
- Compatible with `rm` command, e.g. `-r`, `-f` options
- Nice UI, awesome CLI UX
- Easy to see what gomi does with setting `GOMI_LOG=[trace|debug|info|warn|error]`
- Functions like the `rm` command but moves files to the trash instead of permanently deleting them.
- Simple and intuitive restoration process with a user-friendly interface.
- Compatible with most of the flags available for the `rm` command.
- Allows easy searching of deleted files using fuzzy search.
- Customizable via a YAML configuration file:
- Filter what files to show (using regexp patterns, file globs, file size, etc.).
- Customize file content colorization.
- Define the command to list directory contents.
- Customize visual styles (e.g., color of selected files).

## Usage

```console
$ alias rm=gomi
```
```console
$ rm -rf important-dir
```
```console
$ rm --restore
Search: █
Which to restore?
▸ important-dir
main_test.go
main.go
test-dir
↓ validate_test.rego

Name: important-dir
Path: /Users/babarot/src/github.com/babarot/important-dir
DeletedAt: 5 days ago
Content: (directory)
-rw-r--r-- important-file-1
-rw-r--r-- important-file-2
drwxr-xr-x important-subdir-1
drwxr-xr-x important-subdir-2
...
`gomi` is compatible with `rm` flags (like `-i`, `-f`, and `-r`), so you can easily replace `rm` by setting up an alias:

```bash
alias rm=gomi
```

## Installation
I developed `gomi` as a safer replacement for `rm`, so setting up the alias is recommended. However, feel free to adjust to your preferences. The instructions below assume the alias is set.

Download the binary from [GitHub Releases][release] and drop it in your `$PATH`.
Move files to the trash:

- [Darwin / Mac][release]
- [Linux][release]
```bash
rm files
```

For macOS / [Homebrew](https://brew.sh/) user:
Restore a file to its original location. The `--restore` flag is a bit long, so you can use the shorthand `-b`:

```bash
brew install babarot/tap/gomi
rm -b
```

Using [afx](https://github.com/babarot/afx), package manager for CLI:
## Installation

### From Binaries

Download a precompiled binary directly from [GitHub Releases][release] and place it in your `$PATH`.

### Using a CLI Package Manager

With [afx](https://github.com/babarot/afx):

```yaml
github:
Expand All @@ -98,20 +61,111 @@ github:
repo: gomi
release:
name: gomi
tag: v1.1.5
tag: v1.2.0
command:
link:
- from: gomi
alias:
rm: gomi
```
```console
afx install
```

### AUR (Arch User Repository)

AUR users:
You can install `gomi` using an AUR helper:

https://aur.archlinux.org/packages/gomi/
```bash
yay -S gomi
```

```bash
paru -S gomi
```

Find it [here on AUR](https://aur.archlinux.org/packages/gomi/).

## Configuration

<!--
In `gomi`, you can customize its behavior and appearance using a YAML configuration file. When you run `gomi` for the first time, a default config (like the one below) will be automatically generated at `~/.config/gomi/config.yaml`.
-->

You can customize `gomi`'s behavior and appearance with a YAML configuration file. The first time you run `gomi`, a default config will be automatically generated at `~/.config/gomi/config.yaml`.

Here is an example of the default config:

```yaml
core:
restore:
confirm: false # If true, prompts for confirmation before restoring (yes/no)
verbose: true # If true, displays detailed restoration information

ui:
density: spacious # or compact
preview:
syntax_highlight: true
colorscheme: nord # Available themes: https://xyproto.github.io/splash/docs/index.html
directory_command: ls -F -A --color=always
style:
list_view:
cursor: "#AD58B4" # purple
selected: "#5FB458" # green
indent_on_select: false
detail_view:
border: "#FFFFFF"
info_pane:
deleted_from:
fg: "#EEEEEE"
bg: "#1C1C1C"
deleted_at:
fg: "#EEEEEE"
bg: "#1C1C1C"
preview_pane:
border: "#3C3C3C"
size:
fg: "#EEEEDD"
bg: "#3C3C3C"
scroll:
fg: "#EEEEDD"
bg: "#3C3C3C"
exit_message: bye! # Customizable exit message
paginator_type: dots # or arabic

history:
include:
within_days: 100 # Only show files deleted in the last 100 days
exclude:
files:
- .DS_Store # Exclude .DS_Store files
patterns:
- "^go\\..*" # Exclude files starting with "go."
globs:
- "*.jpg" # Exclude JPEG files
size:
min: 0KB # Exclude empty files
max: 10GB # Exclude files larger than 10GB

```

## Tips

To get extra debug output (not shown in the official help), use the `--debug` flag:

```console
gomi --debug
```

This command will stream log output, similar to `tail -f`. While running `gomi --debug`, you can open another terminal or console and execute `gomi` commands to view live updates in the log as they happen. This is useful for debugging and monitoring `gomi`'s actions in real time.

If you prefer JSON formatted output, use:

```console
gomi --debug=json
```

## Versus
## Related

- [andreafrancia/trash-cli](https://github.com/andreafrancia/trash-cli)
- [sindresorhus/trash](https://github.com/sindresorhus/trash)
Expand Down
Binary file added docs/demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
84 changes: 84 additions & 0 deletions docs/demo.tape
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
Require gomi

Output demo.gif

Set Shell "zsh"
Set FontSize 24
Set Width 1800
Set Height 1200
Set Theme "tokyonight"
Set FontFamily "Hack Nerd Font"

Hide
Type "setopt interactivecomments" Enter
Type "alias ls='exa --group-directories-first'" Enter
Type "clear" Enter
Show

## Example 1
Sleep 1s
Type "# Let's move files to trash" Sleep 0.2s Enter Sleep 0.5s
Type "ls" Sleep 0.2s Enter Sleep 0.5s
Type "gomi ./internal ./main.go" Sleep 0.2s Enter Sleep 0.5s
Type "ls" Sleep 0.2s Enter Sleep 0.5s
Type "# Ok, removed." Sleep 0.2s Enter Sleep 0.5s
Type "# Let's restore files!" Sleep 0.2s Enter Sleep 0.5s
Type "gomi --restore" Sleep 0.2s Enter Sleep 0.5s

# See the UI
Sleep 1.5s

# file 1
Type " " Sleep 2s
Type "j" Sleep 100ms
Type "j" Sleep 100ms
Type "j" Sleep 100ms
Type "j" Sleep 100ms
Type "j" Sleep 100ms
Type "j" Sleep 100ms
Type "j" Sleep 100ms
Type "j" Sleep 100ms
Type "j" Sleep 100ms
Sleep 0.5s
Type "G" Sleep 100ms
Sleep 0.5s
Type "g" Sleep 100ms
Sleep 1s
Type " " Sleep 100ms
Sleep 1s

# next file
Type "j" Sleep 100ms
Sleep 1s

# file 2
Type " " Sleep 2s
Type "j" Sleep 100ms
Type "j" Sleep 100ms
Type "j" Sleep 100ms
Type "j" Sleep 100ms
Type "j" Sleep 100ms
Type "j" Sleep 100ms
Type "j" Sleep 100ms
Type "j" Sleep 100ms
Type "j" Sleep 100ms
Sleep 0.5s
Type "G" Sleep 100ms
Sleep 0.5s
Type "g" Sleep 100ms
Sleep 1s
Type " " Sleep 100ms
Sleep 1s

# restore
Type "k" Sleep 100ms
Sleep 1s
Tab@1s
Tab@1s
Sleep 0.5s
Enter
Sleep 0.5s
Type "# Let's check file is back" Sleep 0.2s Enter Sleep 0.5s
Type "ls" Sleep 0.2s Enter Sleep 0.5s
Type "# Now restored!" Sleep 0.2s Enter Sleep 0.5s
Sleep 2s
Loading

0 comments on commit 9b84962

Please sign in to comment.