Skip to content

Commit

Permalink
add fetch script for neovim, workaround antivirus
Browse files Browse the repository at this point in the history
* antivirus workaround by deleting templates/powershell
  • Loading branch information
matu3ba committed Jan 7, 2025
1 parent db04ba9 commit 5f856f6
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 324 deletions.
6 changes: 6 additions & 0 deletions .config/shells/aliases_git
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,12 @@ alias gsu='git submodule update'
# 3. rebase and merge + push
# git rebase master feature && git fetch . feature:master
# git rebase master feature && git fetch . feature:master && git push upstream master:master
# 4. git recording of resolved conflicts
# git rerere
# git config rerere.enabled true
# git worktree add scratch @
# git -C scratch merge feature
# git worktree remove -f scratch

#====checks
#has git: git rev-parse --is-inside-work-tree
Expand Down
202 changes: 135 additions & 67 deletions scr/fetchNeovim.ps1
Original file line number Diff line number Diff line change
@@ -1,68 +1,136 @@
Write-Output "TODO: adjust or build neovim from source with clang or msvc"
exit 1
# idea once merged: build from source with zig https://github.com/neovim/neovim/pull/28344
$NEOVIM_RELEASES_URL = "https://api.github.com/repos/neovim/neovim/releases"
$NEOVIM_TMP_DIR = "$HOME\tmp"
$NEOVIM_URL_ZIP = "https://github.com/neovim/neovim/releases/download/nightly/nvim-win64.zip"
$VERSION = "0.12.0"
function CheckLastExitCode {
param ( [string] $pwd)
if (!$?) {
Set-Location -Path "$pwd"
exit 1
}
return 0
}
function IfExistDelFile {
param ( [string] $filepath, [string] $pwd)
if (Test-Path "$filepath") {
Write-Output "Removing $filepath.."
Remove-Item -Path "$filepath"
CheckLastExitCode($pwd)
} else {
Write-Output "Nonexist $filepath.."
}
}
function IfExistDelDir {
param ( [string] $dirpath, [string] $pwd)
if (Test-Path "$dirpath") {
Remove-Item -Path "$dirpath" -Recurse -Force
CheckLastExitCode($pwd)
} else {
Write-Output "Nonexist $dirpath.."
}
}
function MoveNvimItem {
param (
[string] $unzip_target
, [string] $target_path
, [string] $itempath
, [string] $pwd
)
# Write-Output "1 $unzip_target, 2 $target_path, 3 $itempath, 4 $pwd, $HOME\tmp\"
# Write-Output "$HOME\tmp\$unzip_target\$itempath pa2 $target_path\$itempath"
[string] $unzippath = "$HOME\tmp\$unzip_target"
[string] $src = "$unzippath\$itempath"
[string] $dest = "$target_path\$itempath"
Write-Output "in MoveNvimItem: $src $dest"
Move-Item -Path "$src" -Destination "$dest"
CheckLastExitCode($pwd)
}
function MoveUnpackedNeovim {
param (
[string] $unzip_target
, [string] $target_path
, [string] $pwd
)
Write-Output "$unzip_target, $target_path"
Write-Output "bin\cat.exe $pwd"
MoveNvimItem $unzip_target $target_path 'bin\cat.exe' $pwd
MoveNvimItem $unzip_target $target_path 'bin\dbghelp.dll' $pwd
MoveNvimItem $unzip_target $target_path 'bin\lua51.dll' $pwd
MoveNvimItem $unzip_target $target_path 'bin\nvim.exe' $pwd
MoveNvimItem $unzip_target $target_path 'bin\nvim.pdb' $pwd
MoveNvimItem $unzip_target $target_path 'bin\tee.exe' $pwd
MoveNvimItem $unzip_target $target_path 'bin\win32yank.exe' $pwd
MoveNvimItem $unzip_target $target_path 'bin\xxd.exe' $pwd
MoveNvimItem $unzip_target $target_path 'lib\nvim' $pwd
MoveNvimItem $unzip_target $target_path 'share\applications' $pwd
MoveNvimItem $unzip_target $target_path 'share\locale' $pwd
MoveNvimItem $unzip_target $target_path 'share\man' $pwd
MoveNvimItem $unzip_target $target_path 'share\nvim' $pwd
}

# $ZIG_URL_JSON = "https://ziglang.org/download/index.json"
# $ZIG_TMP_DIR = "$HOME\tmp"
#
# function CheckLastExitCode ($pwd) {
# if (!$?) {
# Set-Location -Path "$pwd"
# exit 1
# }
# return 0
# }
#
# $PWD = Get-Location
# Write-Output "$PWD"
#
# Set-Location -Path "$HOME"
#
# if (!(Test-Path "$ZIG_TMP_DIR")) {
# New-Item -Path "$ZIG_TMP_DIR" -ItemType Directory
# }
#
# $ZIG_BUILDS = Invoke-RestMethod -Uri "$ZIG_URL_JSON"
# CheckLastExitCode($PWD)
# $ZIG_TARBALL = $ZIG_BUILDS.master."x86_64-windows".tarball
# Write-Output $ZIG_BUILDS.master."x86_64-windows".tarball
# Write-Output $ZIG_BUILDS.master."x86_64-windows".shasum
# Write-Output $ZIG_BUILDS.master."x86_64-windows".size
# $ZIP_TARGET = Split-Path -Leaf $ZIG_TARBALL
# $ZIP_TARGET_BASENAME = Split-Path -LeafBase $ZIP_TARGET
#
# $UNZIP_TARGET_ZIG = "$ZIG_TMP_DIR\$ZIP_TARGET_BASENAME\zig.exe"
# $UNZIP_TARGET_LIB = "$ZIG_TMP_DIR\$ZIP_TARGET_BASENAME\lib"
#
# Write-Output "unzip zig: $UNZIP_TARGET_ZIG"
# Write-Output "unzip lib: $UNZIP_TARGET_LIB"
#
# if (Test-Path "$ZIG_TMP_DIR\$ZIP_TARGET") {
# Write-Output "Zig already up to date"
# Set-Location -Path "$PWD"
# exit 0
# } else {
# Write-Output "Zig not up to date, fetching zip into $ZIG_TMP_DIR\$ZIP_TARGET"
# }
# Invoke-WebRequest -Uri "$ZIG_TARBALL" -OutFile "$ZIG_TMP_DIR\$ZIP_TARGET"
# CheckLastExitCode($PWD)
#
# Write-Output "Deleting old Zig instance.."
# Remove-Item -Path "$HOME\bin\zig.exe" -ErrorAction Ignore
# Remove-Item -Path "$HOME\bin\lib" -Recurse -Force -ErrorAction Ignore
# CheckLastExitCode($PWD)
#
# Write-Output "Unpacking $ZIG_TMP_DIR\$ZIP_TARGET .."
#
# Add-Type -AssemblyName System.IO.Compression.FileSystem ;
# [System.IO.Compression.ZipFile]::ExtractToDirectory("$ZIG_TMP_DIR\$ZIP_TARGET", "$ZIG_TMP_DIR\")
# CheckLastExitCode($PWD)
#
# # move unpacked zig and lib to "$HOME\bin"
# Move-Item -Path "$UNZIP_TARGET_ZIG" -Destination "$HOME\bin"
# CheckLastExitCode($PWD)
# Move-Item -Path "$UNZIP_TARGET_LIB" -Destination "$HOME\bin"
# CheckLastExitCode($PWD)
#
# Write-Output "Unpacking finished, Zig was updated."
# Set-Location -Path "$PWD"
# exit 0
$PWD = Get-Location
Write-Output "$PWD"
Set-Location -Path "$HOME"
if (!(Test-Path "$NEOVIM_TMP_DIR")) {
New-Item -Path "$NEOVIM_TMP_DIR" -ItemType Directory
}

if (Get-Process -ProcessName nvim -ErrorAction SilentlyContinue) {
Write-Output "there exist opened nvim instances, exiting.."
Set-Location -Path "$PWD"
exit 2
}
$neovim_release_json = $(Invoke-WebRequest $NEOVIM_RELEASES_URL | convertfrom-json)
CheckLastExitCode($PWD)
if ($neovim_release_json[0]."tag_name" -ne "nightly") {
Write-Output "did not find tag nightly"
Set-Location -Path "$PWD"
exit 3
}
$COMMIT = $neovim_release_json[0]."target_commitish"
$zip_target = "nvim-windows-x86_64-$VERSION-$COMMIT.zip"
$unzip_target = "nvim-windows-x86_64-$VERSION-$COMMIT"

if (Test-Path "$NEOVIM_TMP_DIR\$zip_target") {
Write-Output "Neovim already up to date"
Set-Location -Path "$PWD"
exit 0
} else {
Write-Output "Neovim not up to date, fetching zip into $NEOVIM_TMP_DIR\$zip_target"
Invoke-WebRequest -Uri "$NEOVIM_URL_ZIP" -OutFile "$NEOVIM_TMP_DIR\$zip_target"
CheckLastExitCode($PWD)
}

Write-Output "Deleting old Neovim instance.."
IfExistDelFile "$HOME\.local\bin\cat.exe" $PWD
IfExistDelFile "$HOME\.local\bin\dbghelp.dll" $PWD
IfExistDelFile "$HOME\.local\bin\lua51.dll" $PWD
IfExistDelFile "$HOME\.local\bin\nvim.exe" $PWD
IfExistDelFile "$HOME\.local\bin\nvim.pdb" $PWD
IfExistDelFile "$HOME\.local\bin\tee.exe" $PWD
IfExistDelFile "$HOME\.local\bin\win32yank.exe" $PWD
IfExistDelFile "$HOME\.local\bin\xxd.exe" $PWD
IfExistDelDir "$HOME\.local\lib\nvim" $PWD
IfExistDelDir "$HOME\.local\share\applications" $PWD
IfExistDelDir "$HOME\.local\share\locale" $PWD
IfExistDelDir "$HOME\.local\share\man" $PWD
IfExistDelDir "$HOME\.local\share\nvim" $PWD

$zip_target = "nvim-windows-x86_64-0.12.0-e27f7125d66f6026adacbbad00bbf6e66a6ba883.zip"
$unzip_target = "nvim-windows-x86_64-0.12.0-e27f7125d66f6026adacbbad00bbf6e66a6ba883"
Write-Output "Unpacking $NEOVIM_TMP_DIR\$zip_target .."
New-Item -Path "$NEOVIM_TMP_DIR\$unzip_target" -ItemType Directory
CheckLastExitCode($PWD)
Expand-Archive -Path "$NEOVIM_TMP_DIR\$zip_target" -DestinationPath "$NEOVIM_TMP_DIR\$unzip_target"
CheckLastExitCode($PWD)
Move-Item -Path "$NEOVIM_TMP_DIR\$unzip_target\nvim-win64\*" -Destination "$NEOVIM_TMP_DIR\$unzip_target"
CheckLastExitCode($PWD)
Remove-Item -Path "$NEOVIM_TMP_DIR\$unzip_target\nvim-win64" -Recurse -Force
CheckLastExitCode($PWD)

MoveUnpackedNeovim $unzip_target "$HOME\.local" $PWD

Write-Output "Unpacking finished, Zig was updated."
Set-Location -Path "$PWD"
exit 0
7 changes: 1 addition & 6 deletions scr/fetchZig.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@ function CheckLastExitCode ($pwd) {
}
return 0
}

$PWD = Get-Location
Write-Output "$PWD"

Set-Location -Path "$HOME"

if (!(Test-Path "$ZIG_TMP_DIR")) {
New-Item -Path "$ZIG_TMP_DIR" -ItemType Directory
}
Expand All @@ -29,7 +26,6 @@ $ZIP_TARGET_BASENAME = Split-Path -LeafBase $ZIP_TARGET

$UNZIP_TARGET_ZIG = "$ZIG_TMP_DIR\$ZIP_TARGET_BASENAME\zig.exe"
$UNZIP_TARGET_LIB = "$ZIG_TMP_DIR\$ZIP_TARGET_BASENAME\lib"

Write-Output "unzip zig: $UNZIP_TARGET_ZIG"
Write-Output "unzip lib: $UNZIP_TARGET_LIB"

Expand All @@ -49,7 +45,6 @@ Remove-Item -Path "$HOME\bin\lib" -Recurse -Force -ErrorAction Ignore
CheckLastExitCode($PWD)

Write-Output "Unpacking $ZIG_TMP_DIR\$ZIP_TARGET .."

Add-Type -AssemblyName System.IO.Compression.FileSystem ;
[System.IO.Compression.ZipFile]::ExtractToDirectory("$ZIG_TMP_DIR\$ZIP_TARGET", "$ZIG_TMP_DIR\")
CheckLastExitCode($PWD)
Expand All @@ -62,4 +57,4 @@ CheckLastExitCode($PWD)

Write-Output "Unpacking finished, Zig was updated."
Set-Location -Path "$PWD"
exit 0
exit 0
1 change: 1 addition & 0 deletions templates/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ static_assert(__cplusplus >= 201402L, "require c++14 for sanity");
// - replace #define with 'static constexpr' and 'auto lambda_fn = [](auto ..) {}'
// - templates instead of type params (or write out coercible types): template <typename T> T square(T n) { return n * n; }
// - constexpr/consteval if and SFINAE (ie std::enable_if or concepts)
// - TODO explain ADL
// - variadic templates instead of macro ellipsis/VA_ARGS
// template <typename... Args>
// void printValues(Args&&... args) {
Expand Down
6 changes: 6 additions & 0 deletions templates/common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
# https://4sysops.com/archives/measure-object-computing-the-size-of-folders-and-files-in-powershell/
# https://www.gngrninja.com/script-ninja/2016/5/24/powershell-calculating-folder-sizes

# SHENNANIGAN
# , is join operator which may silently work or break the program
# worse, C# code calls use C# syntax ie
# Add-Type -AssemblyName System.IO.Compression.FileSystem ;
# [System.IO.Compression.ZipFile]::ExtractToDirectory("$NEOVIM_TMP_DIR\$zip_target", "$NEOVIM_TMP_DIR\")

# ====common_paths
# echo $profile shows powershell configuration
# $HOME\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
Expand Down
Loading

0 comments on commit 5f856f6

Please sign in to comment.