Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bash helper script #44

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions vim-copilot-setup.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# vim-copilot-setup.sh

This `bash` script:

1. ensures this git repo is up to date locally
2. checks dependencies
3. then runs setup
4. outputs helpful next steps.

First time:

`curl -s https://raw.githubusercontent.com/github/copilot.vim/refs/heads/release/vim-copilot-setup.sh | bash`

Subsequent times:

`~/.vim/pack/github/start/copilot.vim/vim-copilot-setup.sh`
82 changes: 82 additions & 0 deletions vim-copilot-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/bash

function starting () {
echo "$1 …"
}

function isdone () {
echo " … done!"
echo ""
}

function warn () {
level="W"

local caller_info=$(caller 0)
if [[ $caller_info == *"die"* ]]; then
level="E"
fi

echo "[$level] $1" 1>&2
}

function die () {
warn "$1"
exit -1
}

function ensure_git () {
starting "Ensuring git repo"

git --version
if [ "$?" -ne 0 ]; then
die "Install \`git\` and try again"
fi

if [ -d ~/.vim/pack/github/start/copilot.vim ]; then
git -C ~/.vim/pack/github/start/copilot.vim pull
else
git clone https://github.com/github/copilot.vim.git ~/.vim/pack/github/start/copilot.vim
fi

isdone
}

function check_prereq () {
starting "Checking prereqs"

min_vim=9
min_node=18

vim_ver=$(vim --version | head -n 1 | awk '{print $5}')
if [[ $(echo "$vim_ver < $min_vim" | bc -l) -eq 1 ]]; then
die "need vim version $min_vim or newer"
fi

node_ver=$(node -v | awk -F. '{print $1}' | sed 's/^v//')
if [[ "$node_ver" -lt "$min_node" ]]; then
die "need node version $min_node or newer"
fi

isdone
}

function do_setup () {
starting "Initializing set up"

vim -S ~/.vim/pack/github/start/copilot.vim/vim-copilot-setup.vim

isdone
}

function run () {
ensure_git
check_prereq
do_setup # or only do first time (if cloned) or when given --setup?

echo "For more info:"
echo " * \`cat ~/.vim/pack/github/start/copilot.vim/doc/copilot.txt\`"
echo " * \`:help copilot\` for more information."
}

run
1 change: 1 addition & 0 deletions vim-copilot-setup.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Copilot setup