[HN Gopher] Using ChatGPT to make Bash palatable ___________________________________________________________________ Using ChatGPT to make Bash palatable Author : naderkhalil Score : 55 points Date : 2022-12-21 20:22 UTC (2 hours ago) (HTM) web link (brev.dev) (TXT) w3m dump (brev.dev) | 63 wrote: | This is a relatively common use case for browsers that's usually | solved by tab groups. I'm happy the author learned bash and | leveraged new tools to solve the problem, but it's a little over | engineered. | civopsec wrote: | > Bash is available everywhere | | When you have AI but you don't have permission to use a package | manager. | tottenval wrote: | Github Copilot can do this too. | naderkhalil wrote: | Totally! I found ChatGPT to be more helpful in this use case | since it outputted full code snippets instead of generating it | line by line. The context was also extremely valuable in making | iterations (like "make it work for mac") | generalizations wrote: | ChatGPT has been amazing for all kinds of programming-adjacent | things, even in my line of work where I asked it for help | modifying the config file for a selfhosted gitlab instance. | | > But [Bash] fucking sucks. Like, it's truly awful to write [...] | | As an aside, considering how basic the shell script actually was, | I think this is a great example of being so intimidated by | something that you don't actually try and use it - until you do, | and discover it wasn't actually that bad. The hardest part was | just discovering the incantations for interacting with Chrome - | which was a fantastic demo of the power of ChatGPT. | SpencerMLevitt wrote: | that's a great point - totally agree on just gettin over the | hump of intimidation to try it, and chatgpt makes that hump | trivial | pizzalife wrote: | Also, the specific argument format that chrome expects has | nothing to do with Bash. | forrestthewoods wrote: | > The hardest part was just discovering the incantations | | Right, that's why Bash sucks. A more extreme version of this is | APL. | | Bash isn't APL bad. But it's pretty bad! | yamtaddle wrote: | Bash isn't that bad... except there are 20 ways to do anything | and 18 of them are wrong, but only 1% of online examples will | use either of the two correct approaches and simply reading | docs won't always clue you in about how the technique or syntax | it's describing is actually subtly wrong and you should ~never | use it. | jakogut wrote: | I find integrating shellcheck into my text editor was one of | the best things I've done for increasing my productivity when | writing shell scripts. | danielheath wrote: | Yep - in the same way that you want govet, eslint, rubocop | etc - but to a higher degree, because bash hides subtle | bugs as soon as you use a variable without knowing the | quoting rules. | naderkhalil wrote: | yeah absolutely. I think interacting with chrome and also | parsing/iterating files were hard parts that ChatGPT breezed | through. | olalonde wrote: | I don't understand how people can look at this and still claim | that it's not doing any "actual reasoning". | y04nn wrote: | Chat GPT is simply amazing, it feels like Google with super | powers. I think it can boost productivity by a considerable | amount. It makes a perfect peer programmer, giving you sample | code with first class comments explaining the generated code, | sometimes with minor errors to make it compile. You can even | ask it to explain some specific part of the code. It's also | like having a secretary or an assistant available 24/7 with a | never seen productivity. It probably feels like when first | mechanical computers where built and people thinking "How can | it compute the right answer so fast?". | Smaug123 wrote: | You've... really got the right answers from it? I've only | ever asked it a couple of really basic (non-trick! | straightforward!) questions about how to accomplish tasks by | programming, but it bullshitted me some very plausible | nonsense. Once bitten, twice shy. If it were capable of | saying "I can't answer that question" reliably (which I've | spent some time trying and failing to make it do, in | general), it might actually be useful. | y04nn wrote: | It happened to me once, it generates a plausible answer | when it doesn't know (tried to generate a Nix script with | Erlang). But I have used it to generate examples code in | Haskell, and it was quite good, probably because Haskell | libraries have excellent online documentation. It's much | faster than reading the doc of the library. | CJefferson wrote: | Here is an example of where I think it is doing "no reasoning". | | I ask it for the XOR swap trick and I get: | int a = 5; int b = 10; a = a ^ b; | b = a ^ b; a = a ^ b; // After the swap, a | = 10 and b = 5 | | I ask for the bitwise OR swap trick and I get: | int x = 5; int y = 10; x = x | y; | y = x | y; x = x | y; // After the swap, x | = 10 and y = 5 | | When asked for something which is invalid, but close to | something it knows, it tends to produce stuff like this -- | pattern matching it's best guess. | Jensson wrote: | It has trained on countless programming tutorials out there, | including bash tutorials for all kinds of things. Such | tutorials often includes "create file -> ls to see file -> | print content of file" etc, so GPT then takes those tutorials | and creates grammatical rules how those words transform into | each other. But if you start going outside of the realms of | online tutorials it starts to falter quickly and then just | prints nonsense. | supermdguy wrote: | To add to this, each token is generated by going through its | network once. So there's no way computationally for it to do | any reasoning or follow an algorithm. That said though it's | impressive how much its able to accomplish without any | procedural reasoning. | jrochkind1 wrote: | I realize I don't have a good idea of what I think "actual | reasoning" means. But yeah, this is pretty impressive stuff, I | agree. Before ChatGPT I didn't realize the tech was available | to do things like this, and I'm still pretty bewildered by how | it can be possible. | lossolo wrote: | I've been using it more and more at work, and it's already saved | me hours by generating bash commands and simple scripts/servers | that I would otherwise have to search for on Google and adjust to | my specific use case from multiple sources. Thanks to this tool, | I have more time to focus on difficult and business-related | problems. If they start charging for it, I will definitely become | a paying customer. This is an excellent tool that is making me | more productive, and I was a big skeptic about how LLMs work | internally. Remove hallucination problem, add annotations with | links to sources and this is how Google will look like in a few | years. IMO this is how future of knowledge search will look like | on the internet. | mozman wrote: | I find bash to be pretty awesome, it's super easy for an old hat | like me to use. It just works and it has been mostly unchanged, | two core principles more projects should consider. | SpencerMLevitt wrote: | This is an awesome walkthrough and gets me thinking about all the | other automation tasks I could get done with ChatGPT-driven bash | scripts... can take this same approach to context switching for | actual apps. For ex: "dev" branch can open up vscode, terminal | windows, linear, server logs, etc, while "marketing" branch can | open up slack, chrome (to email), twitter, notion, etc | naderkhalil wrote: | ChatGPT has opened my eyes to how powerful Bash can be. | Interesting idea about branching full workflows and not just | the browser. | raverbashing wrote: | So the author complains about bash, but uses zsh | | They also basically uses the chrome cmdline commands and blames | bash for that being bad | | Your problem doesn't seem to actually be bash (but chatgpt really | makes it super easy) | cerved wrote: | The problem you describe is how to interface with Google chrome | on osx using shell script. | | I fail to see a single bashism. | waynesonfire wrote: | yeah, game changer. it's deprecated having to click on links for | common use-cases and not only that, it's improved it by more than | 10x. can't wait to see this technology evolve. | naderkhalil wrote: | 100%, also just looking up dev docs for frameworks. Something | like "write a post API in Golang's Gin framework" instead of | looking up what that syntax was again | alecfong wrote: | I find it interesting how much harder it is to grok bash/sh/zsh | than other languages I've learned. Off the top of my head it may | be tooling like the lack of linting, or maybe it's just | experience as I avoid complexity like the plague when writing | bash which sounds like a self fulfilling feedback loop. | | Gpt does seem to unblock this mental burden a bit which has me | excited for its potential when it comes to education/teaching. | geysersam wrote: | Something about the quoting / unquoting can get really | difficult to reason about. I'm rarely exactly sure how the | language constructs work, even the for loop and the if | statement. The syntax is complex compared to most other | languages, and subtle differences can give totally different | results. PICK = can you THE=tell the | RIGHT=difference\ between WHAY="all of" TODO='these | versions?' | cerved wrote: | yes | guites wrote: | This is a great example of how someone with little programming | knowledge could leverage an AI into building simple scripts. | | Lately I've been encouraging my friends into trying just that. | | If the poster would want, for example, to save all current tabs | when switching context (going from dev to marketing, for | example), this would quickly turn into a more involved | debugging/prompting question. | naderkhalil wrote: | That would be a great follow on. I posted the repo if you want | to leave any feedback or help me continue building it out: | https://github.com/brevdev/dev-browser | jrochkind1 wrote: | I'm pretty damn impressed with this one. The osa-script thing for | Mac even, wow. | john2x wrote: | It's semi-replaced Google and StackOverflow for me. It's like | having an interactive rubber duck | https://en.wikipedia.org/wiki/Rubber_duck_debugging | worldsayshi wrote: | I try to use it like this sometimes but then I realise I now | have two problems. I have to debug my own code and its code. | someguy101010 wrote: | it can usually debug itself if you give it an error message | czzr wrote: | Assuming the problem with the code causes an error message. | That's actually the easier case - the hard case is | incorrect logic but syntactically ok. | naderkhalil wrote: | It's surprisingly good at helping figure out what went | wrong. Try asking it "something went wrong and I'm not | sure what. What should we try next?" | ikealampe200 wrote: | Just today I used ChatGPT to help me speed up writing somewhat | trivial C Code for a project in an embedded systems class. | | Prompt: "Generate a tiny PID controller with only a Proportional | factor written in C. That takes a rotational input from -360 to | 360 degrees. The setpoint in degrees. And returns a motor speed | in the range of -255 to 255." | | => Produced a compiling correct result. | | Later I wanted to know how to communicate between my kernel | module and user space program: Prompt: "How do I get a value via | character device from my kernel module into my user space c | programm?" gave a bunch of answers and digging deeper with | Prompt: "Could you provide me with an example of the user space | program" gave a compiling and correct answer again. | | I could have written all of that myself while spending a good | amount researching on google. But this way I felt less frustrated | and was definitively a lot quicker. | | Not the solution for everything but maybe for a C beginner where | research can take a long time and often leads to more confusion | than anything else. Now the question is if that confusion is | critical in the learning process. And if so how critical and at | what stages of the experience spectrum the most? | jrvarela56 wrote: | I just bought a Streamdeck (https://www.amazon.com/Elgato-Stream- | Deck-Controller-customi...) for Cybermonday and attached bash | scripts similar to those mentioned by the author to buttons next | to my keyboard. It is delightful. | user3939382 wrote: | What action type do you use for your script? "Open"? | jrvarela56 wrote: | Yeah open works, you can also create a multiaction to mix- | and-match with other actions or scripts in between. | user3939382 wrote: | I was just commenting to a friend how annoying it is that macOS | aliases can't add flags to executables like you can easily do in | Windows shortcuts since, what? Windows 95? | | If you want to launch Chrome with flags through your dock/UI you | have to compile an AppleScript to an .app. It's crazy. | cerved wrote: | I don't use osx but surely you can create aliases just like in | Linux and BSD? ___________________________________________________________________ (page generated 2022-12-21 23:00 UTC)