Background: The story of implementing a trash can on the command line in Golang
gomi is a simple trash script that works on CLI, written in golang
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.
A well-known similar trash can tool is
Command line interface to the freedesktop.org trashcan.
Cross-platform command-line app for moving files and directories to the trash - A safer alternative to
rm
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.
Delete: package:
$ gomi file
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
- "*~"
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.
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.
You can also use Windows.
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.
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"
--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