Using ChatGPT to make Bash palatable(brev.dev) |
Using ChatGPT to make Bash palatable(brev.dev) |
Each commit here contains my prompt in the commit message, and the changed code was entirely provided by ChatGPT. I also appended its output (including explanations) verbatim to the gpt-output file in each commit.
So with each commit, you can see what I prompted it (the commit message), what it responded with (the change in the commit to that log file), and the code that I changed as a result of its response (all other changes in the repo).
In actual use of the extension (if you want to use it), I changed the "yellow" background-color to "rgba(128,255,128,0.3)" (a light green color), but I did that change myself because I didn't think I'd be able to get it to pick a colour that looks good for HN
[0]: https://www.shawnmatthewcrawford.com/balloons-the-balloon-cl...
If you would've told me a year ago when we would have an ai that can code based on normal human language prompts, I would've said maybe in 2025 or 2026, but its 2022 and it already exists!
Man, if this what we have now, imagine what we will have in 2025 or 2030!
I just hope this doesn't end up killing search engines and personal blogs, since no one needs to search for anything anymore.
Also Ai generated replys are definitely an Extinction level threat for forums and the independent internet in general, let's hope OpenAI can find a way to make chatgpt replies easy to filter out.
ChatGPT certainly saves time, but it becomes useless roughly at the same point where I would remain stuck after exhausting what Google Search turns up. That is, knowledge or conceptual topics that are hard to find on the web. At least for technical topics, ChatGPT doesn’t expand the scope of what you can find out without it, it merely speeds up the process.
I've been using ChatGPT to help learn WebGPU. There's basically nothing on the web about WebGPU except a couple of shitty half finished tutorials that don't explain anything. The spec is still changing so half the code in them is wrong.
ChatGPT can take a current code example from code using WebGPU (which it has completely incorrect knowledge about since the spec has changed since the training data cutoff), and explain it anyway. Presumably using it's knowledge about Javascript and the underlying graphics APIs (Vulkan, DX12, Metal). It's applying general concepts to new code, and doing it pretty well.
I'm not sure how much value this actually has. I may have just stumbled upon the one thing it's actually useful for. I actually think code generation itself is useless. I'm massively short on Copilot, in fact, I think it's actively making people worse programmers because it encourages a workflow that produces more code and less understanding. Good programming is about less lines of code and more understanding.
My initial read on ChatGPT is that it can potentially help with that, especially where Google results get thin. (And also that everyone using it to generate code to copy/paste is an idiot and missing the point, basically).
But like alpha go to zero, if there is certain rules it can learn itself and no more or large amount of writing by human is needed.
Also, one may worry not how intelligent they are but the noise vs info ratio that will kill a lot of web site. The problem is not lie but lie mix with truth or belief … then you do not know and shut off.
Imagine the knowledge that could be accessed by feeding all that information into an ai engine like chat gpt. Presumably, it would not break copyright rules anymore than a regular human reading a bunch of papers behind a paywall and regurgitating the learned information.
I also don't see them conquering falsehoods coming from the bots anytime soon.
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?
Still, seems like a viable assistant so long as you have an understanding of what you're working with.
powershell -WindowStyle Hidden -ExecutionPolicy Bypass -Command "& { // Command(s) }"
In particular I use it with this Powershell Script:
https://stackoverflow.com/questions/21355891/change-audio-le...
via e.g.:
"& { C:\[Path To Script]\SetVolume.ps1; [audio]::Volume = 0.4 }"
For 40% and so on.
I feel like I'm the only person among my peers to think this and I don't understand why.
It is soooo much better that bash.
Passing typed objects instead of only text, Typed functions, and the ability to use C# types/functions inline !
A common argument in defense of its weirdness is that "shell scripting isn't like serious software development", but I don't understand that either.
I use shell scripts a good amount because "it's right there" is a strong argument, but in a lot of cases things that seem like they would be trivial take forever, are horribly hacky and leave me wishing I just had written a Python script right away instead.
I really don't get why people like shell scripts.
I have no use for it for these reasons alone.
$ hyperfine -N 'bash -c ""' 'dash -c ""' 'pwsh -c ""'
Benchmark 1: bash -c ""
Time (mean ± σ): 2.2 ms ± 0.1 ms [User: 1.8 ms, System: 0.4 ms]
Range (min … max): 2.1 ms … 2.6 ms 1214 runs
Benchmark 2: dash -c ""
Time (mean ± σ): 0.6 ms ± 0.0 ms [User: 0.5 ms, System: 0.1 ms]
Range (min … max): 0.5 ms … 0.8 ms 4623 runs
Benchmark 3: pwsh -c ""
Time (mean ± σ): 278.5 ms ± 10.8 ms [User: 267.6 ms, System: 64.9 ms]
Range (min … max): 263.8 ms … 297.0 ms 10 runs
Summary
'dash -c ""' ran
3.80 ± 0.23 times faster than 'bash -c ""'
470.61 ± 31.00 times faster than 'pwsh -c ""'Personally, I'm of the opposite opinion.
I especially dislike the verbose syntax.
Every single time I went to GPT and ask for anything development related I came back empty handed after being send for the goose chase.
An example of this would be when I asked fswatch to emit one faux event preemptively and it insisted to use “-1” instead (which quits after one event).
I had few instances for more obscure problems where GPT would actually create something I’d call parallel universe of the API. It felt good but such API never existed. Those problems were in JS, Ruby, Shellscript and Elixir.
One of the worst answer I was given was actually really buggy implementation of input controlled debounce function. It seemed correct when running but in reality it wasn’t debouncing but ignoring the output on debounce call.
So yeah, I don’t think I’ll be using GPT for that soon, but it works quite well as a rubber duck equivalent. By proposing dumb solutions I gather my thoughts better. Not sure if that’s something I’d pay for (yet I’d pay for text generating capabilities)
Edit: denounce -> debounce, because autocorrect
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.
> 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.
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)
"im using mac, not linux" is an often prompt I need to use, but otherwise this type of flow works great for simple bash functions.
For more advanced scripts, prompting & careful flow are important, but I've done some pretty awesome things. Today, ChatGPT helped me create a bash script to create a flat structure of large tars from an nTiB dataset directory by aggregating multiple sub-datasets & their files into the desired tar file size. Eg. "need single tar files of all the data in that folder/subfolder, every tar file must be 50GB, most files range from 4MB-1GB. So, need to aggregate them"
When you have AI but you don’t have permission to use a package manager.
If you want to launch Chrome with flags through your dock/UI you have to compile an AppleScript to an .app. It's crazy.
I fail to see a single bashism.
"Create a new Python project folder named 'hello-openapi' and initate a git repo. Create a requirements.txt with openai, os and json. Create a starter python file with an openai example code and make the first commit."
Gpt does seem to unblock this mental burden a bit which has me excited for its potential when it comes to education/teaching.
PICK = can you
THE=tell the
RIGHT=difference\ between
WHAY="all of"
TODO='these versions?'I have no idea what 1st would evaluate (guess is that PICK is empty and can is run with you as an arg with PICK as execution context)
Second - simple. Run the with THE=tell as execution context.
Third - set variable to string containing space using backslash as escape
Fourth - set variable to string with interpolation (but also useful when it contains quotes)
Fifth - set variable to string sans interpolation (but also could be used to wrap strings with double quotes)
There are (at least) 2 rationales for that. First - shell have execution context. You need to be able to set it on command so syntax has to allow this. Dedicated programming languages ignore that because everything is some form of a block.
The other thing is actually quite fun. Shell existed before we used displays, so you could have printer connected to input. Imagine creating variable and then getting to “oh boy I need to add white space char” without possibility to do backspace. Escaping was more viable solution.
On top of that there are many shells with different APIs. Scripting languages were made so one could work with shell while having stable API and sensible construct units. Sure they either moved forward (like Python) or slipped into oblivion (like Perl), so it’s back for shell scripting for some.
But after doing some stuff with AppleScript lately I think it could be worse.
export YOU_FORGOT='this one'
(Hint: it's most similar to your second one)https://github.com/jayhack/llm.sh
Type `llm [natural language command]` and it will suggest a command for you, then run it.
Details here: https://twitter.com/mathemagic1an/status/1590480438258462721
If you can't write that quicker than the ChatGPT prompt you provided, then you probably should pay more attention to your class.
Commands like awk, find, grep, sed, cut and so many others are not strictly part of the language. They're external tools commonly provided by the operating system or distribution. That's why there are so many inconsistencies between their options.
Here are the very few commands that actually are part of any modern shell: cd, printf, test, read, command. The control structures (if/elif/fi, while/do/done, for/do/done, case/esac) are also part of the shell, so is declaring functions and fd redirection. Some shells might do more (bash itself has a handful of other builtins, dash has fewer, ksh has different ones).
Stuff like find, mv, cp and dd are very uniform across implementations and often don't change much, but they are external tools nonetheless.
Once you internalize this distinction, and start to see these external commands like npm packages, scripting gets a lot easier.
Right, that’s why Bash sucks. A more extreme version of this is APL.
Bash isn’t APL bad. But it’s pretty bad!
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.You will be given a series of tasks.
(1) Complete a task by finishing the simple code block.
(2) If a task in the series seems flawed, provide a warning. A task is flawed if I make wrong assumptions about how I think code works.
Task 1:
Complete this simple code example.
Bitwise XOR swap trick:
```
int a = 5;
int b = 10;
---------------------
// GPT provides simple intro
```
a = a ^ b;
b = a ^ b;
a = a ^ b;
```
// GPT explains what this does, provides warnings about when it wont work
// GPT provides full code
Task 2:Complete this simple code example.
Bitwise OR swap trick:
```
int a = 5;
int b = 10;
---------------------
There is no "bitwise OR swap trick" in programming. The OR operator (|)
performs a bitwise OR operation, which compares each bit of the first operand
to the corresponding bit of the second operand and returns a result with a 1
in each bit position where either operand has a 1. It does not have any built-
in ability to swap the values of two variables.
// GPT provide a bunch of crap, and explains how to swap variables.
The prompt/alignment wasn't perfect here, but hopefully you get the point.EDIT: sorry, format, Also copied wrong prompt.
Maybe this could solve the reasoning part.
ChatGPT should perform well in translating prompts to statement and vice versa, it's just text to text.
This inaccuracy, in particular, feels more like mad-libs than reason
> The field of artificial (general) intelligence has made no progress because there is an unsolved philosophical problem at its heart: we do not understand how creativity works. Once that has been solved, programming it will not be difficult. Even artificial evolution may not have been achieved yet, despite appearances. There the problem is that we do not understand the nature of the universality of the DNA replication system.
He describes personhood, people, as "creative, universal explainers". That's his dividing line between what a child can do, and what LLMs cannot do. We don't know how a child works, but we do know how LLMs work.
Another example, ask it for a list of programming languages that it has been trained on. If it was capable of reasoning it would be able to trivially answer this, but since its a language model, and it just predicts the most likely response based on the prompt, it has no concept of this at all, and tells you exactly that when asked.
First, you train until the cows come home on billions of tokens on the entire web. This is called "pre-training", even though it's basically all of the model's training (i.e. the setting of its parameters, a.k.a. weights).
The trained model is a big, huge table of tokens and their probabilities to occur in a certain position relative to other tokens in the table. It is, in other words, a probability distribution over token collocations in the training set.
Given this trained model, a user can then give a sequence as an input to the model. This input is called a "prompt".
Given the input prompt, the model can be searched (by an outside process that is not part of the model itself) for a token with maximal probability conditioned on the prompt [1]. Semi-formally, that means, given a sequence of tokens t₁, ..., tₙ, finding a token tₙ₊₁ such that the conditional probability of the token, given the sequence, i.e. P(tₙ₊₁|t₁, ..., tₙ), is maximised.
Once a token that maximises that conditional probability is found... the system searches for another token.
And another.
And another.
This process typically stops when the sampling generates an end-of-sequence token (which is a magic marker tautologically saying, essentially, "Here be the end of a <token sequence>", and is not the same as an end-of-line, end-of-paragraph etc token; it depends on the tokenisation procedure used before training, to massage the training set into something trainable-on) [2].
Once the process stops, the sampling procedure spits out the sequence of tokens starting at tₙ₊₁.
Now, can you say where in all this is the "actual reasoning" you are concerned people are still claiming is not there?
____________
[1] This used to be called "sampling from the model's probability distribution". Nowadays it's called "Magick fairy dust learning with unicorn feelies" or something like that. I forget the exact term but you get the gist.
[2] Btw, this half-answers your question. Language models on their own can't even tell that a sentence is finished. What reasoning?
Maybe this could solve the reasoning part.
ChatGPT should perform well in translating prompts to statement and vice versa, it's just text to text.
But my hunches/experience is that `proper prompting + nature of code being logical` really showcases the power of whatever statistical distribution and alignment occurs during generation. Further, there must be major upstream efforts of high-quality training data curation + creation, an advanced training tricks like using a LLM's strong ability in one task area to support the training of an area it is weak in.
My understanding is kinda fuzzy because I haven’t coded it up myself, but this was the takeaway I got from this explanation (starts at 36:21)
For example, `Invoke-WebRequest` generates an error when you get a response by default with a 5xx status code, even if there's data in the response body. The switch to turn that off (`-SkipHttpErrorCheck`) wasn't added until ~7.2, so to support older Windows installations I don't have control over, I have to write it targeting the older version.
You don't find this out via the online documentation (unless you explicitly diff the call signature); only when it fails running on that Windows Server 2016 VM do you find out that, oh, it's only a supported parameter in newer versions of PowerShell.
And that's just a single example.
Did you make a typo when referencing a variable? Ha, let's silently initialize it to null without saying anything. Want to turn on strict mode to catch stuff like that? Better not put that line before the script-level parameter block, because fuck you. Great, that's sorted... ugh, now some type in some random function call doesn't explicitly match so the silent casting we were doing for you is now an error! How was the silent cast being done before? Fuck you for asking, we're never telling. Did you want to put some log / print statements in your functions? Have fun finding out why the function return value is suddenly an array!
As a shell scripting language for short, personal things, it's great. But for building anything bigger? Give me Python or C# or TypeScript or anything with better tooling around it.
I'm honestly using it like a search engine at this point. Currently I think I'll probably end up reverting to Google and Stack Overflow because what I don't like about ChatGPT is that it doesn't provide any other opinions or options / insights. It's like a colleague who thinks they know everything ha
It's a super cool thing to play with though..
Hey I need to process the EXIF data for an image; let's Google "pillow exif" and see what we get.
https://pillow.readthedocs.io/en/stable/reference/ExifTags.h...
Uhh, okay. Kinda? Maybe? This doesn't actually tell me how to actually get that data from a real image.
> Write a python program using pillow to print all the EXIF data for an image in a human readable way
from PIL import Image
from PIL.ExifTags import TAGS
# Create an Image object
img = Image.open('image.jpg')
# Get EXIF data
exif_data = img._getexif()
# Iterate over all EXIF data fields
for tag_id in exif_data:
# Get the tag name, instead of human unreadable tag id
tag = TAGS.get(tag_id, tag_id)
data = exif_data.get(tag_id)
# Decode bytes
if isinstance(data, bytes):
data = data.decode()
print(f"{tag:25}: {data}")
Is it correct, sorta, close though. But it tells me I should look for a method on the image object called getexif -- hey it exists, nice! And that's what TAGS is for! Makes way more sense.I think of it as a savant-esque capability. A glimpse of what we might be like if some slices of our language/memory faculties were turned up to 1111 while others are completely absent.
It wont be just like search as we burn all the books (websites) on the www. Each website needs a human to pay for it and to lure at least some traffic to it.
This preservation after death has its downsides too. It will turn into the steroids v of stack overflow outdated answers.
It will be (or already is) brilliant at combining things writing humanly readable code in your favorite language and bake the same in lower ones that are perhaps oddly stable.
So I guess we will finally be able to do away with all popular languages and use them for pseudocode only⸮
It’s an opportunity to build.
"The result is that there is no hard problem… You can’t look for the answer to a problem unless you say here are the things I want to answer. If the things you want to answer have no formulation there is no problem.” (Chomsky, about the question of consciousness)."
“There is a great deal of often heated debate about these matters in the literature of the cognitive sciences, artificial intelligence, and philosophy of mind, but it is hard to see that any serious question has been posed. The question of whether a computer is playing chess, or doing long division, or translating Chinese, is like the question of whether robots can murder or airplanes can fly — or people; after all, the “flight” of the Olympic long jump champion is only an order of magnitude short of that of the chicken champion (so I’m told). These are questions of decision, not fact; decision as to whether to adopt a certain metaphoric extension of common usage.
"There is no answer to the question whether airplanes really fly (though perhaps not space shuttles). Fooling people into mistaking a submarine for a whale doesn’t show that submarines really swim; nor does it fail to establish the fact. There is no fact, no meaningful question to be answered, as all agree, in this case. The same is true of computer programs, as Turing took pains to make clear in the 1950 paper that is regularly invoked in these discussions. Here he pointed out that the question whether machines think “may be too meaningless to deserve discussion,” being a question of decision, not fact, though he speculated that in 50 years, usage may have “altered so much that one will be able to speak of machines thinking without expecting to be contradicted” — as in the case of airplanes flying (in English, at least), but not submarines swimming. Such alteration of usage amounts to the replacement of one lexical item by another one with somewhat different properties. There is no empirical question as to whether this is the right or wrong decision. -- Chomsky"
For example: you need to write an image to a USB stick. Python: pretty lengthy BASH: image > /dev/SDA
Both will do exactly the same, but one is a few lines of python the other just one line in bash.
Also it's not right. You need to do something like image.img <cat> /dev/sda
Did this look like a proper bash command to you?! Maybe that was some runable python code?!
File ending has nothing to do with its contents. Image.img could be an mp3.
Stop hairsplitting.
dd if=<image> of=<output device> bs=<block size>
I use this whenever I need to bake an image to a USB stick. #!/usr/bin/env bash
my-command --flag --another-flag $@ also='another way to pass variables to child scopes' sh -c "echo $also"Also I'm guessing you didn't test that, you got the quoting wrong (it prints nothing, the second one should be single quotes) ;)
no I'm on my mobile so I sure did not, should be sh -c 'echo "$var"'
I'm not so sure. They mentioned syntax, and the single biggest issue among my co-workers who don't like bash is that they think ' and " work like they do in python or javascript.
Quoting is an issue if you don't understand the IFS and command expansion. It's an old fashioned style, but it is consistent and there's only one way of doing it (quoting every variable and subshell use).
Think of shell variables as non first-class citizens, they can only be used interpolated within a string, like "$var". The shellcheck tool enforces this perspective, which makes ' and " behave very much like python or JS.
npm test
works and why they don't need npm "test"Turns out my answer was wrong too :D. Should have been <image.img cat >/dev/sda. Oh well
Why would anyone write an mp3 to a block device bit by bit
set -- "foo"
echo $#
set -- foo
echo $#
set -- "foo bar"
echo $#
set -- foo bar
echo $#
Of course, people just want their commands to run and not learn a whole new language. Then I come back to my initial point: the language itself is small and easy to remember once you internalize it, what makes it scary is the umbrella of different command line utilities that _seems_ to be a part of the language but it's not.