[Music]
So, every once in a while you need to go
into the terminal and print out a file.
And you don't want to actually have to
go into the file because then you can't
probably access your systems clipboard.
So, one of the reasons why I use cat
quite often actually is that I need to
go copy something from a particular
file. And in order to do that, I need to
not have to be in Vim because I don't
have the systemwide clipboard available
to myself in Vim. So CAT is the way that
I do that. Now, the problem with CAT is
that it's just kind of plain. It doesn't
actually
look and feel functional other than just
listing things out. Everything is the
same color. Things just kind of get
printed out. If you're in a long file,
you actually have to have scrollback
enabled in your terminal in order to see
everything. and unless you pipe it
through something like less and it's
just not a very functional program
beyond the simple thing that it does
which is just print out a file. Now if
you're clever you can do a whole bunch
of stuff with with cat in order to
actually make it better but there are
alternatives and the one we want to talk
about today is called bat. Now I would
have called it dog but you know whatever
I'm just silly that way. So, bat is
basically cat but with color and some
extra features to make it more useful.
So, that's what we're going to take a
look at today. Let's go ahead and jump
in. But before we do, if you leave a
thumbs up on this video, I'd really
appreciate it. It'd really help the
channel. So, let's go ahead and take a
look at my terminal. We're in my blog
post directory because we're going to do
some messing around with files and it's
just easier if I have a bunch of files
to work with. So, let's just take a look
at what BAT looks like. So, let's bat
out
one file. And this is what BAT looks
like without any options whatsoever.
Now, if I were to use cat to do the same
thing. You can see it's in this section,
but I have to scroll up. It's all part
of the terminal. There's no fanciness
there. Now, fanciness isn't always a
good thing. Sometimes simplicity is
better, but some of that fanciness,
quote unquote fanciness, can add
functionality. So if we go back and look
at the bat again, it's not actually part
of the terminal. It's actually more of a
lesslike environment. So if you've ever
used less before, you'll know that it
allows you to view longer files with the
ability to basically use your Vim key
bindings to get back through them. Now,
you can also do things like search. So
if I wanted to search for something like
the word thing, it would show me all the
instances of the word thing in this
file. You can't really do that with cat.
You have to go into vim or use gp or
something like that, you know. So, if I
if I wanted to do the same thing with
cat, I would have to do cat like so and
then pipe that into gp and type thing
like so. And it show me all the
sentences that have the words thing in.
It's not going to just point me towards
the word. It's just going to use the
sentences that have thing in it or the
lines I suppose is what we're looking
for there. So, it's not nearly as
useful. It's doing the same thing. it's
just not doing it as efficiently or as
good. So bat at its very simple layer
just makes thing makes cat more useful
because it allows you to do things like
search flow through long documents with
your vim motions and all that kind of
stuff. But it does actually more than
that. You can customize this thing
however you want. There's loads of
different ways. So let's actually just
look at the man page here. The man page
has all the options that you could
possibly want. And the one I'm going to
look at right now is actually -p. So if
I do the exact same I did thing I did
earlier and just do -p like so. You're
going to see I get the same thing but
without all of the UI elements. So
there's no line numbers, none of the
other stuff. And the reason why I think
this is important is because if I were
into just the regular bat without the P
and then I wanted to try to copy and
paste something like that, I'm going to
get the line numbers too. So I don't
want I actually don't want that. I want
the plain version which I can then just
copy like this without getting anything
extra which is cool. You can also use
bat to highlight certain areas of the
file. So if I go up over here and use
the flag capital H and then give it a
line range. So like uh 10 to 15. So
that's 10 colon 20 I I guess we'll do
that. It basically will just highlight
in another color and you can specify the
color the those particular lines. We got
line 10 through line 20 which is down
here. So all of these here are are
highlighted. It's a it's a very kind of
weak highlight in this case cuz it's
using terminal colors but you can kind
of see how those are highlighted. It
would be good for if you wanted to
showcase something to someone else.
Let's say, for example, you're making a
YouTube video and you wanted to
highlight a certain range and you didn't
want to have to go with your mouse and
highlight things like this. You could
highlight just the specific lines you
wanted with that itself. Another thing
you can actually do with that same kind
of functionality is using the R flag.
And that's just going to allow you to
print just a range of lines. So, if I
just do this, it's just going to print
the range of lines from 10 to 20. So if
I wanted to showcase just that one line,
one section of lines or I know that's
all I needed. And of course you can use
that in conjunction with other things
too. So if you don't want the extraneous
UI elements like the file name and the
line numbers, just do P and then that
will just show you the 20 lines or the
10 lines that we've selected without any
of the other stuff. So that's cool as
well. Now, so another thing that this is
really cool to do is if I go and use
bat-dflake.nix,
we're in a different folder now.
Obviously, it's going to show me if
there are any differences from the last
time I did any uh a git commit to these
files. So, if I let me see if I can find
one in my repository that I've made a
change to. I'm not actually sure that
there is. So, if I do bat modules
binds.com, but instead use the dashd,
what it's going to do is show me just
the one line that has been changed since
the last time I pushed that to get. So,
if you just want to see the differences
that you have waiting to be staged, if
you're using a git repository, you can
do that as well. that's really really
cool and could be very useful if you're
just trying to figure out where the
changes are in a certain file and if you
need to go in and make any changes or
whatever. So that's really really nice.
Now BAT does have a configuration file.
So if we go into my BAT configuration
file which is config/bat,
you can actually generate this by doing
bat slash dash or d-generate
config file and that will generate this
config file. Now, there's not actually
all that much to this thing. There is a
ability to set the theme. So, if I want
to set this as Grubbox or whatever, you
can do that. There's quite a few themes.
I'll show you that here in a second. You
can change the way it displays ital
itallic text, whether or not it uses
paging or not. And you can change how it
showcases certain syntax or chooses what
syntax highlighting to follow. So, you
can do all that stuff from here. I think
if you look at the man page and their
documentation, you can do more permanent
settings from their configuration file,
but frankly, I just would prefer to use
the flags because I don't need the flag
the all the flags all the time. So, the
last thing I want to show you is this
here.
You can actually see that they allow you
to choose uh from a number of different
themes. So, there's probably about 20
themes there. Several very popular ones
like Dracula and GitHub and Monkey and
Grubbox are all here. So, if you want to
put this in your theming script or
whatever, you could theme that so it's
always showing the exact theme that you
want to show, which is right up my heart
and alley. So, it's just really really
good. I like being able to theme things.
That's that's that's very nice. Now,
there's a couple things regarding
languages and syntax highlighting. As
you can see, there's actually syntax
highlighting. That's one of the main
reasons why you'd want to use BAT, other
than the the less functionality. It
supports a ton of different languages.
So, if we do BAT-list
languages, it's going to showcase all
the languages that it supports. So,
things like CSS is here. Things like uh
C++, all the C stuff is here. Things
like Apple script if you're, you know,
doing Apple script for some reason on
Linux. Of course, you could use this on
Mac, too, as well, I believe. Things
like Haskell's here. here. So, there's
just a ton of different languages. Like,
if we scroll down this this file,
there's a ton of languages that it
supports. Probably every one that you
could expect to be here is here. Even
things like SCSS is here, which is which
is interesting. So, it does support bash
as well. So, if you using a bash script.
So, basically every language that you
can think of is here. But if you do find
a language that isn't supported, that
does support the sublime language
format. So you can add in new languages
if you need to. I personally don't think
that you'll ever come across that
situation because there just they just
support so many, but just in case you
can do that. So you can also
install other themes. I should have
mentioned that earlier. You can do that
into a themes directory inside your BAT
directory. So speaking of languages, you
can also specify what language the file
is going to look at. So, say for
example, you're looking at a file that
doesn't have an extension and you want
to still specify what syntax
highlighting to use. You can use the -l
flag to specify what language the file
is written in if it doesn't have an
extension. So, that's basically that. I
would highly recommend going into the
man page cuz there's a whole bunch of
options here that I didn't talk about
like being able to control the wrap,
control the numbers individually without
having to turn everything off. Change
the highlight colors of the the
highlighting that we use we looked at.
Change which pager it actually uses.
Sometimes it you will use by default it
will use less but there are a couple
other options. You can also do a whole
bunch of other stuff to customize how it
looks, how it functions, all sorts of
that stuff. And I think believe and I
believe most of the stuff can also be
put in the configuration file if you
want to use those as permanent options.
So that is BAT. There's not much more to
it. I really do think that this is one
of those applications that I'm just
going to alias to cat. So I'm used to
using cat, but I want to use bat. So
I'll put that in as an alias and just
use bat all the time. I will probably
use it without the line numbers to be
honest with you because most of the time
when I'm doing this, I want to be able
to copy and paste something without
having to worry about grabbing the line
numbers too. But other than that, this
is a very, very good application,
especially if you use CAT all the time.
This adds in a whole bunch of extra
functionality that cat either doesn't
have or would be a pain to set up in
CAT. So, I truly do believe that this is
a fantastic application and everybody
should give it a try. If they're in the
terminal and they use this thing all the
time. So, that's it for this one. If you
have any thoughts on this, you can leave
those in the comment section below. I'd
love to hear from you. You can follow me
on Macedon or Odyssey. Those links will
be in the video description. You can
support me on Patreon at
patreon.com/theinxcast.
Uh those of you who do support me on
Patreon, YouTube and Kofi get access to
an exclusive weekly podcast that I
basically post just me sitting in front
of a microphone for about 15 minutes
just rambling on about nothing. So if
you're if you're interested in me
rambling about random topics, head on
over there, give me some support. It's
available at all levels. Or you can head
over to the shop which is available at
shop.theinxcast.org.
There you'll find hats like this one. So
you can get a Linux nerd hat and be a
Linux nerd. or you can find shirts and
other kind of hats and backpacks and all
sorts of stuff. All the proceeds from
the store go directly towards helping me
make more links content for you guys.
And perhaps I if you support me enough,
I'll remember not to hit the microphone
when I'm just stickulating with my hands
for whatever reason that's likely to
happen. Anyways, that's it for this one.
Thanks to everybody who does support me
and Patreon and YouTube. You guys are
all absolutely amazing. Without you, the
channel just would not be anywhere near
where it is right now. So, thank you so
very, very much for your support. I
truly do appreciate it. Just seriously,
thank you so very much. I hope everyone
has a wonderful day or night or whatever
happens to be for you and I'll see you
next time.