diff options
| author | Robert Günzler <r@gnzler.io> | 2021-04-26 01:59:39 +0200 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2021-04-26 02:09:50 +0200 |
| commit | afad731bc89c88f063603e2944bb73d5e9ce0587 (patch) | |
| tree | 8a292bfad7b677013543c4f80f28085262cb5e44 | |
| parent | 2fa1b42fc9e37dc1e0baa02f8ede0a6655b72858 (diff) | |
add bin/rm and bash alias; help not deleting stuff on accident
| -rw-r--r-- | .bashrc | 2 | ||||
| -rwxr-xr-x | bin/rm | 38 |
2 files changed, 39 insertions, 1 deletions
diff --git a/.bashrc b/.bashrc index 784d49b..d7dfbd5 100644 --- a/.bashrc +++ b/.bashrc @@ -70,9 +70,9 @@ _prompt_hook() { # Alias shell commands # alias logout='dbus-send --session --type=method_call --print-reply --dest=' -alias rm='rm -I --one-file-system' alias vim=nvim alias v=nvim +alias rm=$HOME/bin/rm alias l='exa --long --classify --group --header --group-directories-first' alias lt='exa --classify --group-directories-first -T' alias ..='cd ..' diff --git a/bin/rm b/bin/rm new file mode 100755 index 0000000..f3a604c --- /dev/null +++ b/bin/rm @@ -0,0 +1,38 @@ +#!/bin/bash + +if [ ! -t 1 ]; then + # shellcheck disable=SC2068 + exec /bin/rm $@ +fi + +# stop me from being stupid + +OPTIND=0 +for o in "$@"; do + OPTIND+=1 + if [ -d "$o" ] || [ -f "$o" ]; then + break + fi + [ "$o" = "-r" ] && recurse=1 + [ "$o" = "-f" ] && force=1 + [ "$o" = "-rf" ] && force=1 && recurse=1 +done + +if [ -n "${force}" ] && [ -n "${recurse}" ]; then + tput setaf 1 + ls -l "${!OPTIND}" >&2 + echo "!" + echo "! recursive force not allowed" >&2 + echo "!" + tput sgr0 + exit 1 +fi + +if [ -n "${recurse}" ]; then + tput setaf 1 + ls -l "${!OPTIND}" >&2 + tput sgr0 +fi + +# shellcheck disable=SC2068 +exec /bin/rm -I --one-file-system $@ |