 I've been doing a lot more shell scripting here in the last few weeks, more than I typically do, and one of the things that I've really enjoyed is doing these shell scripts that involve Dmenu or Rofi as far as command launchers, because they're very useful. You can output anything you want in Dmenu, of course, and, you know, I had a problem the other day I wanted to solve. I wanted the ability to search through my web browsers, bookmarks, and history, and have that output into Dmenu so I could search, you know, through that stuff in Dmenu. And this is very easy to do because your web browsers, they're storing these bookmarks and your history, they're typically storing them in plain text files anyway, the history they're probably storing in a database because, you know, your web browser's history can sometimes be several thousand lines long, but that's still fine too because that database will be searchable. So what I wanted to do was I wanted to create a really simple shell script to be able to search through. In my case, I wanted to be able to search through cute browsers, bookmarks, and history. So let me switch over to my desktop here and this is cute browser and cute browser really saves three different kinds of URL history information. They save your bookmarks, they save quick marks, and they also save the history itself. Now bookmarks, you guys know what bookmarks are. They're just sites you've visited and you may eventually need to come back to that information. So you bookmark it. A quick mark is slightly different. A quick mark is like a bookmark, but you also assign it a hotkey. For example, because I go to my get lab all the time I have it set as a quick mark rather than a bookmark. So I can type O here in cute browser for open and I can search through my bookmarks, but I know I have my get lab actually set to this quick mark here. I just need to type O and then the word lab and hit enter. And that's a quick mark. If I type O again, you will actually see when I start typing lab, I have quick marks that gives me the URL and the quick mark itself is lab bookmarks. I don't have any bookmarks that involve the word lab. And then the history I've been to get lab several times in the history, apparently. So that is what's going on there. So we have quick marks, bookmarks and history and cute browser stores them all in plain text files on your system. So let me launch do me max here because that's my text editor of choice these days. And let me get into my D menu scripts directory and the script that I've been working on. I named it dm cute because it's mainly for cute browser, although eventually I may work on a script that's browser independent because maybe instead of using the existing cute browser configs, you know, where it stores your bookmarks and quick marks in history. Maybe I start managing them in my own configs independently. That way I can use them with whatever browser I choose. But for right now, I'm just going to use the existing cute browser config files, you know, the plain text files where cute browser stores its information. So I'm going to talk you guys through this very easy to read script here and tell you exactly what I did here. The very first thing I needed to do is I needed to define three variables. And these variables are the locations to where cute browser stores its bookmarks, its quick marks and its history database. So the bookmark file, I called it BM file is typically stored in dot config slash cute browser slash bookmark slash URLs, it's a plain text file called URLs, the quick marks file, which I called QB file for some reason, I don't know why I didn't call it QM file, but maybe I'll change the name of it and do a push after the video. But that is typically located at dot config slash cute browser slash quick marks. Once again, just a plain text file called quick marks. The history database is stored in a SQL database, it's actually a SQLite database, and it is actually stored not in dot config, it is stored in dot local slash share slash cute browser slash and then the name of the database history dot SQLite. And then there was a fourth variable I defined here, I called it separator and it's just, I don't know, eight or 10 dashes here, because what I want to do is when I open this in D menu, I want it to load the quick marks and then a separator, then the bookmarks, then a separator and then the history. Why do I want to do that? Well, it just seemed like the right thing to do because that's kind of what happens in cute browser itself. If I hit O for open, it's going to give me quick marks first and then bookmarks and then history. I was just trying to keep the same format in D menu as if I was searching in cute browser itself, so it was just for consistency's sake. So now that we have all these variables defined, the next thing we needed to do is start creating some arrays of the information contained in these files. So I have read array dash T, B marks, because that's going to be the name of this array, I just named it B marks. It could be named anything and the array is going to contain all the information from BM file. So you see BM file and then the right or the left pointing Chevron there, we're taking that information and sending it into the array basically is what that means. Let me get into a terminal here and what I'm going to do is I'm going to actually show you the format that the URLs are in. So let me zoom in here in a Lackardy and what I'm going to do is I'm going to cat out that URLs file. So .config slash cute browser slash bookmark slash URLs and you can see the format it is in. It is in URL followed by a space followed by the title of the page. So that is the standard bookmark format there. So that is very easy to work with because really the most important part is the URL and it's already the first field, the first column and then everything after that will be part of a title or description and it doesn't matter the spaces, however many spaces are after it because we're just going to take the first field and then everything after it will just be a field by itself. So that is a very easy file to work with with something like all for example. So that was the bookmarks file. The quick marks file is in a slightly different format, which makes things a little trickier when we're going to output everything all together in a menu. But if I cat out the quick marks, you see it has the quick mark itself, which is basically your hotkey. For example, DT is the hotkey for distrotube.com. So if I hit O inside Q browser and then DT, it'll take me to that web page. Let me show you. So O DT hit enter. So DT in this case on that line is the quick mark and then the URL is the second column. So there's only two columns in this, but unfortunately it's not in the same order as the URLs file appears. So now the URL for the quick marks is the second column rather than the first. So we're going to have to take that into account here in a second. And then to make matters worse, the history stuff is in a database. Remember it's in an SQLite database and it is in a different format than either of the URLs and the quick marks. So if I start typing SQLite3 here in the fish shell, thankfully, it'll remember the last time I ran this command because I can't remember exactly what I searched for. Let me clear the screen here so you guys can see the command. Let me up arrow. So SQLite3, I'm having it read this database, the Q browser history dot SQLite database. And I'm asking it to pull URL and title from history. So these are tables within the database. And if I run that command, let me run that command so you guys can see the output again. The output is the URL first, which is great. That's what we want. And then the problem is there is a pipe symbol next. And then we get the title. So URL, pipe symbol, and then the title. And the title is going to have some spaces. ALK typically works with spaces, but we can specify ALK to treat the pipe symbol as a separator. So this is actually pretty easy to work with in ALK. But we're going to have to format the bookmarks, the quickmarks, and the history database, all three of them differently. So let me close the terminal. And now that we've seen that, so I've got these arrays. I created the bookmark file array, the b-marks array, and then the q-marks arrays for the quickmarks. It's just taking the qb file that we defined up here. And it's piping that into an array. And then what we're doing is then I create this variable here, bm-list. So this is our bookmark list. What's that doing? That is taking the b-marks array we created, piping it into ALK and printing the second column first, followed by a dash, and then printing the first column. So let me show you this script. And that's the quickmarks. Let me scroll down past the separator. That is the bookmarks. And this is the format that I specified with ALK. We get the title, dash, URL. Title, dash, URL. And I want that to be the case for quickmarks, bookmarks, and the history. I always want title or, in the quickmarks case, just the quickmark itself, dash, and then the URL will always be the second field. So then I create a qm-list, which is exactly like bm-list, except we are sorting the quickmarks rather than the bookmarks. And we're doing it slightly differently because, remember, the quickmarks and bookmarks, the order that everything was in was slightly different. This time, with the quickmarks, we're piping it through ALK and we're printing the first column first. The first column is the quickmark itself. And I wanted it to be wrapped in brackets. So just for visual purposes, so it will stand out. So if I actually run the script, you will see the quickmarks themselves are wrapped in brackets. Just visually, that stands out. Because with quickmarks, you're typically not searching. You're not going to start typing the URL or a title or anything. You just want the quickmark itself, like lab for my GitLab or DT for distrotube.com. So if I typed lab right now and hit Enter, kind of like I did in the browser itself earlier, you know, the same thing. It worked just like it would had I done, oh, lab here in Qt browser. So I really want them to be as close to identical as possible. And sorting them in the way I did helps that by having the quickmark being the very first thing searched, followed by a dash, followed by dollar sign, capital N, capital F, that means the last field. It's basically what that means. So first field dash and then last field. And then I'm also piping it through sort because the quickmarks are not sorted alphabetically themselves. So I want them to be sorted alphabetically. So I'm also piping that through sort. And then finally, we have a SQL here. So this variable SQL. And what does that equal? Well, we're selecting title and URL from history from the history database. And then we're printing it in this format here or piping it through all where the field separator is the pipe symbol. Remember, there was a weird pipe symbol that appeared in the database entries for the history. So we're saying when you find the pipe symbol, print the first field, which is the URL, followed by a dash, followed by the last field, which is everything after that pipe symbol. And if you wanna see what the history format looks like, if I scroll down past the bookmarks and the quickmarks, this is history stuff. So most of this is like search engine results from DuckDuckGo, YouTube and things like that. And you can see it's the title of the page dash followed by the URL. So all of these are either a quickmark or a title followed by a dash, followed by a URL. It doesn't matter if it's quickmark, bookmark, or history, they're all kind of in the same format. And really that's all of the script for the most part. The easy part is piping all of that into D menu. So I created this here choice, this variable. And what choice is, is what is my choice in D menu? Well, we're gonna print out the QM list, the quickmark list, followed by a separator, followed by the bookmark list, followed by a separator, followed by the history list. And then we're gonna pipe that of course into D menu. So quickmark list, separator, bookmark list, separator, history list. And if I open this, there's the quickmark list, followed by that separator that I defined earlier, followed by the bookmarks, followed by I went too fast, followed by one more separator, followed by of course the history list again. And finally, all I needed to do was create this simple if statement here. If our choice is the separator itself, because that's not a real URL. So I needed to have it just in case here, right? So if you choose the separator, then just open KubeBrowser with no other arguments, because KubeBrowser followed by 10 dashes, it's not gonna be a real argument, right? It's not a real URL. So if we accidentally choose the separator, just open up KubeBrowser, you know, the default homepage. Else if we choose anything other than the separator, then open KubeBrowser at the URL we chose. And of course it works because I can show you guys this in action. Let me actually close out my browser that I already had open. So this really stands out. So I'm gonna run the script here and let me make sure I'm on the correct screen so you guys get to see it. There we go. And say that I want to, I don't know, I mean I could start searching for anything here. I'm gonna search for the word Xmonad and go to the last page that I went to that involved the word Xmonad. And it was a search result. I was looking for Xmonad pass prompt for some reason, probably to fix the Xmonad config. You know, maybe I was getting an error or maybe I just wanted some options to play with. So I looked up Xmonad pass prompt in .go and that was part of the history. So that is how this file works. And again, I could do my key binding for that and I could, you know, DT and it should just open up distrotube.com here in KubeBrowser. A very, very simple file to work with, right? This is not complicated at all. The one thing I will say, I have pushed all of these scripts that you guys have seen on camera here in the last few weeks to my GitLab. And one of the cool things about me pushing all these scripts to GitLab is you guys have actually done some contributions as well. So let me type lab here in my script. I love the fact that the quick marks to work through D menu, just like they work inside KubeBrowser itself. But go to my GitLab over at GitLab.com slash DWT1 look for my DM scripts repository. And I've already had three or four people contribute. So people are checking out my scripts, they're finding errors or they're just contributing new code. And these scripts are actually starting to get fleshed out a little bit, right? I mean, some of these are already pretty useful scripts that search engine script that I created on camera the other day is really nice. I like it does everything I want it to do. And now the KubeBrowser script, I mean, you guys can do that with any browser you want. Find out wherever your browser stores its bookmark information and its history information. Or ideally you could probably just manage bookmarks yourself. What I would do is I would create plain text files on your system, call them bookmarks or quick marks. So you can actually create quick marks for any browser. Quick marks is a KubeBrowser thing, but it doesn't have to be. All you need to do is create a plain text file with some URLs and some key binding, you know, some quick hotkeys. They're quick marks, quick marks. And you could do that with any browser, you know, just manage those things yourself. And then, you know, with these shell scripts and these demon use scripts, you can have those things launch in any browser you prefer to use. The only thing that would be tough to be portable between web browsers, every web browser handles history itself, you know, in its own kind of database and its own kind of format, you can't really manage browser history yourself. As far as a portable file that you can take with you anywhere. So that would be a little tricky, but bookmarks and quick marks, I think I could probably make this script handle that regardless of browser. And before I go, I wanna thank a few special people. I wanna thank Absie Dallas, Gabe Lue, Mitchell, Allen, Akami, ArchFish by 30 Chuck, David. The other David, Dylan Gregory, Lewis, Paul Scott, Wes, and Willie, they are the producers of this episode without these guys. I don't know what I'd be doing right now. I mean, really, I wanna thank these guys. They are my highest tier patrons over on Patreon. I also wanna thank each and every one of these ladies and gentlemen as well. These are all my supporters over on Patreon because the DistroTube channel is sponsored by you guys, the community. I couldn't do what I do without you guys. So I do ask for your support, check out DistroTube over on Patreon. All right guys, peace. Why were there so many 4chan URLs in my history?