Skip to main content

Add your description here

Project description

rm-teng

An attempt to minimise the impact of rm in careless hands. Note, minimise, not prevent.

Motivation

A couple of times I've managed to rm -rf {{ some-dir }} accidentally and, each time, it's been verrry annoying. Having something which stored {{ some-dir }} in a different location would have enabled me to undo the error. Issue here is rm -i wouldn't have saved me, I've deleted things thinking they were safe to delete then found out they weren't.

Usage

Basic

Expected usage is as follows:

# in .zshrc / .bashrc / .whatever
alias rm="uvx rm-teng"

The only case that's currently handled is rm -rf {{ some-dir }}.

Configuration

Configuration is done via the following env vars:

  • RM_TENG_DELETION_DIR: Optional, controls where to store files that are relocated by rm-teng. If set it must be an absolute path. Default is ~/.rm_rf_files.
  • RM_TENG_DOUBLE_CHECK: Optional, controls whether to prompt for confirmation when running rm commands that don't have any handlers set. Default is false.

What it doesn't do

If used in the way outlined above rm-teng is only called when called interactively from the shell. It won't be called from scripts, and it won't be called from something like find . -type f | xargs rm (see https://zsh.sourceforge.io/Doc/Release/Shell-Grammar.html#Aliasing or similar if unfamiliar).

Cleaning up

When rm -rf {{ some-dir }} is run the directory is moved to ~/.rm_rf_files instead of being deleted. As a result a few entries can build up here.

rm-teng doesn't currently handle cleaning these up. It's pretty easy to do something along the lines of:

# Simple workflow to check what is in the {{ deleted-dir }} older than a certain
# time, and delete.

# check what's there
find . -mindepth 1 -type d -ctime +10 | less
# delete (if ok)
find . -mindepth 1 -maxdepth 1 -type d -ctime +10 -print0 | xargs -0 rm -rf

Hopefully a bit more mindfulness can be applied at this stage!

Restore deleted

Alternatively, you should be able to restore something by simply moving it back where it was.

E.g: if we have ~/one/two/three/four/five, then run rm -rf one it'll create:

{{ timestamp }}
└── Users
  └── user_name
    └── one
      └── two
        └── three
          └── four
            └── five

Then from ~/ you can run mv {{ rm-teng-dir }}/{{ timestamp }}/Users/user_name/one ./ to restore.

Alternative solutions

I've managed to find more of these after writing most of this, you might find one more suitable! rip2 and rm-protection (who I copied most of this list off) look nice, though I've not really used either:

Future development

I've had this running for a bit and have found it fine. Adding additional handlers should be pretty straightforward, it would also be easy to implement custom handlers for user specific settings.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

rm_teng-1.0.2.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rm_teng-1.0.2-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file rm_teng-1.0.2.tar.gz.

File metadata

  • Download URL: rm_teng-1.0.2.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for rm_teng-1.0.2.tar.gz
Algorithm Hash digest
SHA256 7d46d951d6a12758293e021cb4bba2abf8b1ad97faebcb37876a01a7d7c0c66b
MD5 c0b21bf119c4cd1986fea73fdc827fb8
BLAKE2b-256 ff4e50dc6e25c119fda47e9effbacdcd9b75faa4fd12e52457fd9f1b2383cc97

See more details on using hashes here.

Provenance

The following attestation bundles were made for rm_teng-1.0.2.tar.gz:

Publisher: release.yml on geo7/rm-teng

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file rm_teng-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: rm_teng-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for rm_teng-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d8f7a68b362656e9f4213226cd6123208e09bbe646d9c96b02ab74d2f4a94043
MD5 6afbce63ba77262189258b8c2a816f0b
BLAKE2b-256 e0588892c1613f21f3e8bfaedd389f4ed739ccdceaffe1c75bacc2658e33c116

See more details on using hashes here.

Provenance

The following attestation bundles were made for rm_teng-1.0.2-py3-none-any.whl:

Publisher: release.yml on geo7/rm-teng

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page