Created gomi, a trash can tool for rm in Go language

Background: The story of implementing a trash can on the command line in Golang

logo

b4b4r07/gomi - GitHub

gomi is a simple trash script that works on CLI, written in golang

DEMO

What is gomi?

Recycle bin tool for CLI made in Go language. When you delete a file, you can pool it in its own Recycle Bin (or System Recycle Bin) before you really delete it.

--Work with one binary --Easy to restore with interactive operation --You can QuickLook abandoned files --It can also be linked with the system recycle bin and can be "restored". --Can be customized with a YAML-formatted configuration file --Works on Windows

Everyone, I think you will use rm to delete files, but accidentally deleting important files is something that even beginners do occasionally. Also, there are times when you think you don't need it and erase it and feel the need a few days later.

In this gomi, it is once pooled in a dedicated trash can before it is deleted. In addition, the history is saved at that time, so you can easily refer to it later. It can also be easily restored with an interactive UI.

Feature

A well-known similar trash can tool is

However, the former requires Python and the latter requires Node.js. gomi is a single binary and can be executed in any environment.

Also, trash-cli allows for interactive restores, but it's not a very good UI because it's a numerical type. trash has the advantage of being able to work with the system recycle bin, but it can be easily restored from the command line (although it can be sent to the recycle bin on the command line). I couldn't. This gomi overcomes the shortcomings of both, and has the ability to QuickLook files in the trash as a further feature. The deleted file name may be covered, and there are many times when you want to check the contents quickly. In such a case, it is convenient to have a function to take a peek.

Use gomi -s filename if you want to send it to the system trash instead of the trash provided by gomi. Of course, you can restore it with gomi -r, or you can restore it with the "Return" function of the Recycle Bin.

quicklook.png

How to use

  1. Delete: package:

    $ gomi file
    
  2. Recycle bin: mag:

    $ gomi -r
    

The restore mode UI has been implemented with great reference to peco. Also, if you delete the file in ~ / .gomi again, it will really be deleted.

Also, if you pass an argument to -r, it will restore to that path (if you don't pass an argument, it will restore to the original location). You can restore to the current directory by doing gomi -r ..

It also reads a YAML-formatted configuration file. With ʻignore_files`, you can specify files that you do not want to keep in the history by using wildcards etc. (remains in the Recycle Bin).

yaml:~/.gomi/config.yaml


ignore_files:
  - .DS_Store
  - "*~"

Take a peek at the file

It's a QuickLook-like feature in OS X. You can toggle with C-q </ kbd>. It helps you to see what the files you want to restore were.

For directories, recursively enumerate the files and subdirectories inside them.

quicklook.png

Since the key binding in restore mode is still alive in QuickLook, you can move back and forth between the following files while doing QuickLook with * C-n * etc., or you can execute restore with Enter.

Cross-platform

You can also use Windows.

gomi_windows.png

Installation

If you are a Mac user using Homebrew, the following is OK (Linux is not supported).

$ brew tap b4b4r07/gomi
$ brew install gomi

Others can be installed below or from GitHub Releases.

$ go get -u github.com/b4b4r07/gomi

If it's just a binary, I've uploaded it to GitHub Releases.

Setting

Although not required, we recommend replacing the rm command with gomi. The number of types is reduced by 2 characters (gomi rm), and you can also delete the hand gesture as it is.

~/.bashrc


alias rm="gomi"

Reference: books:

--Replace rm command with trash --2009/04/03 -For those who are afraid of the rm command: Shell script that moves to the trash without deleting --2012/03/22 -Protect rm -rf, command line trash --2013/04/23 -Replace rm with trash-cli --2015/01/27 -[trash – rm alternative. File deletion using the trash can in the terminal](http://www.moongift.jp/2014/05/trash-rm alternative% E3% 80% 82 File deletion using the trash can in the terminal /) --2014/05/29 -trash-cli, rmtrash — From command line to trash

I created it with a lot of thought and momentum. From now on, I plan to maintain it (for myself) and improve the source code and functions.

Recommended Posts

Created gomi, a trash can tool for rm in Go language
Created a package to support AWS Lambda development in Go language
I created a password tool in Python.
I made a kind of simple image processing tool in Go language.
Created a header-only library management tool for C / C ++
Create a web server in Go language (net/http) (2)
Create a web server in Go language (net / http) (1)
I wrote a CLI tool in Go language to view Qiita's tag feed with CLI
A note for embedding the scripting language in a bash script
Note 2 for embedding the scripting language in a bash script
Hello World in GO language
Created a library for python that can easily handle morpheme division
[For beginners] How to register a library created in Python in PyPI
Read the config file in Go language! Introducing a simple sample
I wrote a tri-tree that can be used for high-speed dictionary implementation in D language and Python.
Try implementing Yubaba in Go language
Use optinal type-like in Go language
Post to slack in Go language
Start SQLite in a programming language
Created AtCoder test tool for Python
Write tests in GO language + gin
Do something object-oriented in GO language
I created a template for a Python project that can be used universally
How to make a request to bitFlyer Lightning's Private API in Go language
What Java users thought of using the Go language for a day