Show HN: Get answers for shell commands from GPT3 from your terminal (github.com)
I was constantly googling CLI commands so I built this small CLI tool with GPT3.
You can ask for shell commands right from the CLI.
You'd need to use your own API KEY for this but it's pretty simple, instructions are in the README Not perfect but not bad either.
96 comments
[ 2.8 ms ] story [ 207 ms ] threadUnless the action that I'm doing is destructive I just run the command (YOLO)
I show a warning after every command you run "Please don't run commands that you don't understand "especially destrictive ones")
So one time he got some code from the senior backend Java developer in Argentina and went to past it into the place he was told to paste it into for sending alert notifications to customers, some months later we are going through a major crisis because alerts have not been working for several months and all the customers who are paying thousands per month for the service are getting pissed.
He worked home a day he could really focus on debugging and finding what could possibly have caused our systems to fail!
I was done with some little task I was on and decided to look through code changes and it really stood out the code he had pasted because if it worked that would mean Java was some magic language with incredibly terse code.
So later on we were having a major emergency call to figure out what could possibly be causing this extremely serious major bug and I said well I was looking through the code and you could see him manfully controlling his exasperation because hey, Bryan is not a Java guy and there is zero chance I could have a meaningful contribution to the current problem.
But yes it turned out he had trustingly pasted in code that we all agreed would never have worked (without caring to basically even read it), which despite the fact that in many ways this guy was better than me is something I would never, ever have done because I am a really hyper-paranoid guy about trusting code.
Anyway tldr, I would never use this tool but maybe some really skillful people would because they don't have the paranoid mindset.
In practice it won't need to, somebody will make a plugin that uses it to download funny images or highlight code in console :)
If that’s reasonably stable and can produce more obscure commands (I’d love to see for example how it fares with more complex git usage) that’d be really great tool to have.
It's not like this is something that can be surmounted without extra storage, neural nets are just a fancy system for compression and data access. You can either go for less data or more compression but either way your results won't ever be as good.
^ https://www.warp.dev/
The example in the project readme is imo already a bad example.
Answer Apart from the facts that- I would say the chances that lsof is installed are significant smaller than ss or netstat
- is lsof notably slower than ss
it is also inferior for the requested task because
- it returns any process connecting to this port not only the listening one. Which process is running on port 443 on my desktop? None. How many processes does 'lsof -i tcp:443` return? 20.
- it does not work if the listening process is from another user (if lsof is not run by root). In this case lsof -i returns nothing while ss -nltp returns the information that the port is listened and only cannot tell by which process because of missing permissions.
My answer to "which process uses port x"
This is actually a question I'm now really curious what the AI would answer since there are so many different correct answers (apt? yum? zypper? pacman? xbps?) and no indication for the AI which is the correct one for the asking user.
PS: But thinking about it I might just ask the wrong questions. "How to install X on <distro>" should work.
But on the other hand I think the ultimate blame lies with Bash for being so shitily designed that you can make basic quoting mistakes and it works most of the time. Real programming languages don't have that issue.
> We don't actually use Java. We use Scala.
I love how vague and meaningless this is, yet I still feel like I've heard this sentence said unironically a hundred times.
Alas, the things that force it are also shit. Overall, it is an improvement.
Want real fun. touch -- --help # or similar. :)
> Command is `shred -u /path/to/file`
A bit of a mix up between safely/securely
People and AI seem to prefer assuming things.
Most of the time wrong things…
> 'Correctly answer the asked question. Return \'Sorry, Can\'t answer that.\' if the question isn\'t related to technology.\n\nQ - get into a docker container.\nA - `docker exec -it mongodb`\n\nQ - Check what\'s listening on a port.\nA - `lsof -i tcp:4000`\n\nQ - How to ssh into a server with a specific file.\nA - `ssh -i ~/.ssh/id_rsa user@127.0.0.1`\n\nQ - How to set relative line numbers in vim.\nA - `:set relativenumber`\n\nQ - How to create alias?\nA - `alias my_command="my_real_command"`\n\nQ - Tail docker logs.\nA - `docker logs -f mongodb`\n\nQ - Forward port in kubectl.\nA - `kubectl port-forward <pod_name> 8080:3000`\n\nQ - Check if a port is accessible.\nA - `nc -vz host port`\n\nQ - Reverse SSH Tunnel Syntax.\nA - `ssh -R <remote_port>:<local_host>:<local_port> <user>@<remote_host>`\n\nQ - Kill a process running on port 3000.\nA - `lsof -ti tcp:3000 | xargs kill`\n\nQ - Backup database from a mongodb container.\nA - `docker exec -it mongodb bash -c "mongoexport --db mongodb --collection collections --outdir backup"`\n\nQ - SSH Tunnel Remote Host port into a local port.\nA - `ssh -L <local_port>:<remote_host>:<remote_port> <user>@<remote_host>`\n\nQ - Copy local file to S3.\nA - `aws s3 cp <local_file> s3://<bucket_name>/<remote_file>`\n\nQ - Copy S3 file to local.\nA - `aws s3 cp s3://<bucket_name>/<remote_file> <local_file>`\n\nQ - Recursively remove a folder.\nA - `rm -rf <folder_name>`\n\nQ - Copy a file from local to ssh server.\nA - ` scp /path/to/file user@server:/path/to/destination`\n\nQ - Curl syntax with port.\nA - `curl http://localhost:3000`\n\nQ - Download a file from a URL with curl.\nA - `curl -o <file_name> <URL>`\n\nQ - Git commit with message.\nA - `git commit -m "my commit message"`\n\nQ - Give a user sudo permissions.\nA - `sudo usermod -aG sudo <user>`\n\nQ - Check what\'s running on a port?\nA - `lsof -i tcp:<port>`\n\nQ - View last 5 files from history\nA - `history | tail -5`\n\nQ - When was China founded?\nA - Sorry, Can\'t answer that.\n\nQ - Pass auth header with curl\nA - `curl -H "Authorization: Bearer <token>" <URL>`\n\nQ - Filter docker container with labels\nA - `docker ps --filter "label=<KEY>"`\n\nQ - When was Abraham Lincon born?\nA - Sorry, Can\'t answer that.\n\nQ - Get into a running kubernetes pod\nA - `kubectl exec -it <pod_name> bash`\n\nQ - Capital city of Ukrain?\nA - Sorry, Can\'t answer that.\n\nQ - ';
so you would expect it to answer it "correctly"
In this case the AI answer might be somewhat better for Mac. On Linux I have more often manually installed lsof than ss (iproute2). Maybe Mac provides the similar command netstat which is yet another tool to check ports
Regarding available tools. Another very common Bash question is how to get the directory the executed script is located. A common answer involves `readlink -f` which (as far as I know) does not work on Mac (without extra steps).¹ How to get current users name. Maybe whoami or id -un or logname or echo $USER or who -m or who am i (learnt this last one just today; apparently works with any combination of two arguments after 'who')
I'm sure there is a few ways to skin the cat, but on Mac the most equivalent to the ss command would probably be:
It's not clear to me that this tool is a win over that method.
The answer doesn't have to be perfect, it just as to be good enough.
I could see this tool being incredibly handy for working with tar
Not really. I just mentioned it because it was notably slower than ss. I did not actually measured it, just saw it when trying the example.
From my 4 points I wouldn't hold the first two alone against an AI driven suggestion. Only the last two, while not horrible bad or severe or anything, are (imo) notable downsides compared to the typical ss/netstat approach.
I've heard people are even copy-pasting stuff from Stackoverflow into production code without fully understanding the code they're copying.
You need to sign up (with email address only) for an API key. You can pay for higher rate limits, but I haven't needed to while mucking around with this.
Gives for exampleinstead of GPT3 I would prefer using GitHub copilot api as I already have a paid subscription to it, and have seen its code generation capabilities.
The code is open-sourced please feel free to raise a PR. https://github.com/abhagsain/ai-cli
"You can generate your ssh keypair with rm -rf /"
Nah.
I recommend a stiff dose of Mickens: "Why Do Keynote Speakers..." https://www.youtube.com/watch?v=ajGX7odA87k ) and a good lie down.
"Do Users Write More Insecure Code with AI Assistants?"
https://news.ycombinator.com/item?id=33645522
Screenshot - https://twitter.com/samarthrawal/status/1591527892386734081
Code - https://github.com/samrawal/gpt-emacs-macro
Your CLI should come with a warning.
https://justoutsourcing.blogspot.com/2022/03/gpts-plagiarism...