feat: add vim-zig

This commit is contained in:
AJ ONeal
2023-11-01 23:24:18 -06:00
parent 8bf2fffa1a
commit 81d2eb4288
5 changed files with 233 additions and 0 deletions

45
vim-zig/README.md Normal file
View File

@@ -0,0 +1,45 @@
---
title: vim-zig
homepage: https://github.com/ziglang/zig.vim
tagline: |
vim-zig (zig.vim) adds zig language support for Vim.
---
To update (replacing the current version) run `webi vim-zig`.
## Cheat Sheet
> `vim-zig` provides integration with `zls`, `zig fmt`, and other zig tooling.
You'll also need to install [`ALE`](https://webinstall.dev/vim-ale) (part of
[`vim-essentials`](https://webinstall.dev/vim-essentials)) or
[`syntastic`](https://webinstall.dev/vim-syntastic) first.
### Files
```text
~/.vim/pack/plugins/start/zig.vim/
~/.vim/plugins/start/zig.vim
```
### How to install and configure by hand
1. Remove the previous version of zig.vim, if any:
```sh
rm -rf ~/.vim/pack/plugins/start/zig.vim
```
2. Install `zig.vim` as a Vim8 package with `git`:
```sh
mkdir -p ~/.vim/pack/plugins/start/
git clone --depth=1 --single-branch master \
https://github.com/zig-lang/zig.vim \
~/.vim/pack/plugins/start/zig.vim
```
3. Create `~/.vim/plugins/zig.vim`, as follows:
```vim
" Reasonable defaults for zig.vim
" run zig fmt on save
let g:zig_fmt_autosave = 1
```

107
vim-zig/install.ps1 Normal file
View File

@@ -0,0 +1,107 @@
#!/usr/bin/env pwsh
IF ($null -eq $Env:WEBI_HOST -or "" -eq $Env:WEBI_HOST) {
$Env:WEBI_HOST = "https://webinstall.dev"
}
#############################
# Install vim-zig (zig.vim) #
#############################
# ~/.vim/plugins/<vim-name>.vim
$my_vim_confname = "zig.vim"
# ~/.vim/pack/plugins/start/<vim-plugin>/
$my_vim_plugin = "zig.vim"
# Non-executable packages should define these variables
$pkg_cmd_name = "${my_vim_plugin}"
$pkg_no_exec = $true
$pkg_src = "$HOME\Downloads\webi\$Env:WEBI_PKG_PATHNAME"
$pkg_dst = "$HOME\.vim\pack\plugins\start\$my_vim_plugin"
function fn_vim_init {
if (-Not (Test-Path "$HOME\.vimrc")) {
New-Item -ItemType File -Path "$HOME\.vimrc"
}
New-Item -ItemType Directory -Force `
-Path "$HOME\.vim\pack\plugins\start" | Out-Null
New-Item -ItemType Directory -Force `
-Path "$HOME\.vim\plugins" | Out-Null
}
function fn_git_shallow_clone {
IF (Test-Path -Path "$pkg_src") {
Write-Host "Found $pkg_src"
Return
}
Write-Output "Checking for Git..."
IF (-Not (Get-Command -Name "git" -ErrorAction Silent)) {
& "$HOME\.local\bin\webi-pwsh.ps1" git
$Env:Path = "$HOME\.local\opt\git\cmd;$Env:Path"
[System.Environment]::SetEnvironmentVariable(
"Path",
$env:Path,
[System.EnvironmentVariableTarget]::User)
}
Write-Output "Cloning $Env:PKG_NAME from $Env:WEBI_PKG_URL to $pkg_src"
$my_rnd = (Get-Random -Maximum 4294967295 -Minimum 65535).toString("X")
$my_tmp = "$pkg_src.$my_rnd.part"
& git clone --config advice.detachedHead=false --quiet `
--depth=1 --single-branch --branch "$Env:WEBI_GIT_TAG" `
"$Env:WEBI_PKG_URL" `
"$my_tmp"
Move-Item "$my_tmp" "$pkg_src"
}
function fn_remove_existing {
Remove-Item -Recurse -Force `
-Path "$pkg_dst" | Out-Null
}
function fn_install {
Copy-Item -Path "$pkg_src" -Destination "$pkg_dst" -Recurse
}
function fn_vim_config_download {
$my_vim_confpath = "$HOME\.vim\plugins\$my_vim_confname"
IF (Test-Path -Path "$my_vim_confpath") {
Write-Host "Found $my_vim_confpath"
Return
}
& curl.exe -sS -o "$my_vim_confpath" `
"$Env:WEBI_HOST/packages/${Env:PKG_NAME}/${my_vim_confname}"
}
function fn_vim_config_update {
$my_vim_confpath = "$HOME\.vim\plugin\$my_vim_confname"
Write-Host ''
Write-Host 'MANUAL SETUP REQUIRED' `
-ForegroundColor yellow -BackgroundColor black
Write-Host ''
Write-Host "Add the following to ~/.vimrc:" `
-ForegroundColor magenta -BackgroundColor white
Write-Host " source $my_vim_confpath" `
-ForegroundColor magenta -BackgroundColor white
Write-Host ''
# TODO manually add
#$my_note="$Env:PKG_NAME: installed via webinstall.dev/$Env:PKG_NAME"
}
function main {
fn_vim_init
fn_git_shallow_clone
fn_remove_existing
fn_install
fn_vim_config_download
fn_vim_config_update
}
main

60
vim-zig/install.sh Normal file
View File

@@ -0,0 +1,60 @@
#!/bin/sh
set -e
set -u
fn_vim_init() { (
if ! test -f ~/.vimrc; then
touch ~/.vimrc
fi
mkdir -p ~/.vim/pack/plugins/start/
mkdir -p ~/.vim/plugins/
); }
__install_vim_plugin() {
# ~/.vim/plugins/<vim-name>.vim
my_vim_confname="zig.vim"
# ~/.vim/pack/plugins/start/<vim-plugin>/
my_vim_plugin="zig.vim"
# as opposed to PKG_NAME-<version> / WEBI_PKG_PATHNAME:
# ~/Downloads/webi/<PKG_NAME>-<version>/
# Non-executable packages should define these variables
pkg_cmd_name="${my_vim_plugin}"
pkg_no_exec=true
pkg_dst="${HOME}/.vim/pack/plugins/start/${my_vim_plugin}"
pkg_install() { (
fn_vim_init
rm -rf ~/.vim/pack/plugins/start/"${my_vim_plugin}"/
mv ./"${WEBI_PKG_PATHNAME}"/ ~/.vim/pack/plugins/start/"${my_vim_plugin}"
); }
pkg_post_install() { (
mkdir -p ~/.vim/plugins
if [ -f ~/.vim/plugins/"${my_vim_confname}" ]; then
echo "Found ~/.vim/plugins/${my_vim_confname}"
else
webi_download \
"${WEBI_HOST}/packages/${PKG_NAME}/${my_vim_confname}" \
~/.vim/plugins/"${my_vim_confname}" \
"${my_vim_confname}"
fi
if ! grep "source.*plugins.${my_vim_confname}" -r ~/.vimrc > /dev/null 2> /dev/null; then
my_note="${my_vim_plugin}: installed via webinstall.dev/${PKG_NAME}"
set +e
printf '\n" %s\n' "${my_note}" >> ~/.vimrc
printf 'source ~/.vim/plugins/%s\n' "${my_vim_confname}" >> ~/.vimrc
set -e
echo "Updated ~/.vimrc to 'source ~/.vim/plugins/${my_vim_confname}'"
fi
echo ""
); }
}
__install_vim_plugin

19
vim-zig/releases.js Normal file
View File

@@ -0,0 +1,19 @@
'use strict';
var git = require('../_common/git-tag.js');
var gitUrl = 'https://github.com/ziglang/zig.vim.git';
module.exports = async function (request) {
let all = await git(gitUrl);
return all;
};
if (module === require.main) {
module.exports(require('@root/request')).then(function (all) {
all = require('../_webi/normalize.js')(all);
let samples = JSON.stringify(all, null, 2);
console.info(samples);
});
}

2
vim-zig/zig.vim Normal file
View File

@@ -0,0 +1,2 @@
" Example of disabling fmt on save
"let g:zig_fmt_autosave = 0