Skip to content

Commit 39b42ec

Browse files
authored
Merge pull request #659 from kkoomen/feature/custom-install-path
Support custom installation path.
2 parents a96aef5 + 16e1bc0 commit 39b42ec

File tree

6 files changed

+57
-32
lines changed

6 files changed

+57
-32
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ on a function, press `<Leader>d`, jump quickly through `TODO` items using
3636
- [Configuration](#configuration)
3737
* [Choosing a different doc standard](#choosing-a-different-doc-standard)
3838
* [Options](#options)
39+
+ [`g:doge_install_path`](#gdoge_install_path)
3940
+ [`g:doge_enable_mappings`](#gdoge_enable_mappings)
4041
+ [`g:doge_mapping`](#gdoge_mapping)
4142
+ [`g:doge_filetype_aliases`](#gdoge_filetype_aliases)
@@ -190,6 +191,13 @@ Here is the full list of available doc standards per filetype:
190191

191192
## Options
192193

194+
### `g:doge_install_path`
195+
196+
Default: `/path/to/vim-doge`
197+
198+
The path where the bin/ directory will be installed and loaded from. Can be
199+
useful if your system is read-only or uses immutable datastructures.
200+
193201
### `g:doge_enable_mappings`
194202

195203
Default: `1`

autoload/doge.vim

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ let s:comment_placeholder = doge#utils#placeholder()
99
" actual docblock to be inserted later on.
1010
function! doge#run_parser() abort
1111
let l:executables = [
12-
\ '/helper/target/release/vim-doge-helper.exe',
13-
\ '/helper/target/release/vim-doge-helper',
14-
\ '/bin/vim-doge-helper.exe',
15-
\ '/bin/vim-doge-helper'
12+
\ g:doge_dir . '/helper/target/release/vim-doge-helper.exe',
13+
\ g:doge_dir . '/helper/target/release/vim-doge-helper',
14+
\ g:doge_install_path . '/bin/vim-doge-helper.exe',
15+
\ g:doge_install_path . '/bin/vim-doge-helper'
1616
\ ]
1717

18-
for l:executable in l:executables
19-
let l:script_path = g:doge_dir . l:executable
18+
for l:script_path in l:executables
2019
if filereadable(resolve(l:script_path))
2120
let l:cursor_pos = getpos('.')
2221
let l:current_line = l:cursor_pos[1]
@@ -255,7 +254,7 @@ endfunction
255254
" Install the necessary dependencies.
256255
function! doge#install(...) abort
257256
for l:filename in ['vim-doge-helper', 'vim-doge-helper.exe']
258-
let l:filepath = g:doge_dir . '/bin/' . l:filename
257+
let l:filepath = g:doge_install_path . '/bin/' . l:filename
259258
if filereadable(l:filepath)
260259
let l:binary_version = split(doge#utils#trim(system(shellescape(l:filepath) . ' --version')), ' ')[1]
261260
let l:local_version = doge#utils#trim(readfile(g:doge_dir . '/.version')[0])
@@ -278,10 +277,10 @@ function! doge#install(...) abort
278277

279278
if has('win32')
280279
let l:command = (executable('pwsh.exe') ? 'pwsh.exe' : 'powershell.exe')
281-
let l:command .= ' -Command ' . shellescape('Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process -Force; & ' . shellescape(g:doge_dir . '/scripts/install.ps1'))
280+
let l:command .= ' -Command ' . shellescape('Set-ExecutionPolicy -ExecutionPolicy Unrestricted -Scope Process -Force; & ' . shellescape(g:doge_dir . '/scripts/install.ps1')) . ' ' . shellescape(g:doge_install_path)
282281
let l:term_height = 8
283282
else
284-
let l:command = fnameescape(g:doge_dir) . '/scripts/install.sh'
283+
let l:command = shellescape(g:doge_dir . '/scripts/install.sh') . ' ' . shellescape(g:doge_install_path)
285284
let l:term_height = 4
286285
endif
287286

doc/doge.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ coding!
2424
==============================================================================
2525
CONFIGURATION *doge-config*
2626

27+
*g:doge_install_path*
28+
(Default: /path/to/vim-doge)
29+
30+
The path where the bin/ directory will be installed and loaded from.
31+
2732
*g:doge_enable_mappings*
2833
(Default: 1)
2934

plugin/doge.vim

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ if has('nvim') && !has('nvim-0.3.2')
1919
finish
2020
endif
2121

22+
if has('win32') && &shellslash
23+
set noshellslash
24+
let g:doge_dir = resolve(expand('<sfile>:p:h:h'))
25+
set shellslash
26+
else
27+
let g:doge_dir = resolve(expand('<sfile>:p:h:h'))
28+
endif
29+
2230
" section Introduction, intro {{{
2331

2432
""
@@ -50,6 +58,14 @@ if exists('g:loaded_doge')
5058
endif
5159
let g:loaded_doge = 1
5260

61+
if !exists('g:doge_install_path')
62+
""
63+
" (Default: /path/to/vim-doge)
64+
"
65+
" The path where the bin/ directory will be installed and loaded from.
66+
let g:doge_install_path = g:doge_dir
67+
endif
68+
5369
if !exists('g:doge_enable_mappings')
5470
""
5571
" (Default: 1)
@@ -189,14 +205,6 @@ if g:doge_enable_mappings == v:true
189205
endif
190206
unlet s:mode
191207

192-
if has('win32') && &shellslash
193-
set noshellslash
194-
let g:doge_dir = resolve(expand('<sfile>:p:h:h'))
195-
set shellslash
196-
else
197-
let g:doge_dir = resolve(expand('<sfile>:p:h:h'))
198-
endif
199-
200208
""
201209
" @command DogeGenerate {doc_standard}
202210
" Command to generate documentation. The `{doc_standard}` accepts a count or a

scripts/install.ps1

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
Write-Host "[vim-doge] Preparing to download vim-doge-helper binary..."
1+
$InstallDir = $args[0]
2+
$BinDir = "$InstallDir\bin"
3+
$OutFile = "$BinDir\vim-doge-helper.exe"
4+
5+
Write-Host "Installation path: $OutFile"
26

37
$Arch = $env:PROCESSOR_ARCHITECTURE
48
if ($Arch -eq 'x86') {
@@ -10,16 +14,15 @@ else {
1014
$AssetName = "vim-doge-helper-windows-x86_64.zip"
1115
}
1216

13-
$RootDir = Resolve-Path -Path ((Split-Path $myInvocation.MyCommand.Path) + "\..")
17+
$RootDir = Resolve-Path -Path ((Split-Path $MyInvocation.MyCommand.Path) + "\..")
1418
$AppVersion = Get-Content "$RootDir\.version"
1519

1620
$AssetPath = "$RootDir\bin\$AssetName"
17-
$OutFile = "$RootDir\bin\vim-doge-helper.exe"
1821

1922
$DownloadUrl = "https://github.com/kkoomen/vim-doge/releases/download/v$AppVersion/$AssetName"
2023

21-
if (Test-Path $AssetName) {
22-
Remove-Item "$AssetName"
24+
if (Test-Path $AssetPath) {
25+
Remove-Item "$AssetPath"
2326
}
2427

2528
if (Test-Path $OutFile) {
@@ -35,7 +38,7 @@ try {
3538
}
3639

3740
Invoke-WebRequest -Uri $DownloadUrl -OutFile ( New-Item -Path "$AssetPath" -Force )
38-
Expand-Archive -LiteralPath "$AssetPath" -DestinationPath "$RootDir.\bin"
39-
Remove-Item "$AssetPath"
41+
Expand-Archive -LiteralPath $AssetPath -DestinationPath $BinDir
42+
Remove-Item $AssetPath
4043

41-
Write-Host "[vim-doge] Successfully downloaded vim-doge-helper"
44+
Write-Host "Successfully downloaded vim-doge-helper"

scripts/install.sh

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,20 @@ if ! which curl > /dev/null 2>&1; then
1212
fi
1313

1414
ROOT_DIR=$(cd "$(dirname "$0")/.."; pwd -P)
15-
OUTFILE="./bin/vim-doge-helper"
15+
INSTALL_DIR="${1:-$ROOT_DIR}"
16+
BIN_DIR="$INSTALL_DIR/bin"
17+
OUTFILE="$BIN_DIR/vim-doge-helper"
18+
19+
echo "Installation path: $OUTFILE"
1620

1721
cd "$ROOT_DIR"
1822

1923
if [ -e "$OUTFILE" ]; then
2024
rm -f "$OUTFILE"
2125
fi
2226

23-
[ ! -d ./bin ] && mkdir ./bin
27+
[ ! -d $BIN_DIR ] && mkdir -p $BIN_DIR
28+
cd $BIN_DIR
2429

2530
OS="$(uname)"
2631
ARCH="$(uname -m)"
@@ -47,10 +52,7 @@ fi
4752
ARCHIVE_FILENAME="$TARGET.tar.gz"
4853
DOWNLOAD_URL="$RELEASE_URL/$ARCHIVE_FILENAME"
4954
echo "Downloading $DOWNLOAD_URL"
50-
curl -L --progress-bar \
51-
--fail \
52-
--output "$ARCHIVE_FILENAME" \
53-
"$DOWNLOAD_URL"
54-
tar xzf "$ARCHIVE_FILENAME" && mv "vim-doge-helper" "$OUTFILE"
55+
curl -L --progress-bar --fail --output "$ARCHIVE_FILENAME" "$DOWNLOAD_URL"
56+
tar xzf "$ARCHIVE_FILENAME"
5557
rm -f "$ARCHIVE_FILENAME"
5658
chmod +x "$OUTFILE"

0 commit comments

Comments
 (0)