Skip to content

Commit

Permalink
Merge pull request #659 from kkoomen/feature/custom-install-path
Browse files Browse the repository at this point in the history
Support custom installation path.
  • Loading branch information
kkoomen authored May 1, 2024
2 parents a96aef5 + 16e1bc0 commit 39b42ec
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 32 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ on a function, press `<Leader>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)
Expand Down Expand Up @@ -190,6 +191,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`
Expand Down
17 changes: 8 additions & 9 deletions autoload/doge.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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])
Expand All @@ -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

Expand Down
5 changes: 5 additions & 0 deletions doc/doge.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
24 changes: 16 additions & 8 deletions plugin/doge.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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('<sfile>:p:h:h'))
set shellslash
else
let g:doge_dir = resolve(expand('<sfile>:p:h:h'))
endif

" section Introduction, intro {{{

""
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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('<sfile>:p:h:h'))
set shellslash
else
let g:doge_dir = resolve(expand('<sfile>:p:h:h'))
endif

""
" @command DogeGenerate {doc_standard}
" Command to generate documentation. The `{doc_standard}` accepts a count or a
Expand Down
19 changes: 11 additions & 8 deletions scripts/install.ps1
Original file line number Diff line number Diff line change
@@ -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') {
Expand All @@ -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) {
Expand All @@ -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"
16 changes: 9 additions & 7 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,20 @@ 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"

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)"
Expand All @@ -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"

0 comments on commit 39b42ec

Please sign in to comment.