From 16e1bc033aa14ec515503127fdd0d2c2df05b08e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20=E9=87=91=E5=8F=AF=E6=98=8E?= Date: Wed, 1 May 2024 20:01:43 +0200 Subject: [PATCH] feat: implement `g:doge_install_path` option --- README.md | 8 ++++++++ autoload/doge.vim | 17 ++++++++--------- doc/doge.txt | 5 +++++ plugin/doge.vim | 24 ++++++++++++++++-------- scripts/install.ps1 | 19 +++++++++++-------- scripts/install.sh | 16 +++++++++------- 6 files changed, 57 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index 37743532..a6a8f075 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ on a function, press `d`, jump quickly through `TODO` items using - [Configuration](#configuration) * [Choosing a different doc standard](#choosing-a-different-doc-standard) * [Options](#options) + + [`g:doge_install_path`](#gdoge_install_path) + [`g:doge_enable_mappings`](#gdoge_enable_mappings) + [`g:doge_mapping`](#gdoge_mapping) + [`g:doge_filetype_aliases`](#gdoge_filetype_aliases) @@ -180,6 +181,13 @@ Here is the full list of available doc standards per filetype: ## Options +### `g:doge_install_path` + +Default: `/path/to/vim-doge` + +The path where the bin/ directory will be installed and loaded from. Can be +useful if your system is read-only or uses immutable datastructures. + ### `g:doge_enable_mappings` Default: `1` diff --git a/autoload/doge.vim b/autoload/doge.vim index 50d606d0..fac558cc 100644 --- a/autoload/doge.vim +++ b/autoload/doge.vim @@ -9,14 +9,13 @@ let s:comment_placeholder = doge#utils#placeholder() " actual docblock to be inserted later on. function! doge#run_parser() abort let l:executables = [ - \ '/helper/target/release/vim-doge-helper.exe', - \ '/helper/target/release/vim-doge-helper', - \ '/bin/vim-doge-helper.exe', - \ '/bin/vim-doge-helper' + \ g:doge_dir . '/helper/target/release/vim-doge-helper.exe', + \ g:doge_dir . '/helper/target/release/vim-doge-helper', + \ g:doge_install_path . '/bin/vim-doge-helper.exe', + \ g:doge_install_path . '/bin/vim-doge-helper' \ ] - for l:executable in l:executables - let l:script_path = g:doge_dir . l:executable + for l:script_path in l:executables if filereadable(resolve(l:script_path)) let l:cursor_pos = getpos('.') let l:current_line = l:cursor_pos[1] @@ -255,7 +254,7 @@ endfunction " Install the necessary dependencies. function! doge#install(...) abort for l:filename in ['vim-doge-helper', 'vim-doge-helper.exe'] - let l:filepath = g:doge_dir . '/bin/' . l:filename + let l:filepath = g:doge_install_path . '/bin/' . l:filename if filereadable(l:filepath) let l:binary_version = split(doge#utils#trim(system(shellescape(l:filepath) . ' --version')), ' ')[1] let l:local_version = doge#utils#trim(readfile(g:doge_dir . '/.version')[0]) @@ -278,10 +277,10 @@ function! doge#install(...) abort if has('win32') let l:command = (executable('pwsh.exe') ? 'pwsh.exe' : 'powershell.exe') - let l:command .= ' -Command ' . shellescape('Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process -Force; & ' . shellescape(g:doge_dir . '/scripts/install.ps1')) + let l:command .= ' -Command ' . shellescape('Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process -Force; & ' . shellescape(g:doge_dir . '/scripts/install.ps1')) . ' ' . shellescape(g:doge_install_path) let l:term_height = 8 else - let l:command = fnameescape(g:doge_dir) . '/scripts/install.sh' + let l:command = shellescape(g:doge_dir . '/scripts/install.sh') . ' ' . shellescape(g:doge_install_path) let l:term_height = 4 endif diff --git a/doc/doge.txt b/doc/doge.txt index ca66a8ad..1455527e 100644 --- a/doc/doge.txt +++ b/doc/doge.txt @@ -24,6 +24,11 @@ coding! ============================================================================== CONFIGURATION *doge-config* + *g:doge_install_path* +(Default: /path/to/vim-doge) + +The path where the bin/ directory will be installed and loaded from. + *g:doge_enable_mappings* (Default: 1) diff --git a/plugin/doge.vim b/plugin/doge.vim index 6eae9e62..c0d96f69 100644 --- a/plugin/doge.vim +++ b/plugin/doge.vim @@ -19,6 +19,14 @@ if has('nvim') && !has('nvim-0.3.2') finish endif +if has('win32') && &shellslash + set noshellslash + let g:doge_dir = resolve(expand(':p:h:h')) + set shellslash +else + let g:doge_dir = resolve(expand(':p:h:h')) +endif + " section Introduction, intro {{{ "" @@ -50,6 +58,14 @@ if exists('g:loaded_doge') endif let g:loaded_doge = 1 +if !exists('g:doge_install_path') + "" + " (Default: /path/to/vim-doge) + " + " The path where the bin/ directory will be installed and loaded from. + let g:doge_install_path = g:doge_dir +endif + if !exists('g:doge_enable_mappings') "" " (Default: 1) @@ -189,14 +205,6 @@ if g:doge_enable_mappings == v:true endif unlet s:mode -if has('win32') && &shellslash - set noshellslash - let g:doge_dir = resolve(expand(':p:h:h')) - set shellslash -else - let g:doge_dir = resolve(expand(':p:h:h')) -endif - "" " @command DogeGenerate {doc_standard} " Command to generate documentation. The `{doc_standard}` accepts a count or a diff --git a/scripts/install.ps1 b/scripts/install.ps1 index 7c447c00..b232703d 100644 --- a/scripts/install.ps1 +++ b/scripts/install.ps1 @@ -1,4 +1,8 @@ -Write-Host "[vim-doge] Preparing to download vim-doge-helper binary..." +$InstallDir = $args[0] +$BinDir = "$InstallDir\bin" +$OutFile = "$BinDir\vim-doge-helper.exe" + +Write-Host "Installation path: $OutFile" $Arch = $env:PROCESSOR_ARCHITECTURE if ($Arch -eq 'x86') { @@ -10,16 +14,15 @@ else { $AssetName = "vim-doge-helper-windows-x86_64.zip" } -$RootDir = Resolve-Path -Path ((Split-Path $myInvocation.MyCommand.Path) + "\..") +$RootDir = Resolve-Path -Path ((Split-Path $MyInvocation.MyCommand.Path) + "\..") $AppVersion = Get-Content "$RootDir\.version" $AssetPath = "$RootDir\bin\$AssetName" -$OutFile = "$RootDir\bin\vim-doge-helper.exe" $DownloadUrl = "https://github.com/kkoomen/vim-doge/releases/download/v$AppVersion/$AssetName" -if (Test-Path $AssetName) { - Remove-Item "$AssetName" +if (Test-Path $AssetPath) { + Remove-Item "$AssetPath" } if (Test-Path $OutFile) { @@ -35,7 +38,7 @@ try { } Invoke-WebRequest -Uri $DownloadUrl -OutFile ( New-Item -Path "$AssetPath" -Force ) -Expand-Archive -LiteralPath "$AssetPath" -DestinationPath "$RootDir.\bin" -Remove-Item "$AssetPath" +Expand-Archive -LiteralPath $AssetPath -DestinationPath $BinDir +Remove-Item $AssetPath -Write-Host "[vim-doge] Successfully downloaded vim-doge-helper" +Write-Host "Successfully downloaded vim-doge-helper" diff --git a/scripts/install.sh b/scripts/install.sh index 92cd7714..7316730a 100755 --- a/scripts/install.sh +++ b/scripts/install.sh @@ -12,7 +12,11 @@ if ! which curl > /dev/null 2>&1; then fi ROOT_DIR=$(cd "$(dirname "$0")/.."; pwd -P) -OUTFILE="./bin/vim-doge-helper" +INSTALL_DIR="${1:-$ROOT_DIR}" +BIN_DIR="$INSTALL_DIR/bin" +OUTFILE="$BIN_DIR/vim-doge-helper" + +echo "Installation path: $OUTFILE" cd "$ROOT_DIR" @@ -20,7 +24,8 @@ if [ -e "$OUTFILE" ]; then rm -f "$OUTFILE" fi -[ ! -d ./bin ] && mkdir ./bin +[ ! -d $BIN_DIR ] && mkdir -p $BIN_DIR +cd $BIN_DIR OS="$(uname)" ARCH="$(uname -m)" @@ -47,10 +52,7 @@ fi ARCHIVE_FILENAME="$TARGET.tar.gz" DOWNLOAD_URL="$RELEASE_URL/$ARCHIVE_FILENAME" echo "Downloading $DOWNLOAD_URL" -curl -L --progress-bar \ - --fail \ - --output "$ARCHIVE_FILENAME" \ - "$DOWNLOAD_URL" -tar xzf "$ARCHIVE_FILENAME" && mv "vim-doge-helper" "$OUTFILE" +curl -L --progress-bar --fail --output "$ARCHIVE_FILENAME" "$DOWNLOAD_URL" +tar xzf "$ARCHIVE_FILENAME" rm -f "$ARCHIVE_FILENAME" chmod +x "$OUTFILE"