Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More safety Tips / Suggestions #33

Open
amishmm opened this issue Mar 19, 2014 · 2 comments
Open

More safety Tips / Suggestions #33

amishmm opened this issue Mar 19, 2014 · 2 comments

Comments

@amishmm
Copy link

amishmm commented Mar 19, 2014

This is not really a bug but a TIP. (zsh related). I do not know where else can I put it.

Just sharing a few line code (zsh only) which others may be in search for. (because I searched too and finally made one on my own)

Purpose:

  1. trash / trash-put should ask before trashing, just like rm -i
  2. trash-put should not trash directory but just a regular file
  3. trash-empty and trash-rm should ask first. Infact ask twice, because its going to be erased forever! (Intention is to be 100% sure!)
  4. If user uses rm instead of trash-put, ask first before running rm

Here is the code: (put in your .zshrc)

if (( $+commands[trash-put] )); then
  rm() {
    if read -q "?$0: are you sure you do NOT want to use trash-put? [N/y] "; then
        echo ""
        nocorrect command rm -i "$@"
    fi
  }
  trash-put() {
    local file;
    for file in "$@"; do
      if [[ ! -f $file ]]; then
          echo "$0: cannot remove '$file': not a regular file"
          continue
      fi
      if read -q "?$0: trash regular file '$file'? [N/y] "; then
        echo ""
        nocorrect command trash-put -v -- $file
      fi
    done
  }
  alias trash=trash-put
fi
if (( $+commands[trash-rm] )); then
  trash-rm() {
    if read -q "?$0: are you sure you want to use trash-rm? [N/y] "; then
      echo ""
      if read -q "?$0: are you REALLY sure you want to use trash-rm? [N/y] "; then
          echo ""
          nocorrect command trash-rm "$@"
      fi
    fi
  }
fi
if (( $+commands[trash-empty] )); then
  trash-empty() {
    if read -q "?$0: are you sure you want to empty trash? [N/y] "; then
      echo ""
      if read -q "?$0: are you REALLY sure you want to empty trash? [N/y] "; then
          echo ""
          nocorrect command trash-empty "$@"
      fi
    fi
  }
fi

Hope it helps!

@andreafrancia
Copy link
Owner

Related to #10

@andreafrancia
Copy link
Owner

From the 0.21.5.25 release trash-put honors the -i option.
Example:

$ touch foo
$ trash-put -i foo
trash-put: trash regular empty file 'foo'? y
$ 

You can add alias trash-put='trash-put -i' to your .bashrc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants