# Using Kotlin Scripts and GitHub Copilot for Quick Command-Line Tasks

DevFeed: [Using Kotlin Scripts and GitHub Copilot for Quick Command-Line Tasks](<https://devfeed.tech/articles/supercharge-kscript-with-github-copilot-25278.md>)

Original publisher: [Read original article](<https://kau.sh/blog/kscript-copilot/>)

Author: Kaushik Gopal

Published: 2023-05-07T01:25:34Z

Content type: tutorial

Language: en

Sources: [Kaushik Gopal's Site](<https://devfeed.tech/sources/kaushik-gopal-s-site.md>)

Topics: [Kotlin](<https://devfeed.tech/topics/kotlin.md>), [GitHub Copilot](<https://devfeed.tech/topics/github-copilot.md>), [Scripting](<https://devfeed.tech/topics/scripting.md>), [Command-line interface](<https://devfeed.tech/topics/cli.md>), [Markdown](<https://devfeed.tech/topics/markdown.md>), [Scripting, bash](<https://devfeed.tech/topics/scripting-bash.md>)

Tags: [bash](<https://devfeed.tech/tags/bash.md>), [command-line](<https://devfeed.tech/tags/command-line.md>), [github](<https://devfeed.tech/tags/github.md>), [github-copilot](<https://devfeed.tech/tags/github-copilot.md>), [how-to](<https://devfeed.tech/tags/how-to.md>), [ide](<https://devfeed.tech/tags/ide.md>), [kotlin](<https://devfeed.tech/tags/kotlin.md>), [markdown](<https://devfeed.tech/tags/markdown.md>), [scripting](<https://devfeed.tech/tags/scripting.md>), [video](<https://devfeed.tech/tags/video.md>)

## AI overview

This tutorial presents Kotlin scripts as an alternative to Bash for command-line automation and demonstrates using GitHub Copilot to build a script that processes Markdown front matter. The author reports completing the example in less than 4½ minutes, including IDE autocomplete setup.

## Source excerpt

One of the gifts we got from Kotlin 1.3.70 was the ability to effortlessly run a kscript (Kotlin script) from the command line. All you need to do is add the suffix .main.kts. Seriously, this is all you need to do: brew install kotlin echo '#!/usr/bin/env kotlin' > hello-world.main.kts chmod +x hello.main.kts ./hello.main.kts # 💥 With this 0 friction setup, there's little reason for me to ever write a bash script again. I get to write my script in Kotlin -- a modern & beautiful language. But slap on Github Copilot and I think we've unlocked the holy grail of quick scripting. To prove my point, I recorded a video live coding a script tackling a moderately involved task. Here's what I wanted to do: Take a directory path as argument Make sure it's valid and has at least one .md (markdown) file in it Search the front matter for the "categories" array pluck all the categories from all the files de-duplicate, sort and print them out The entire thing took less than 4½ minutes. This is including me figuring out how to get autocomplete working in my IDE, restarting it etc. Sure I could try to wield a one-line command and do the same thing for this use case but it's so much nicer in Kotlin. If you're intrigued, feel free to checkout my github repo of kscripts. I try to tackle a variety of common use cases in there P.S: The text snippet I use in there kscript;; basically gives me a starter hello world template. Not cheating, I promise.