• Stars
    star
    498
  • Rank 87,864 (Top 2 %)
  • Language
  • Created about 2 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Hack to get Github Copilot working in the terminal with bash

Github Copilot in the Terminal (bash)

copilot-in-the-terminal

So you got tired of AI just suggesting code edits, and now you want it to help you run code, too. Silly human, you have come to the right place. This will take five steps.

This is a hacky solution to allow for copilot suggestions to work in the terminal by treating neovim as a thin shell-around-a-shell.

Installing

I use Astro Vim, so the code snippets below may need slightly different syntax depending on your neovim setup!

  1. You will want to install and get Github Copilot working with neovim.
  2. The configuration for accepting copilot's autocomplete looks a bit like this:

In ~/.config/nvim/init.lua, set a desired keymap:

vim.api.nvim_set_keymap("!", "<C-]>", 'copilot#Accept("<CR>")', { silent = true, expr = true, noremap=true })
vim.api.nvim_set_var('copilot_assume_mapped', true)
  1. You will want to install the following three plugins (special credit to Shougo, the real legend!!!):

In ~/.config/nvim/lua/core/plugins.lua:

  ["Shougo/vimproc.vim"] = {},
  ["Shougo/vimshell.vim"] = {}, 
  ["Shougo/unite.vim"] = {},

Edit: or replace Shougo/vimshell.vim with maxwell-bland/vimshell-copilot.vim and skip step 5 below. (vimshell-copilot.vim also includes bash scripting ergonomic improvements.)

  1. Build vimproc!
cd ~/.local/share/nvim/site/pack/packer/start/vimproc.vim
make
  1. Remove the key mapping conflicts with vimshell!
vim ~/.local/share/nvim/site/pack/packer/start/vimshell.vim/autoload/vimshell/mappings.vim

and comment out (or remap) the overloaded mappings on line 155, change the following

inoremap <expr> <SID>(bs-ctrl-])
      \ getline('.')[col('.') - 2] ==# "\<C-]>" ? "\<BS>" : ''
imap <buffer> <C-]>               <C-]><SID>(bs-ctrl-])
imap <buffer> <CR>                <C-]><Plug>(vimshell_enter)

to the following

" inoremap <expr> <SID>(bs-ctrl-])
"       \ getline('.')[col('.') - 2] ==# "\<C-]>" ? "\<BS>" : ''
" imap <buffer> <C-]>               <C-]><SID>(bs-ctrl-])
imap <buffer> <CR>                <Plug>(vimshell_enter)

Running

Open up a new vim session and type :VimShell. Github copilot's autocomplete will now work in your bash shell. Here's an example I came up with, where I typed in echo a random and cat, then autocompleted the rest.

vimshell% # echo a random number between 1 and 10
vimshell% cat /dev/urandom | od -N 1 -An -i | awk '{print $1 % 10 + 1}'

Conclusion and a Warning

Alright, my 1337 buddy. As you know, Copilot will start learning from the commands you have executed in the current session, and the output. Don't leak anything too secret, haha. Roko's Basilisk thanks you and sees all.

More Repositories

1

i3-natural-scrolling-and-tap

The above is a script that uses an alternate method to enable natural scrolling and tap-to-click on machines running the i3 window manager. This was created after a realization that, for machines that do not use a synaptics touchpad, the easily googlable solutions to enable natural scrolling are not applicable: these include modifying .Xmodmap (not universal) and using synclient (also not universal).
Shell
54
star
2

scapy-MITM

Small python script using Scapy to do ARP poisoning and redirection of IP addresses using iptables to perform a MITM attack. Used for https://www.youtube.com/watch?v=66x3vfac8rA
Python
8
star
3

pdf-latin-text-encodings

Table with StandardEncoding MacRomanEncoding WinAnsiEncoding and PDFDocEncoding values for every character you could ever want.
Python
3
star
4

ucsd-lab-botnet

Old script for (illegally? legally.) using the undergraduate lab computers at UCSD as a beowulf cluster.
Shell
3
star
5

deredaction

Artifact for PETS 2023 "Story Beyond the Eye: Glyph Positions Break PDF Text Redaction"
C++
3
star
6

ring-oscillator

Implementation of a ring oscillator in VHDL.
TeX
2
star
7

glotch

An image manipulation software that purposefully 'glitches' images in order to create computer generated art
Python
2
star
8

vimshell-copilot.vim

Modifications to VimShell, adding copilot and bash command support.
Vim Script
2
star
9

indexof-pdf-scraper

Traverses (scrapes) "index of" style web directories for PDF files.
Python
1
star
10

grok

A gentle introduction to using Rosette for program verification.
Racket
1
star
11

thesis-propsal

TeX
1
star
12

dissertation

WIP Writing towards Ph.D. Dissertation
TeX
1
star
13

automatic-exploit-generation-llms

How to perform automatic exploit generation using GPT4 / LLMs.
Shell
1
star
14

x86-Protected-Mode-Angr

x86 protected mode support for angr
Python
1
star
15

Android-Snippets

Android Application code for Bluetooth and Wifi Scanning, for geolocation, for google drive integration, for multipart form uploads, and for remote outside-of-store application updates.
Java
1
star
16

maxwell-bland

1
star
17

integreat

This is a never-finished project aimed at providing a toolkit and language for writing decompilers. This also serves as a high-level bridge for program analysis procedures leveraging ghidra_bridge as a Python API and analyzers for Ghidra's Clang/angr's recovered ASTs. I am using this as a basis for some other (closed source) research projects; random pull requests are welcome.
TeX
1
star
18

yAFL

Yet another AFL: around 300ish lines of code to create an architecture-independent and easy to use system mode QEMU fuzzer, along the lines of triforce AFL and FirmAFL; version two of the jetset fuzzer, used to hack Boeing 737 components. Note: we are fixing a last bug relating to timing during the VM state restore, then we will hit the first release.
C
1
star