From 13862651ab1d882a7180e5da38c0ce68df2e8bcb Mon Sep 17 00:00:00 2001 From: Dan Muey Date: Thu, 31 Oct 2024 15:21:10 +0000 Subject: [PATCH] Add bash helper script --- vim-copilot-setup.md | 16 +++++++++ vim-copilot-setup.sh | 82 +++++++++++++++++++++++++++++++++++++++++++ vim-copilot-setup.vim | 1 + 3 files changed, 99 insertions(+) create mode 100644 vim-copilot-setup.md create mode 100755 vim-copilot-setup.sh create mode 100644 vim-copilot-setup.vim diff --git a/vim-copilot-setup.md b/vim-copilot-setup.md new file mode 100644 index 0000000..2e44931 --- /dev/null +++ b/vim-copilot-setup.md @@ -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` diff --git a/vim-copilot-setup.sh b/vim-copilot-setup.sh new file mode 100755 index 0000000..b4a97d4 --- /dev/null +++ b/vim-copilot-setup.sh @@ -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 diff --git a/vim-copilot-setup.vim b/vim-copilot-setup.vim new file mode 100644 index 0000000..015e6e1 --- /dev/null +++ b/vim-copilot-setup.vim @@ -0,0 +1 @@ +Copilot setup