Wget, Vim and The Bash Insulter

DistroTube
233 followers
3 Video Views·Oct 25, 2024
have you ever wanted the bass hill to
insult you when you got a command wrong
well there are a lot of scripts out
there that will do just that they will
change your bass Hill to where it will
deliver an insult any time you make a
mistake but that's not really the main
purpose of this video I'm going to show
you one such bash insulter script but
because these scripts are so simple you
know they're really easy to hack on and
modify and I'm gonna show you how you
can modify these kinds of scripts to
your needs with commands like W get and
then with extensible editors like vim or
Emacs let's get started so the script
I'm gonna show you guys today is one
called bash insult er I've seen a few
articles written about bash in soldier
in the last few months I've seen this
particular script mentioned a few times
on various Linux related subgrid it so
it randomly insults the user when he
types a wrong command if you want to
look at the source if you ignore the
license and the readme it's really just
one little shell script that says print
message local messages and then you have
this messages array which is all the
various quotes the insults that it has
to choose from randomly to insult you so
it's not a very difficult script to
interpret if you guys are not familiar
with shell scripting I promise you you
can probably read that script and figure
out exactly what it's doing but say I
wanted to insult myself with more
insults than just what was in this
script because this script has I don't
know 50 60 insults some of them are
actually kind of stupid what if I wanted
to change it to my own kind of insults
or maybe I want to change it out to
where it's not insults at all maybe it's
famous quotes or something but I'm gonna
stick with the insults theme but I want
to change these insults to some bitter
insults so I came up with a couple of
different lists of insults that I
thought were really interesting really
neat and I thought kind of classy so I
did a quick google search for I think
list of insults or collection of insults
and of course you get a bunch of pages
and I found this one this is a list of
Luther's insults so for those of you
that are Lutheran or
or you know just Christian in general
these are some interesting little
insults for example this one here I am
tired of the pestilent voice of your
sirens you know I wouldn't mind if the
Bastille threw out some of these
Lutheran insults hit me every now and
then so I'm gonna try to add that to the
bash insulter and you know what another
one just to have a little more culture
here was a list of the Shakespearean
insults so I found this webpage of the
top 50 Shakespeare insults you know what
I wouldn't mind adding those to the bash
insulter so what's the best way to go
about adding the Shakespearean insults
and the Lutheran insults to the bash
young soldier well first let's bring up
a terminal and what you need to do is
you need to basically just download that
web page it's all you really need to do
and one of the command-line tools you
can use to do this is a tool called W
get W get and then a URL and it will go
and grab that webpage and download it so
I'm gonna go ahead and double you get
the Lutheran insult web page and then
I'm gonna double you get the
Shakespearean insult web page now once I
have those now I can open these nvm so
if I VM and let's start with the
Lutheran one so I will you know
insult - list PHP was what it named
itself when it downloaded this is that
PHP file that we just downloaded if I go
back to the browser for a second and go
back to the source code for the bash
insulter script you see for these
insults to be in the array the message
is array they simply need to be it looks
like they need to be indented about
eight spaces over and then wrapped and
double quotes so that's all we really
need to know let me get back to the
terminal so the reason I open this in VO
more I could open this in do me max
which uses the film modes and key
bindings it really didn't matter which
one I chose for this me jiejie to get to
the top of the page the reason I'm gonna
do this is because it makes editing a
really crazy file like this PHP file a
lot easier because I can use
substitutions search owner of plays I
can use macros to really edit this file
in such a way that I can just plug it
into that
script so the first thing I want to do
is I'm gonna shift V to get into visual
mode and I am gonna get rid of the first
few lines here because quite frankly we
don't need them then I'm going to record
a macro to record a macro in them or in
Emacs if it uses the evil mode you do Q
to record a macro and then the letter
you want to assign that macro I'll name
it far for purposes of this so it says
recording at R now everything I do from
here on Gilman's recording here is what
I want this macro to do I want to do a
slash first search and then I want it to
search for p class equals large and you
see it goes to that line i hit enter and
then when it gets this line i want it to
shift v to get into visual mode and i
want it to go down that many times i
want it to delete then i want to escape
and then hit cue to kill the macro i'm
gonna run this macro i don't know how
many times i need to run it i'm gonna
run it a hundred times so i'm gonna do a
hundred at far all right and i'm
assuming it finished doing what it's
doing so if i go back to the top you
know already we cleaned up this document
a little bit because it got rid of
basically some of the headings is what
we just deleted so if i went back to
that lutheran page here
basically we got rid of that line that
line you know every time there's a new
subsection the headings I'm not gonna
need that so that's what we just got rid
of there with the bill macros now let's
get rid of some other stuff so I'm gonna
cue to record a macro again this time
I'll set it to the letter e so let's
recording now what I want to do is I
want to search for the ending T body tag
now because the t body the ending T body
tag has a slash we need to escape that
character so first do forward slash then
/t body you don't do that
you're it's not going to work correctly
for you then hit enter to get to that
line and then what I want to do I want
to do a 3d D to delete three lines and
then I'm gonna escape you to kill the
macro and then I'm gonna run that that
did what I wanted it to do cleaned up
the document a little bit more and I
could keep doing these macros you know
if I wanted to I could just hit Q and
then Q again and now I'm recording a Q
macro what I'm gonna do now is this time
I want to search for every TR tag gonna
hit enter and when I find this I want to
do a to D D to delete two lines I'm
gonna hit Q to kill the macro now I'm
gonna run that macro 100 at Q and again
we just keep deleting extra stuff you
can already see we are almost there we
have cleaned this document up really
nicely the only thing I need to do now I
need to do a search and replace I want
to replace the opening TD tags with a
quote and then I want to replace the
closing TD tags obviously with a quote
and then all I need to do a simple
search and replace to get rid of the
closing TR tags that are still here so
to do this search and replace what I'm
gonna do is I'm gonna do a percent yes I
want this to replace this every instance
that it happens in the document and then
do a slash what do I want to replace I
want to replace that opening TD tag you
know that every line has then a slash
again what do I want to replace the TD
tag with well I want to replace it with
a double quote and then another slash
and then G and then hit enter and it
says 432 substitutions were made so
there were a lot of TD
in this document some of them were
probably extra stuff if I go to the
bottom of the document you know you
still a lot of HTML that I'm not gonna
use but that's fine and that that's an
easy thing to delete at the end and then
the next thing I need to do I'm gonna do
: and I'm just gonna hit up arrow
because I'm gonna basically run that
same command but I'm gonna do the
closing TD tag now we remembered to
escape that slash now hit enter and it
got rid of four hundred and thirty two
instances of closing TD tags gg back to
the top of the document and really you
guys can already see the last thing to
do is just to get rid of the closing TR
tags so just gonna get rid of TR what am
I gonna replace it with I'm gonna
replace it with nothing and then one
more time I'm gonna go ahead and do the
opening TR tags because it looks like
there were a few of those still left
here GG to get back to the top now we
need to correct the spacing so I'm gonna
get back to the very first line here I'm
gonna go to the beginning of the line
and I'm gonna do ctrl V which is the
visual block mode and then I'm gonna
ctrl G let's go all the way to the
bottom so basically I just chose the
empty space that is in front of every
line and it's a pretty big chunk of
spaces more than I need but for sake of
this video really what I want to do is I
just wanted to delete all of that empty
space so I'm just gonna hit deep and now
GG back to the top of the document and
you can see I got rid of that space in
front of every line now I'm gonna run
this command to actually put the spacing
exactly right because in that bash
script if I go back to the best script
you can see that that array has eight
spaces in front of the line so that's
what we need to do we need to put eight
spaces in front of every line and this
is really easy to do in film just ctrl V
again at the top to get into visual
block mode I'm gonna capital G to go all
the way to the last line to choose every
line and then let's get into command
mode so hit colon colon and then you got
single quote less than sign comma single
quote greater than sign now what does
that mean it means we are gonna run this
command on the lines that are selected
in this case every supply n-- you didn't
actually have to
that at least nothing in my film it just
automatically puts that in there for you
so you don't have to worry about
remembering the single quote greater
than less then thing do a space and then
type the word norm and we're telling
them here to run this command I'm about
to do in normal mode and the command I
want it to run it is capital i capital i
gets you into insert mode and goes to
the beginning of the line and then what
do you want to do after it runs capital
I will I want it to space and I want it
to space eight times so one two three
four five six seven eight hit enter and
we just put eight spaces in front of
every line now we're good we're done
with the Lutheran insults we can just go
and plug that into the source code for
that bash script it can just go in the
messages array just like all these
messages that were already here how cool
is that and we can do the same with the
Shakespearean insults as we'll so I just
opened the Shakespearean insult page
that we pulled down with W get and this
is a massive page it is 2066 lines the
good thing is we only need about a
hundred lines out of this page so most
of it is just gonna be deleted just easy
delete so on line 587 it's where I need
to start someone to shift V to get back
into visual mode G G to go to the top of
the document D to delete those first 587
lines I'm not gonna need them and then
there's really only about a hundred
lines or so of these quotes and then the
rest of it I don't need so once I get to
the last quote here I'm gonna shift V to
get into visual mode capital G to go to
the last line of the document D to
delete all that we just got rid of about
thirteen hundred and seventy five lines
with that last command and about five
hundred lines with the first command so
that two thousand line document now is
much more manageable and you can see
actually this one will be a little
easier to do the substitutions and the
macros and get this cleaned up a lot
easier than the lutheran list was
actually and you know through the magic
of video editing you guys didn't have to
watch me run those substitutions and
macros the second time but this is the
list he
year of the Shakespearean insults the
only thing I haven't done as of course I
haven't added the spacings Oh control V
to get into visual block mode capital G
to go to the bottom of the document
remember : of course get you in command
mode in film and automatically it enters
the first five characters that you
needed to type there you're good they're
spaced norm because you want to do this
in normal mode run the command capital I
which gets you into insert mode brings
you to the beginning of each line and
then what do you want to do at once
you're at the beginning of each line you
want to space over 1 2 3 4 5 6 7 8 times
hit enter boom we're done with both
lists let's plug them into the bash
insulter script I'm going to write and
click and of course to plug these into
the bash consultor script we actually
need to go get the bash and software
script so let me go back to the bash
insulter getup page installing it is
dead simple you just need to run two
commands really so first things we need
to do is we need to go ahead and get
clone that script so now the script is
on our system we need to copy that
script over to slash Etsy of course we
have to give no sudo privileges to copy
over to the slash Etsy directory and
then we need to source that list of
insults so in film I'm just gonna source
it locally on my home users bash RC
Capital G to go to the bottom of the
document and I to get into insert mode
and I'm just gonna do a quick pace and I
just need to add those three lines there
I will make a comment actually just for
myself here I'm going to say bash
insulter escape right and quit and then
let's start another bash and see if I
type a wrong command will it actually do
something so instead of echo it spelled
correctly let's do echo not spill
correctly okay and it does it didn't do
it on the first one that did it on the
second one and doesn't do it every time
I know why it doesn't do it every time
though a checking the source code for
this so let me open up the source code
for bash insulter here in them of course
you get your array at the top with all
the messages
but then right after it you know how it
actually loads the commands at pixel at
random but it also at random intervals
its does not actually load an insult and
you see he left a comment in the script
it prints a randomly selected message
but only about half the time to annoyed
the user a little bit less and so I
guess a lot of people don't want to be
insulted every single time they do a
wrong command so it only does it about
half the time so pretty cool now of
course that's the default insults let's
go ahead and plug in our Lutheran
insults and our Shakespearean insults
what I'm gonna do is I'm gonna run the
same VM command I just ran by doing
exclamation film because the last
command I used VM with of course was
opening the source code for the bash and
soldier now the simple way to just add
your messages whatever it is you're
wanting to add it's just plug it in to
the messages array but I'm gonna do
something a little bit different here
because maybe I don't want to keep the
Lutheran insults all the time or the
Shakespearean insults all the time maybe
I want to mix and match various styles
of insults occasionally so I won't
separate arrays for all the various
kinds of insults so I'm gonna delete
messages here I'm gonna CW to change
word and I'm gonna do declare - a grey
one we're gonna change this we're gonna
call it array 1 and why are we gonna do
that
hit escape the reason we're gonna do
this because I'm gonna create a couple
of more arrays let's get to the bottom
of array 1 that was the end of that list
I'm gonna get back into insert mode here
and space over and then I'm going to
declare - a array 2 equals parentheses
we need to have a closing parenthesis of
course you know scape and let's go ahead
while we're here and do the third array
all right so now we have three different
arrays a GG to get back to the top
though remember that this thing is going
to search for an array called messages
messages doesn't exist anymore we have
array 1 or a 2 or a 3 so here passed
array 3 we're gonna go ahead and create
this new messages equals and then
parentheses array 1 or a 2 or a 3
course get it do the ending parentheses
and basically what when I just did here
is messages the messages array now is
actually a combination of three
different arrays I want you to get
everything from Ray one everything from
array two and everything from array
three and that is now the messages array
and that's what it's going to choose as
far as insults at random it's going to
choose from all three arrays then I just
need to plug in the Lutheran insults
into a ray tube and the Shakespearean
insults into array three so I plug in
what I wanted to plug in here so again
we got the array at the top which would
suggest the default messages that came
with the script and then I've got array
two and this is where I plugged in the
Lutheran insults and then I've got array
three right here that is where I plug in
the Shakespearean insults and then of
course after array three we have this
line messages equals all three arrays
now let me write and quit and clear the
screen here and the thing we need to do
now is if we go back to the web browser
remember to install the bash and soldier
we needed to run this command here where
we copy over the source over to slash
Etsy since I changed the source I added
the Lutheran insults and the
Shakespearean insults we need to copy
the new file to slash Etsy rewrite the
open now let me start another instance
of bash and now let me start typing
wrong commands echo echo not found of
course randomly it will insult you
randomly it will not remember that's
part of the script thou art as fat as
butter I'm pretty sure that came from
the Shakespearean array that was array
three this is why you get to see your
children only once a month course that's
the first array oh you wolf in
Christendom that's probably the lutheran
array so very cool it's working I know
it's kind of a bit of a random video
today but you know you guys sometimes
want to see how you go about hacking on
your sister playing with scripts and
things like that I came across the bash
in soldier the other day and I was gonna
put it on my system I was like you know
what if I'm gonna put it on my system
I should change it up a little bit and
if I'm gonna change it up I should
actually get it on camera exactly how
you go about this this kind of stuff
because I'm sure a lot of you guys
probably don't know about double you get
how you can just download a web page in
the terminal with W yet and then if
you're not using a extensible text
editor like either vilmer Emacs that you
know has the really great search and
replace functionality and the macros and
on all of that you know if you had to
edit especially that that really crazy
2,000 line page that I had to edit for
the Shakespearean insults you had to do
that in a standard text editor like G
edit or something like that it would
take you it might take you an hour to
get the result that it took me like two
minutes to get and I also need to thank
these guys before I go the show was made
possible by Chris DJ Donnie Dylan George
Kaplan 8 lambda Michael Mitchell armory
Rob Sean and Willie these guys they're
the producers of the show without these
guys this episode would not have been
possible shows also brought to you by
all those other names you're seeing on
the screen at the moment here these guys
they help support my work over on
patreon without these guys this channel
wouldn't be possible sincere thank you
to those guys if you'd like to support
the channel look for distro tube over on
patreon I promise you he's over there
all right guess peace
you
