Skip to content

Commit 1386265

Browse files
author
Dan Muey
committed
Add bash helper script
1 parent 8703812 commit 1386265

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

vim-copilot-setup.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# vim-copilot-setup.sh
2+
3+
This `bash` script:
4+
5+
1. ensures this git repo is up to date locally
6+
2. checks dependencies
7+
3. then runs setup
8+
4. outputs helpful next steps.
9+
10+
First time:
11+
12+
`curl -s https://raw.githubusercontent.com/github/copilot.vim/refs/heads/release/vim-copilot-setup.sh | bash`
13+
14+
Subsequent times:
15+
16+
`~/.vim/pack/github/start/copilot.vim/vim-copilot-setup.sh`

vim-copilot-setup.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/bash
2+
3+
function starting () {
4+
echo "$1"
5+
}
6+
7+
function isdone () {
8+
echo " … done!"
9+
echo ""
10+
}
11+
12+
function warn () {
13+
level="W"
14+
15+
local caller_info=$(caller 0)
16+
if [[ $caller_info == *"die"* ]]; then
17+
level="E"
18+
fi
19+
20+
echo "[$level] $1" 1>&2
21+
}
22+
23+
function die () {
24+
warn "$1"
25+
exit -1
26+
}
27+
28+
function ensure_git () {
29+
starting "Ensuring git repo"
30+
31+
git --version
32+
if [ "$?" -ne 0 ]; then
33+
die "Install \`git\` and try again"
34+
fi
35+
36+
if [ -d ~/.vim/pack/github/start/copilot.vim ]; then
37+
git -C ~/.vim/pack/github/start/copilot.vim pull
38+
else
39+
git clone https://github.com/github/copilot.vim.git ~/.vim/pack/github/start/copilot.vim
40+
fi
41+
42+
isdone
43+
}
44+
45+
function check_prereq () {
46+
starting "Checking prereqs"
47+
48+
min_vim=9
49+
min_node=18
50+
51+
vim_ver=$(vim --version | head -n 1 | awk '{print $5}')
52+
if [[ $(echo "$vim_ver < $min_vim" | bc -l) -eq 1 ]]; then
53+
die "need vim version $min_vim or newer"
54+
fi
55+
56+
node_ver=$(node -v | awk -F. '{print $1}' | sed 's/^v//')
57+
if [[ "$node_ver" -lt "$min_node" ]]; then
58+
die "need node version $min_node or newer"
59+
fi
60+
61+
isdone
62+
}
63+
64+
function do_setup () {
65+
starting "Initializing set up"
66+
67+
vim -S ~/.vim/pack/github/start/copilot.vim/vim-copilot-setup.vim
68+
69+
isdone
70+
}
71+
72+
function run () {
73+
ensure_git
74+
check_prereq
75+
do_setup # or only do first time (if cloned) or when given --setup?
76+
77+
echo "For more info:"
78+
echo " * \`cat ~/.vim/pack/github/start/copilot.vim/doc/copilot.txt\`"
79+
echo " * \`:help copilot\` for more information."
80+
}
81+
82+
run

vim-copilot-setup.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Copilot setup

0 commit comments

Comments
 (0)