10

My Gentoo Linux is compiled with the offensive USE flag enabled:

# sudo su -
Password: 
Hold it up to the light --- not a brain in sight!
Password: 

It is also possible to select fortunes based on the degree of offensiveness:

# fortune -o kernelcookies | cowsay -b
 _________________________________________ 
/ /* This is total bullshit: */           \
|                                         |
\ linux-2.6.6/drivers/video/sis/init301.c /
 ----------------------------------------- 
        \   ^__^
         \  (==)\_______
            (__)\       )\/\
                ||----w |
                ||     ||

Considering the list of flavored items1 provided in the link is short - and I personally don't use a molecular dynamics simulation package - is there any more of that sort of spice in the shell(s) in Linux generally (or UNIX)?


1- It's good to remember that cowsay can output any argument, not just fortunes, for instance the output of a command or script: cowsay -s $(script_in_path_or_command). Note -s is just for the cow's appearance here, see manpages.

  • apt-get moo and aptitude moo , aptitude moo -v , aptitude moo -vv and so on. but it's for Debian based. – Renan Vicente Mar 28 '14 at 20:51
  • @RenanVicente Note I use Gentoo. In my repo, the `moo` I have is dev-perl/Moo - Minimalist Object Orientation (with Moose compatiblity). Please be more precise. –  Mar 28 '14 at 20:56
  • 1
    There should be a special insult for every time you run `sudo su -`. Possibly it should just change the root password to `sudo -i`. – derobert Mar 28 '14 at 20:57
  • @illuminÉ `sudo -i` gives the root shell that you're using `sudo su -` to get. I was joking it should insult you for the roundabout way you're doing it. – derobert Mar 28 '14 at 21:55
  • @derobert Yes indeed it changes everytime...both commands. Thanks for explaining, I didn't know `sudo -i` was the same as `sudo su -`. Saves 1 char to type each time! –  Mar 28 '14 at 22:00
  • 1
    BTW, I thought of a way to do this in bash, using the same stunt I use to color the prompt based on exit code and also Ubuntu's command not found stuff... Will write up and post it once I get home. – derobert Mar 28 '14 at 22:06
  • 1
    Not too offensive, but in that kind of mood: `sl` - A steam locomotive runs across the screen if you type "sl" instead of "ls" – Ouki Mar 28 '14 at 23:55
  • @Ouki Sure, "offensive" is really about humor and flavor and, because of the possible confusion with ls here, it's also about something unexpected happening in the shell... I couldn't find `sl` on Gentoo but the source is [here](http://www.tkl.iis.u-tokyo.ac.jp/~toyoda/index_e.html). Cheers! –  Mar 29 '14 at 05:31
  • 1
    Well, I went to bed upon getting home so didn't get around to writing this until today... but posted as an answer. – derobert Mar 29 '14 at 19:02

2 Answers2

9

Ok, by using PS1 and command_not_found_handle, it's possible to have bash insult you:

anthony@Watt:~$ . /tmp/insult.sh 
anthony@Watt:~$ sl
bash: sl: command not found, incompetent spoony bard
anthony@Watt:~$ ls /wrong/path
ls: cannot access /wrong/path: No such file or directory
Learn to type, second-rate Horrified Heron.
anthony@Watt:~$ 

And here is /tmp/insult.sh that I sourced in above.

### Data ###
bash_insulter_sentences=(
    'Have you considered Windows, %s?\n'
    'Learn to type, %s.\n'
    'Fell asleep at the keyboard again, %s?\n'
    "Failure is common when you're a %s, isn't it?\n"
)

bash_insulter_subjects=(
    'spoony bard'           # we all played this, right?
    'extra-Warty Warthog'
    'Dazed Drake'
    'Fidgety Fawn'
    'Horrified Heron'       # etc.
)

bash_insulter_adjectives=(
    'incompetent ' # these have built-in spacing
    'inept '
    'second-rate '
    '' # chance of none
    ''
)

### Functions to generate insults ###
bash_insulter_random_element() {
    if [ ${BASH_VERSINFO[0]} -lt 4 ] || \
        [ ${BASH_VERSINFO[0]} -eq 4 -a ${BASH_VERSINFO[1]} -lt 3 ]; then
        # bash before 4.3 doesn't have -n
        eval "local var=(\"\${$1[@]}\")"
    else
        local -n var="$1"
    fi
    local len=${#var[@]}
    echo -n "${var[$RANDOM % len]}" # Slightly biased. Don't care.
}

bash_insulter_full_subject() {
    bash_insulter_random_element bash_insulter_adjectives
    bash_insulter_random_element bash_insulter_subjects
}

bash_insulter_do_insult() {
    printf "$(bash_insulter_random_element bash_insulter_sentences)" "$(bash_insulter_full_subject)"
}

### set up ###
command_not_found_handle() {
    echo "bash: $1: command not found, $(bash_insulter_full_subject)"
    return 127
}

PS1='`
    if [ 0 -ne $? -a 127 -ne $? ]; then
        bash_insulter_do_insult
    fi
    echo "\u@\h:\w\$ "; 
`'
derobert
  • 107,579
  • 20
  • 231
  • 279
  • @illuminÉ maybe you have an older version of bash, not sure when that feature was added. Does declare -n work? – derobert Mar 30 '14 at 01:56
  • I have 4.2.45(1)-release. It so happens I have tons of pkg to update. So I'll try this under Arch later! Thanks there, seems fun, I like the idea of mixing it up! Cheers! –  Mar 30 '14 at 02:20
  • @illuminÉ 4.3.0 here, how is it possible that Debian has a newer bash than Gentoo? Anyway, checking the NEWS file, it's a new feature in 4.3. I'll see about adding in a version that doesn't need the new feature. – derobert Mar 30 '14 at 02:50
  • @illuminÉ edited, will hopefully now work with bash 4.2. – derobert Mar 30 '14 at 03:06
  • Thank you, that's a blast really loll. Works great! But indeed Debian. I [checked](https://packages.gentoo.org/package/app-shells/bash) and indeed 4.3 hasn't made it yet. Oh, btw, I was more into Bard's tale lol. –  Mar 30 '14 at 03:17
  • Dear Torvalds this is *amazing*. – cat May 11 '16 at 12:27
2

Someone mentioned sl. In software like an interpreter which aims at maximum predictability, surprise certainly qualifies as something "offensive" in context. The manual also lists appropriate options:

DESCRIPTION
   sl  is a highly advanced animation program for curing your bad habit of
   mistyping.

   -a     An accident is occurring. People cry for help.

   -l     Little version

   -F     It flies like the galaxy express 999.

   -c     C51 appears instead of D51.

...and an interesting bug :

BUGS
   It sometimes list directory contents.