Loading
Conversation 14 exercises
lesson

Use CLI Tools from a Script

We can use grep to search for the file we want to open based on its contents.

The code to add the search functionality is a bit long, so you can [view it on GitHub](https://github.com/johnlindquist/kit-ai-conversation/blob/ae47c14e8496141f0e0f5b792ad1dfe05f8adc1d/scripts/continue-adventure.ts#L34-

Loading lesson

Transcript

00:00 Now because we are looking through text files we can use grep to search for it as well. So let us paste in this option that you could copy and use, where the arg prompt can take the current input. You can grep against that, which will give you a big old string and you can split on those new lines. And then in the preview you can match the input against the contents of a line. So now searching in this script will give us some more information.

00:24 I'll type keyboard and you'll see keyboard show up in the highlighting, or if I go back and I type parachute you'll see it'll start highlighting parachute. And if you wanted to grep against files across your system when generating the array of file names you could use a library like globby to generate a huge array of file names rather than having to do it all manually. And finally if this is feeling a little cramped because you're looking at a large body of text, you can configure your prompt options in here where the placeholder will be choose a story, and the height can be 1 of the options of prompt height, and we'll pick like 5xl. And now when we run this you'll see we get a nice large layout to be able to read and see all of the matches. Then when you hit enter it'll drop back into chat and you get this great experience.