/[smecontribs]/rpms/bash-insulter/contribs9/bash.command-not-found
ViewVC logotype

Contents of /rpms/bash-insulter/contribs9/bash.command-not-found

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download)
Mon Nov 20 22:49:05 2017 UTC (6 years, 5 months ago) by jpp
Branch: MAIN
CVS Tags: bash-insulter-0_1_20171120-1_el6_sme, HEAD
* Mon Nov 20 2017 Jean-Philipe Pialasse <tests@pialasse.com> 0.1.20171120-1.sme
- initial release

1 print_insult () {
2 local insults
3 local selection
4
5 insults=(
6 "Boooo!"
7 "Don't you know anything?"
8 "RTFM!"
9 "Haha, n00b!"
10 "Wow! That was impressively wrong!"
11 "Pathetic"
12 "The worst one today!"
13 "n00b alert!"
14 "Your application for reduced salary has been sent!"
15 "lol"
16 "u suk"
17 "lol... plz"
18 "plz uninstall"
19 "And the Darwin Award goes to.... ${USER}!"
20 "ERROR_INCOMPETENT_USER"
21 "Incompetence is also a form of competence"
22 "Bad."
23 "Fake it till you make it!"
24 "What is this...? Amateur hour!?"
25 "Come on! You can do it!"
26 "Nice try."
27 "What if... you type an actual command the next time!"
28 "What if I told you... it is possible to type valid commands."
29 "Y u no speak computer???"
30 "This is not Windows"
31 "Perhaps you should leave the command line alone..."
32 "Please step away from the keyboard!"
33 "error code: 1D10T"
34 "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."
35 "Pro tip: type a valid command!"
36 "Go outside."
37 "This is not a search engine."
38 "(╯°□°)╯︵ ┻━┻"
39 "¯\_(ツ)_/¯"
40 "So, I'm just going to go ahead and run rm -rf / for you."
41 "Why are you so stupid?!"
42 "Perhaps computers is not for you..."
43 "Why are you doing this to me?!"
44 "Don't you have anything better to do?!"
45 "I am _seriously_ considering 'rm -rf /'-ing myself..."
46 "This is why you get to see your children only once a month."
47 "This is why nobody likes you."
48 "Are you even trying?!"
49 "Try using your brain the next time!"
50 "My keyboard is not a touch screen!"
51 "Commands, random gibberish, who cares!"
52 "Typing incorrect commands, eh?"
53 "Are you always this stupid or are you making a special effort today?!"
54 "Dropped on your head as a baby, eh?"
55 "Brains aren't everything. In your case they're nothing."
56 "I don't know what makes you so stupid, but it really works."
57 "You are not as bad as people say, you are much, much worse."
58 "Two wrongs don't make a right, take your parents as an example."
59 "You must have been born on a highway because that's where most accidents happen."
60 "If what you don't know can't hurt you, you're invulnerable."
61 "If ignorance is bliss, you must be the happiest person on earth."
62 "You're proof that god has a sense of humor."
63 "Keep trying, someday you'll do something intelligent!"
64 "If shit was music, you'd be an orchestra."
65 "How many times do I have to flush before you go away?"
66 )
67
68 # Seed "random" generator
69 RANDOM=$(date +%s%N)
70
71 # Only print the insults some of the time
72 selection=$((${RANDOM}%2))
73 if [[ ${selection} -lt 1 ]]; then
74 printf "\n $(tput bold)$(tput setaf 1)$(shuf -n 1 -e "${insults[@]}")$(tput sgr0)\n\n"
75 fi
76 }
77
78 function_exists () {
79 # Zsh returns 0 even on non existing functions with -F so use -f
80 declare -f $1 > /dev/null
81 return $?
82 }
83
84 #
85 # The idea below is to copy any existing handlers to another function
86 # name and insert the insulter in front of the old handler in the
87 # new handler. By default, neither bash or zsh has has a handler function
88 # defined, so the default behaviour is replicated.
89 #
90 # Also, ensure the handler is only copied once. If we do not ensure this
91 # the handler would add itself recursively if this file happens to be
92 # sourced multiple times in the same shell, resulting in a neverending
93 # stream of insults.
94 #
95
96 #
97 # Zsh
98 #
99 if function_exists command_not_found_handler; then
100 if ! function_exists orig_command_not_found_handler; then
101 eval "orig_$(declare -f command_not_found_handler)"
102 fi
103 else
104 orig_command_not_found_handler () {
105 echo "zsh: command not found: $1"
106 return 127
107 }
108 fi
109
110 command_not_found_handler () {
111 print_insult
112 orig_command_not_found_handler "$@"
113 }
114
115
116 #
117 # Bash
118 #
119 if function_exists command_not_found_handle; then
120 if ! function_exists orig_command_not_found_handle; then
121 eval "orig_$(declare -f command_not_found_handle)"
122 fi
123 else
124 orig_command_not_found_handle () {
125 echo "$0: $1: command not found"
126 return 127
127 }
128 fi
129
130 command_not_found_handle () {
131 print_insult
132 orig_command_not_found_handle "$@"
133 }

admin@koozali.org
ViewVC Help
Powered by ViewVC 1.2.1 RSS 2.0 feed