My best use of ChatGPT yet!

My best use of ChatGPT yet!

As a Full Stack developer at F?rd Kommunikasjon, I've been using ChatGPT for quite a while, even without knowing it. It started in the summer of 2022 when I subscribed for GitHubs CoPilot. It took some time for me to fully understand the power of the API, but after I knew how to trigger the help I needed, it all felt like superpowers.

Today I use ChatGPT every day. And today I needed a way of streamlining some of my workflow so I could focus more on my task rather all the hassle to start working externally on a site.

I work a lot with linux servers and the terminal. That also means that I work a lot with SSH, Tmux and Vim/Nvim. Until today I have done this in a tedious way by adding the host/customer account in my .ssh/config file and added the password with ssh-copy-id so I could easily connect with just the customeralias "ssh customeralias".

Today I asked Chat to create a script with the following request:

"Could you write a bash script that iterates all my ssh config hosts and gives me an option list. When choosing a host in the option list, I want the script to mount the host as a filesystem in my home folder ?"

The answer was of course:

Here is a sample bash script that iterates through all the hosts defined in your ~/.ssh/config file, presents them as a numbered list, and allows you to choose one to mount as a filesystem in your home folder

I soon realised that I had forgotten something. I rushed this, because of the excitement. I added some ideas to the request:

"Could you add to the host list that it shows which host is allready mounted and if i choose that, it will umount it"

And the reply was again a positive and polite one:

Sure, here's an updated version of the script that also checks which hosts are currently mounted and marks them as such in the list, and unmounts the selected host if it is already mounted

I got what I asked for, and the script worked fine. But again, some new features where needed. I noticed that it used a static username that I had to change in different places and that sshfs had no rights to create mountingpoints without a existing folder. So I asked again:

"I want you you to add user as a variable and create the mounting dir before mounting it"

And the answer was:

Here's an updated version of the script that uses a variable for the username and creates the mount directory if it doesn't already exist

Yeah! This is good, but I noticed that it had forgotten something ( yeah, it somethimes weight the words and sentences wrong and leave out some stuff sometimes. But I just let Chat know that, and it fixes it. This is the result, and it worked like a charm. All in all this took me about 15 minutes to create. If I had to write this from scratch, I'd probably use one hour or maybe two for the obvious reasons of reading up on bash syntax and even deciding how to structure it. That era is now long gone..

No alt text provided for this image

要查看或添加评论,请登录

社区洞察

其他会员也浏览了