Hacker News new | past | comments | ask | show | jobs | submit login
I figured out how to get GitHub Copilot to run in the terminal (github.com/maxwell-bland)
164 points by roko-298 on Sept 15, 2022 | hide | past | favorite | 97 comments



It’s generally claimed that reading other people’s code is harder than writing your own. I mean, everybody loves writing code on a greenfield project but hates maintenance of legacy code, right? So, why do people like these code generators? The only explanation I can see is that people use them and then don’t read the code. Which would be horrifying.

(I stay away for obvious copyright reasons.)


It is absolutely amazing for writing boilerplate code that is also context aware. It saves me hours of typing. It's hard to explain if you've never tried it because you're ideologically opposed to it, but stop being close minded and try it out, I promise it's a great tool to assist your programming.


Good codebases don't need boilerplate to do basic stuff: in this sense, copilot is a patch over the real problem, which can be solved with better frameworks and more code reuse.

I tried copilot during the beta, and apart from the obvious legal licensing issues, I simply could not find a valid usecase for any of the codebases I usually work with.

At my day job, I spend more time thinking of better ways to do X, rather than writing boilerplate code :)


I disagree. Some amount of boilerplate is preferred versus abstracting everything. Boilerplate can be frustrating to write, and fiddly boilerplate absolutely should be abstracted, but in general it should makes the flow of logic easier to follow.

> At my day job, I spend more time thinking of better ways to do X, rather than writing boilerplate code :)

Not that you are suggesting otherwise, and I am being somewhat facetious, but oftentimes boilerplate is preferred to boiling the ocean.


A million times yes. If a codebase is magically adding _all_ of the boilerplate, it's almost always harder to understand what's actually happening.


I have found Copilot useful while writing compilers and virtual machines all the way up the chain to CSS grids and media queries.

Are you telling me there isn’t a fair bit of boilerplate in bog standard implementations of OP_ADD or in a grid layout with a sidebar and a footer?

The irony here is that the level of abstraction necessary to remove all boilerplate means that you’re removing the descriptive nature of the boilerplate and making your code difficult to understand.

Boilerplate isn’t necessarily a bad thing but sometimes it can be rather verbose and it is very nice to offload that typing to a tool.


Whenever I have boilerplate in a codebase I try to make a tool to create it for me. So copilot does seem like an extension of that.

I think the thing that weirds me out about copilot is that I can't peer inside it. I guess I like knowing something will always work?


If it doesn't work, you don't have to accept its recommendation. You just keep coding.


What are some examples of code without boilerplate?


At your job the boilerplate was probably written already and you can avoid it.

Not all jobs are on mature projects.

I get tired of highly subjective anecdotes being used as concrete truths.

You are not the center of reality as we don’t know there is one. So good on you for having a job where the boring work was already in place. Look how far you have come on your own leveraging past effort. So proud of you.


This way lies hellish amounts of indirection.


You're completely missing the point of copilot. It speeds up typing by 10% or more in highly organized codebases. Strong codebases synergize with copilot, they don't compete.

10%+ speedup is a huge, obvious win. Anything that increases my productivity is good.


I am curious about the hours of typing thing. I don't normally need much boilerplate, so I normally just type things. If I do need boilerplate, I yank the boilerplate into a buffer and put it into the file I am working on. Yet I feel like the overall time spent doing this is incredibly slight.

I feel like it's possible some time could be shaved off somewhere there, but this all happens very quickly and it's not an area where optimization would improve things much overall. For this to amount to literal hours of typing, I think I would need to be either very much slower at typing, writing an immensely large volume of boilerplate, or working over many many years. Typing stuff is essentially never a bottleneck for me.


[flagged]


Calling fellow commenters stupid or ignorant isn’t right. Please reconsider.


I was against copilot until I tried it.

It’s not always on target, but it’s usually pretty close and the suggestions are good.

No, it doesn’t write all of the code for me. But it does rapidly construct even quite complicated if/else statements that I was going to write anyways, just from knowing where I’m typing. Quite a great tool.


I was just revisiting an api call which it turns out needed pagination. I put a note in the docstring before I began and copilot just... rewrote the function to include pagination. Except for a couple of corrections to the json returned by the api (copilot could only guess), it just worked! I'm amazing by copilot and it frequently writes chunks of my code, especially shell scripts and docker files. A little worried that my job might be on the way out at some point!


I love it but it’s nowhere near the level of replacing anything but the lowest skill developers. The actual real skills involved with deciding what problems to solve, architecting and developing complex software would require general AI level AI, and at that point a *lot* of people are going to be out of jobs.


I prefer to think that I'm learning $x much faster because I don't have to go hunting documentation nearly as often.


I think many people see GitHub Copilot as a code generator, without having used it, and then wonder like you.

But afaik almost everybody uses it as autocomplete on steroids.

So the reasoning behind using it is the exact same as using autocomplete in I.e. Intellij.

It's just slightly more powerful, since it will usually autocomplete the whole line (occasionally a bit more), instead of just the current keyword.


It sometimes completes whole functions for me, from which I just have to make minor corrections afterwards. Some of which would have required me to lookup syntax 2 or 3 times. So it saves a lot of time in that way.

I do find it's much better in some languages though. And probably especially with languages you're new in. It doesn't do much for me in PHP, but does a lot in JavaScript.


Exactly this!

And it's scary how good it is for "autocomplete" sometimes. I've found it much more useful on our angular webside frontend rather than the c# backend.. but man on the angular/javascript side it really saves time.

I can't think of any good examples off the top of my head, but every few days I literally am wondering to myself "how did I now I wanted to do exactly that!"


I use them to quickly learn new languages or libraries. E.g., I’ve done only C++ for a few years and got rusty in other things. I used copilot to quickly learn how to create a Python Flask server, how to draw shapes on an HTML canvas with JavaScript, how to write common algorithms like “generate a random number in this range” without having to reach for pen and paper, etc. all without leaving my editor. It’s kind of like a much faster Google search for a StackOverflow result, and keeps you in the flow.

Disclosure: I work at Microsoft, opinion is my own.


I'm sorry, but this is an incredibly shallow analysis. You don't even know what CoPilot is, apparently, and yet you speak in these broad generalities that are misguided at best. It's the only explanation you can see because clearly you haven't looked...


It's good enough that I wouldn't really call it a code generator, and I wouldn't put it in a category with other tools due to the performance different from anything else like it.

Often, it creates code that follows the style of the surrounding environment.

Honestly at this point, the copyright concern seems either ignorant or paranoid to me. The program is interactive and generally only creates small chunks of code at a time. You can read and modify the code it generates (I always do). I only operate on it in digestible chunks, none of which are "original" enough to be considered copyright. Surely, you as a developer can easily say whether the code generated is just some non-copyrightable snippet (some simple BFS code) vs stolen code lifted off a codebase (weirdly specific implementations, fast invsqrt, comments that look like they were written for a different context, magic numbers, undiscovered algorithms).

I would argue that if you can't differentiate between meaningful IP and boilerplate algorithm implementations (with variable names conveniently matching the surrounding context), then you have a different problem.

Yesterday I implemented a BFS in about 30 seconds because copilot recognized the pattern and auto-completed. It took 5 seconds to autocomplete, and 25 seconds to read and fix one line that was wrong. That normally would have taken me 5-10 minutes to code + debug (the copilot code didn't have any errors, minus the 1 I easily found). The productivity gains are too good.


> reading other people’s code is harder than writing your own

This is the first time I've ever seen this lol. I'd have had a hell of a time learning how to code if that were true!


> So, why do people like these code generators?

To cover the lack of good libraries and/or language abstractions.


This is a bit off topic, but I am naturally excellent at reading other people's code. I can somehow factor in commit messages and see their style to determine if they didn't know X area very well, if it was a temporary hotfix, or if they intended to come back and fix this area up at a later time. It's like I'm sitting there with them while I read it.

Is there a job title where I can put this to use? I'm alright in general feature work, generally exceptional in bug fixes or finding exploits, and exceptional in code reviews. I always get stuck in leetcode tests of technical interviews though despite having like 8 years of experience.


I've found myself needing some snippet of code that has a very targeted function, and whenever I see something online that's close enough, I sometimes paste that in my code and then make the necessary adjustments. This pattern is common enough (at least in my workflow) that if I could just start writing in the editor and it did a decent job figuring out what I was going for (in much the same way as my google query), and then let me dive straight into adjusting it, that's kinda nice.


You know all the times you need to lookup syntax or how to do something on Stack Overflow or some other site? Copilot replaces about 80% of that. Speeds up that process a lot.


> It’s generally claimed that reading other people’s code is harder than writing your own. So, why do people like these code generators?

Harder doesn't mean quicker :)


nothing tells me you've never even tried it as much as this comment of yours

it is "intelligent context-aware code autocomplete on steroids"


> nothing tells me you've never even tried it as much as this comment of yours

You mean the part where I said that I haven’t tried it?


Hah, fair. Honestly, it's great. It's great in 2 ways:

1) When it's 100% correct, I smile, because it's often very clever, and as a programmer whose very existence is based on work elimination, when that amazing technological weapon is aimed at my own work needs as a developer, this is some Inception-level glee.

2) It's often wrong. Maybe like, 33% of the time? BUT when it's wrong (note that 95% right is still "wrong," so it's still very good), I smile, because it's often STILL clever, even in its wrongness, and this cleverness amuses me while working. For example, I use Elixir, which linguistically (but NOT semantically) is very similar to Ruby, so on occasion I've seen it make a Ruby-flavored suggestion to my Elixir. "Silly Copilot," I'd say smiling as I'd correct it (and probably teach it further).

So basically, it's made my day slightly more joyful, which is great. I already enjoy programming, so watching a program try to write my code ahead of me is absolutely fascinating.

Simple example of labor saving- I was doing some bash scripting and I wanted some constants for ANSI colors. Well I started writing them, and Copilot finished the whole damn table (with correct constant names, using the naming pattern I'd already established). And all the color codes were correct. This was wonderful! It's GREAT for language domains you're not hugely familiar with. Like, know how you have to often look something up working in a lesser-used language? Well in Copilot, you can just start writing a comment describing what you need or what the code will do, and 8 times out of 10 it will then spit the actual correct code out for you, it's just amazing.

Oh, tip: There's a keystroke combo that will advance through various suggestion possibilities. Often the first suggestion is not quite there, but another suggestion is.


By the way, the example snippet given to "echo a random number between 1 and 10" is incorrect, pedantically speaking. It's random, but not uniformly so. It's biased towards lower numbers (1-6).


Why? Wiki doesn't say anything about it and when I run it, the result looks fine

> $ for((i=1;i<10000;i+=1)); do cat /dev/urandom | od -N 1 -An -i | awk '{print $1 % 10 + 1}' >> rand.txt ; done

> $ cat rand.txt | sort | uniq -c

   1051 1
    932 10
   1012 2
   1042 3
    983 4
   1015 5
   1042 6
   1035 7
    992 8
    995 9


`cat /dev/urandom | od -N 1 -An -i` gives you a uniform random number between 0 and 255. The following mod 10 in the awk command introduces "modulo bias", which you can read about here https://research.kudelskisecurity.com/2020/07/28/the-definit...

You can see it quite intuitively if you iterate over all possible numbers between 0 and 255:

  $ (for i in {0..255}; do; echo $i | awk '{print $1 % 10 + 1}'; done) | sort -n | uniq -c
     26 1
     26 2
     26 3
     26 4
     26 5
     26 6
     25 7
     25 8
     25 9
     25 10


So, is there a correct way to do it in bash?


But that is not how /dev/(u)random works and does not give U(255). Generally speaking, it gives some hash of some user/device activity, from these resources:

https://linuxhint.com/dev_random_vs_dev_urandom/

https://en.wikipedia.org/wiki//dev/random


I know how urandom works (consider reading the articles you linked). The number between 0 and 255 is produced by the `od` command:

https://man7.org/linux/man-pages/man1/od.1.html


> does not give U(255)

What do you think each byte from /dev/(u)random is?


Just to be clear, cryptographic hashes and other outputs of cryptographic primitives are designed to be uniform random. If you find a detectable bias from uniform on the outputs of /dev/urandom then you should consider the underlying primitive (the ChaCha20 stream cipher, in the case of modern Linux urandom) to be broken.


If you sum the occurrences of numbers 1-6, you get 1051 + 1012 + 1042 + 983 + 1015 + 1042 = 6145. The expected count (if the numbers were uniformly random) is only 6000, on average. If you repeat your experiment, you will find that this sum is greater than 6000 more often than not.


Could someone explain how? I don't grok the command. My best guess is this relates to hexadecimal.


The calculation maps a random number R in range 0..255 to numbers 1..10 via

    R % 10 + 1
The problem is that 10 does not evenly divide 256, hence for large R, the mapping will be incomplete. Specifically,

    250 => 1
    251 => 2
    252 => 3
    253 => 4
    254 => 5
    255 => 6
with no more random numbers available to yield results 7, 8, 9 and 10.


Thanks for the explanation!


`od -N 1 -An -i` reads one byte from stdin (urandom in this case) and prints it as a decimal string (with value between 0 and 255). The awk command receives that number and prints it back out modulo 10.


Thanks for the explanation!


To add to this: (one of) the correct solution(s) is

  R * 10 / 256 + 1
EDIT: I am wrong, this still has bias.


Yeah, an easy solution to all these things is “find a uniformly random source that outputs in a range larger but close to what you want and then try again if it’s outside your range.

And indeed this is how Python does it

https://github.com/python/cpython/blob/e37ac5fbb6de593521cf2...

https://github.com/python/cpython/blob/e37ac5fbb6de593521cf2...


It took me a few hours to find the right plugins for neovim. Thought I'd post it here in case anybody was thinking about doing this. Cheers.


Nice work. Almost tempts me to try it.

I wonder if you could bundle it as a language server to make integrating it into editor workflows easy. It’s “basically” just the completion capability, right? Or maybe there’s something else to the interactions that make it not work nicely.


Speaking of copilot, when is GitHub going to support billing for it at the organization level? Right now I would have to do a monthly reimbursement request which is a pain.


Help me understand something.

I understand that the company should pay for Copilot in principle.

However, is paying $120 per year that much when it helps you in your at least mid-five-figures job? I would ask for the reimbursement if it was annual, but filling out a form to ask for $10 back every month seems a bit over the top. Maybe I'm a spendthrift?

Am I missing something here? Would you say I am being irresponsible with my money?

I just remembered to cancel my AMC membership. That one was definitely not helping me do my job faster, and I'm not particularly regretful of losing a few dollars.


> However, is paying $120 per year that much when it helps you in your at least mid-five-figures job? I would ask for the reimbursement if it was annual, but filling out a form to ask for $10 back every month seems a bit over the top. Maybe I'm a spendthrift?

It's a slippery slope. You can't start giving freebies to your bosses (who are almost certainly much wealthier than you are) or it'll never end, just like you can't ever pay blackmail


Any $ is too much $. I claim back $1.99 every month through the horrible SAP Concur.


i had to use that at a $prevJob. My condolences


On the flip side a company may want to buy a bulk license so that it is available for free to all their developers.

You don’t want Bob being less productive just because he didn’t want to spend $10 a month.


First of all. If I was the legal team of any company I'd tell developers to stay away from copilot, since the legal status is still undecided and microsoft has a disclaimer that any legal issues fall on the users (which is probably illegal but you'd have to sue microsoft to get it overturned).

Second… It's a work tool just like any other work tool, why should I buy it out of pocket? In the end it's to the advantage of the company if I'm faster at my job.

Now I'm thinking, precisely because it's not paid by the company but by the single user, in case there is legal action, the company might shift the blame on the developer. If they reimbursed they would have no way of claiming they weren't aware.


If it's a tool to do company's work, the company should pay for it.


You can pay yearly which is not as annoying.


This 100 times. Reimburse team members once year. Problem solved.


I reckon there's a reason why it's not available yet: legal uncertainty about the training data and generated code in a commercial context.

Right now it's only individual developers, placing the burden on them and preventing any major repercussions for Github.

This changes when (large) companies start using it, and when GitHub gives potentially copyrighed code to companies.

Personally I only use it for personal/OS projects right now, not professionally.


Are there any companies forbidding developers to use it?

If that was my role I'd totally forbid it, precisely for the reasons you indicated.

If a developer is paying on his own for it to work, who would have the legal responsibility in the end? The developer personally? Another good reason to stay away from it.


Our company is forbidding it too, for exactly the legal reasons parent posted


I see the concern here from a level perspective so I’d probably forbid it too just to be safe.

That being said…I think this line of thinking is probably mostly a nothing-burger at this point. My experience is that anything sufficiently complicated that Copilot outputs is likely to be somewhat wrong.

I’ve only really found it to be (quite) useful for speeding up small things like if statements, switches/matching, short documentation etc, which I don’t think you can copyright anyways. I wonder to what degree we can expect customization options in the future to forbid any complex code from being generated, or to constrain Copilot to helping with specific whitelisted

Perhaps, extending that last thought, there’s an ideological argument to be made that code that is so simple an AI can generate it isn’t worthy of being protected under copyright law anyways. I don’t know.


It can detect and remove any exact collisions with code from the training data now, by the way.


Would be nice, have not used it since trial because of this.


This is really cool! Here's an example of using emacs to do it. Uses tabnine for real time completion, and Copilot/Codex for more advance completions.

https://semiosis.github.io/posts/nlsh-plus-tabnine-real-time...

It uses NLSH and Cterm. https://semiosis.github.io/nlsh/ https://semiosis.github.io/cterm/


I just did an exposision of a bunch of them.

https://mullikine.github.io/posts/ai-terminals/

Also, there is ii, the fully imaginary interpreter


Fig recently shipped something related, which translates plain English into bash commands with AI: https://fig.io/user-manual/ai


I find documentation and examples of using copilot quite limited. Anyone have any good pointers? Specifically I’m interested in how you can tune copilot on a specific codebase or language.


Also interested in this, I don't think you can.

One piece of info I was able to get out of copilot devs directly in their Q&A session was that it looks at other open tabs for completion context (the example they gave being header files in C/C++, commonly open alongside implementations).

I've taken to just prototyping things in giant, single files because Copilot at least has the entire program in it's buffer (I think) to give suggestions based on.

https://github.com/orgs/community/discussions/29932#discussi...


GPT-3 codex has a limit of 8k tokens, which is roughly 32k characters - so you are limited to that much context at a maximum.

With the time it takes to return results with that much context, I wouldn't be suprised if they generally limit context to less than that though.


I'm using a slightly different method. Vimwiki diary and a code block runner (runs in another tmux window)... so it's doubling as a (markdown/html) documentation generator of all my work.

I'm actually enjoying it as it's providing a lot of context on the time and notes/discussion on every command I run. Also good for history searches as regular cli history ultimately relies on your own memory.

Still it feels like you need to already have paid your dues... (I'm 20+ years in...) .


For those having issues with copilot on vscodium, you can try this out, it's working for me now: https://prose.bentopais.pt/vscodium-and-copilot


Haha, this is great! Thank you for sharing! Though you definitely started it with that username and the subject.

My friends have been using warp.dev and claim that the AI autopilot has made them 10x as productive on the shell. I just lament that people who haven't suffered through learning shell primitives as a teenager are now as productive or more than me. In time, all our primitive skills fall to the machine. I love it.


>warp.dev

>Our GPT-3 powered AI search will convert natural language into executable shell commands. It's like GitHub Copilot, but for the terminal.

First time I'm hearing about this. Looks pretty cool. I think I already have a pretty good grasp on CLI commands, but I'll give it a shot, especially since the other features also seem interesting.


Yeah, sounded great. I just downloaded it.. hit a login screen..?! Then I read the HN comments on this page from 5 months ago, and immediately uninstalled:

https://news.ycombinator.com/item?id=30921231

The most worrying comments are those by the OP, the "founder and CEO of warp", who comes across as a liar and scammer. Super-unimpressive.


I didn't use it myself for the same reason. I offered to pay money for a login free build in those comments. Anyway, my friends do really like it.


You can already use copilot to write shell scripts.


And with copilot.vim and EDITOR=nvim and C-x C-e this means you can write at the shell!


I feel like if we don’t keep up and learn this new skill. We will soon fall behind.


Copilot is a crutch that prevents learning. You are not falling behind.

"Catching up" by using this tool will only land you in a lawsuit for copyright infringement.


This is the “spell checkers cause bad spelling” fallacy.

People learn by being told they are wrong. When you use copilot you are constantly being given examples that challenge your intuition. Maybe copilot is wrong, maybe you are wrong, either you are learning more with it on than with it off. Countless programmers get stuck in a rut writing the same bad code over and over again because nobody tells them it’s wrong. And it doesn’t matter if you’ve been programming for 1 month or 20 years, we all have something to learn.


Spell checkers do cause bad spelling, though. My spelling was once excellent (literally spelling bee kid), and after years of spellcheck, it's not only a lot worse, but I also often use the wrong word because it passed spellcheck - either because the wrong word is spelled similarly to the right word, or because the right word isn't in the spellcheck dictionary so I assumed I was wrong.

I don't know how you can tell me that my spelling has actually improved, and that I'm learning something from spellcheck other than not to worry about spelling things correctly because the computer will do it.

edit: By the same reasoning, you could argue that people are better at remembering phone numbers now because their cellphones remind them of the numbers every time they make a call. It would be a vaguely plausible theory before cellphones were widespread, but obviously false with experience.


Who copyrights individual bash commands?


No one; I'm referring generally to Copilot and similar tools. But god, who needs an AI to write their fucking shell commands?


It would be cool if it could learn to recover from failures and try other approaches until it gets the job done, and in the end verify it was correct. The security implications are huge, though.


Does anyone here use Copilot with less mainstream languages? Curious to hear what your experiences are like...


Yes, I have used it with languages like Bluespec and Lean v4, which have very little data (FOSS code on GitHub) for the model to work with.

It's nowhere near as accurate as it is when using Rust or TypeScript but it's still mostly "autocomplete, on steroids", just with fewer "oh shit" moments.


I use it for Toit (toitlang.org).

It's not perfect, but still incredible useful (and sometimes scary; in a good way).

I particularly like it for writing tests, but it's useful in normal code too.


That's funny, right before I opened HN I had just figured out how to get GitHub Copilot running in VS Code on a remote SSH server. I'm really impressed with how easy it is to install the VS Code agent and run extensions on a remote server, it feels very seamless.


What I would like would be github copilot for terminal completion.

based on my bash history and folder structure.


Has someone got this working in a notebook?

I can't wait until someone open sources a model that will really drive innovative in this space. I don't feel great about a company uploading unknown information from my filesystem as context.


Really cool. Also, a nice origin story for Skynet. /s


This claims to do Bash integration, but instead it seems to do Vim integration (I don't use Vim, but I do use Bash). Can anyone fill me in?


Since copilot support has only been implemented for a few editors (vscode, nvim, ...), the OP works around it by starting a bash shell inside the nvim editor.

Once you get to "vimshell %", you could just run bash and disable the vim keybindings.

A less hacked together solution would probably be running nvim in the background, feeding it the content from the current terminal session, intercepting the copilot suggestions, and then returning them as terminal suggestions (I'd use `tmux send-keys` and `tmux read-pane` with some regex to get the copilot results). Even less hacked together would be to implement a bash plugin to send out the necessary copilot API requests.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: