标签 嘲讽 下的文章

这是一个非常有趣的脚本,每当用户在终端输入错误的命令时,它都会嘲讽用户。

它让你在解决一些问题时会感到快乐。有的人在受到终端嘲讽的时候感到不愉快。但是,当我受到终端的批评时,我真的很开心。

这是一个有趣的 CLI 工具,在你弄错的时候,会用随机短语嘲讽你。此外,它允许你添加自己的短语。

如何在 Linux 上安装 Bash-Insulter?

在安装 Bash-Insulter 之前,请确保你的系统上安装了 git。如果没有,请使用以下命令安装它。

对于 Fedora 系统, 请使用 DNF 命令 安装 git。

$ sudo dnf install git

对于 Debian/Ubuntu 系统,请使用 APT-GET 命令 或者 APT 命令 安装 git。

$ sudo apt install git

对于基于 Arch Linux 的系统,请使用 Pacman 命令 安装 git。

$ sudo pacman -S git

对于 RHEL/CentOS 系统,请使用 YUM 命令 安装 git。

$ sudo yum install git

对于 openSUSE Leap 系统,请使用 Zypper 命令 安装 git。

$ sudo zypper install git

我们可以通过 克隆 clone 开发人员的 GitHub 存储库轻松地安装它。

首先克隆 Bash-insulter 存储库。

$ git clone https://github.com/hkbakke/bash-insulter.git bash-insulter

将下载的文件移动到文件夹 /etc 下。

$ sudo cp bash-insulter/src/bash.command-not-found /etc/

将下面的代码添加到 /etc/bash.bashrc 文件中。

$ vi /etc/bash.bashrc

#Bash Insulter
if [ -f /etc/bash.command-not-found ]; then
 . /etc/bash.command-not-found
fi

运行以下命令使更改生效。

$ sudo source /etc/bash.bashrc

你想测试一下安装是否生效吗?你可以试试在终端上输入一些错误的命令,看看它如何嘲讽你。

$ unam -a

$ pin 2daygeek.com

如果你想附加你自己的短语,则导航到以下文件并更新它。你可以在 messages 部分中添加短语。

# vi /etc/bash.command-not-found

print_message () {

    local messages
    local message

    messages=(
        "Boooo!"
        "Don't you know anything?"
        "RTFM!"
        "Haha, n00b!"
        "Wow! That was impressively wrong!"
        "Pathetic"
        "The worst one today!"
        "n00b alert!"
        "Your application for reduced salary has been sent!"
        "lol"
        "u suk"
        "lol... plz"
        "plz uninstall"
        "And the Darwin Award goes to.... ${USER}!"
        "ERROR_INCOMPETENT_USER"
        "Incompetence is also a form of competence"
        "Bad."
        "Fake it till you make it!"
        "What is this...? Amateur hour!?"
        "Come on! You can do it!"
        "Nice try."
        "What if... you type an actual command the next time!"
        "What if I told you... it is possible to type valid commands."
        "Y u no speak computer???"
        "This is not Windows"
        "Perhaps you should leave the command line alone..."
        "Please step away from the keyboard!"
        "error code: 1D10T"
        "ACHTUNG! ALLES TURISTEN UND NONTEKNISCHEN LOOKENPEEPERS! DAS KOMPUTERMASCHINE IST NICHT FÜR DER GEFINGERPOKEN UND MITTENGRABEN! ODERWISE IST EASY TO SCHNAPPEN DER SPRINGENWERK, BLOWENFUSEN UND POPPENCORKEN MIT SPITZENSPARKEN. IST NICHT FÜR GEWERKEN BEI DUMMKOPFEN. DER RUBBERNECKEN SIGHTSEEREN KEEPEN DAS COTTONPICKEN HÄNDER IN DAS POCKETS MUSS. ZO RELAXEN UND WATSCHEN DER BLINKENLICHTEN."
        "Pro tip: type a valid command!"
        "Go outside."
        "This is not a search engine."
        "(╯°□°)╯︵ ┻━┻"
        "¯\_(ツ)_/¯"
        "So, I'm just going to go ahead and run rm -rf / for you."
        "Why are you so stupid?!"
        "Perhaps computers is not for you..."
        "Why are you doing this to me?!"
        "Don't you have anything better to do?!"
        "I am _seriously_ considering 'rm -rf /'-ing myself..."
        "This is why you get to see your children only once a month."
        "This is why nobody likes you."
        "Are you even trying?!"
        "Try using your brain the next time!"
        "My keyboard is not a touch screen!"
        "Commands, random gibberish, who cares!"
        "Typing incorrect commands, eh?"
        "Are you always this stupid or are you making a special effort today?!"
        "Dropped on your head as a baby, eh?"
        "Brains aren't everything. In your case they're nothing."
        "I don't know what makes you so stupid, but it really works."
        "You are not as bad as people say, you are much, much worse."
        "Two wrongs don't make a right, take your parents as an example."
        "You must have been born on a highway because that's where most accidents happen."
        "If what you don't know can't hurt you, you're invulnerable."
        "If ignorance is bliss, you must be the happiest person on earth."
        "You're proof that god has a sense of humor."
        "Keep trying, someday you'll do something intelligent!"
        "If shit was music, you'd be an orchestra."
        "How many times do I have to flush before you go away?"
    )

via: https://www.2daygeek.com/bash-insulter-insults-the-user-when-typing-wrong-command/

作者:Magesh Maruthamuthu 选题:lujun9972 译者:zero-mk 校对:wxy

本文由 LCTT 原创编译,Linux中国 荣誉推出

你可以通过配置 sudo 命令去嘲讽输入错误密码的用户。但是现在,当用户在 shell 输错命令时,就能嘲讽他了(滥用?)。

你好 bash-insulter

来自 Github 页面:

当用户键入错误命令,随机嘲讽。它使用了一个 bash4.x. 版本的全新内置错误处理函数,叫 command_not_found_handle

安装

键入下列 git 命令克隆一个仓库:

git clone https://github.com/hkbakke/bash-insulter.git bash-insulter

示例输出:

Cloning into 'bash-insulter'...
remote: Counting objects: 52, done.
remote: Compressing objects: 100% (49/49), done.
remote: Total 52 (delta 12), reused 12 (delta 2), pack-reused 0
Unpacking objects: 100% (52/52), done.

用文本编辑器,比如说使用 vi,编辑你的 ~/.bashrc 或者 /etc/bash.bashrc 文件:

$ vi ~/.bashrc

在其后追加这一行(具体了解请查看 if..else..fi 声明source 命令):

if [ -f $HOME/bash-insulter/src/bash.command-not-found ]; then
    source $HOME/bash-insulter/src/bash.command-not-found
fi

保存并关闭文件。重新登录,如果不想退出账号也可以手动运行它:

$ . $HOME/bash-insulter/src/bash.command-not-found

如何使用它?

尝试键入一些无效命令:

$ ifconfigs
$ dates

示例输出:

一个有趣的 bash 钩子功能,嘲讽输入了错误命令的你。

自定义

你需要编辑 $HOME/bash-insulter/src/bash.command-not-found

$ vi $HOME/bash-insulter/src/bash.command-not-found

示例代码:

command_not_found_handle () {
    local INSULTS=(
        "Boooo!"
        "Don't you know anything?"
        "RTFM!"
        "Hahaha, n00b!"
        "Wow! That was impressively wrong!"
        "What are you doing??"
        "Pathetic"
        "...and this is the best you can do??"
        "The worst one today!"
        "n00b alert!"
        "Your application for reduced salary has been sent!"
        "lol"
        "u suk"
        "lol... plz"
        "plz uninstall"
        "And the Darwin Award goes to.... ${USER}!"
        "ERROR_INCOMPETENT_USER"
        "Incompetence is also competence"
        "Bad."
        "Fake it till you make it!"
        "What is this...? Amateur hour!?"
        "Come on! You can do it!"
        "Nice try."
        "What if... you type an actual command the next time!"
        "What if I told you... it is possible to type valid commands."
        "Y u no speak computer???"
        "This is not Windows"
        "Perhaps you should leave the command line alone..."
        "Please step away from the keyboard!"
        "error code: 1D10T"
        "ACHTUNG! ALLES TURISTEN UND NONTEKNISCHEN LOOKENPEEPERS! DAS KOMPUTERMASCHINE IST NICHT FÜR DER GEFINGERPOKEN UND MITTENGRABEN! ODERWISE IST EASY TO SCHNAPPEN DER SPRINGENWERK, BLOWENFUSEN UND POPPENCORKEN MIT SPITZENSPARKEN. IST NICHT FÜR GEWERKEN BEI DUMMKOPFEN. DER RUBBERNECKEN SIGHTSEEREN KEEPEN DAS COTTONPICKEN HÄNDER IN DAS POCKETS MUSS. ZO RELAXEN UND WATSCHEN DER BLINKENLICHTEN."
        "Pro tip: type a valid command!"
    )

    # 设置“随机”种子发生器 
    RANDOM=$(date +%s%N)
    VALUE=$((${RANDOM}%2))

    if [[ ${VALUE} -lt 1 ]]; then
        printf "\n  $(tput bold)$(tput setaf 1)$(shuf -n 1 -e "${INSULTS[@]}")$(tput sgr0)\n\n"
    fi

    echo "-bash: $1: command not found"

    # 无效命令,常规返回已存在的代码
    return 127
}

赠品:sudo 嘲讽

编辑 sudoers 文件:

$ sudo visudo

追加下面这一行:

Defaults insults

或者像下面尾行增加一句嘲讽语:

Defaults !lecture,tty_tickets,!fqdn,insults

这是我的文件:

Defaults    env_reset
Defaults    mail_badpass
Defaults    secure_path = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
## If set, sudo will insult users when they enter an incorrect password. ##
Defaults    insults

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root ALL = (ALL:ALL) ALL

# Members of the admin group may gain root privileges
% admin ALL = (ALL) ALL   

# Allow members of group sudo to execute any command
% sudo ALL = (ALL:ALL) ALL   

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

试一试:

$ sudo -k # 清除缓存,从头开始
$ sudo ls /root/
$ sudo -i

样例对话:

当输入错误密码时,你会被一个有趣的的 sudo 嘲讽语戏弄。

赠品:你好 sl

sl 或是 UNIX 经典捣蛋软件 游戏。当你错误的把 ls 输入成 sl,将会有一辆蒸汽机车穿过你的屏幕。

$ sl

Linux / UNIX 桌面乐趣: 蒸汽机车


via: https://www.cyberciti.biz/howto/insult-linux-unix-bash-user-when-typing-wrong-command/

作者:Vivek Gite 译者:CYLeft 校对:wxy

本文由 LCTT 原创编译,Linux中国 荣誉推出