Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option for preamble before shdo scripts #200

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions autoload/dirvish.vim
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ func! dirvish#shdo(paths, cmd) abort
let f = !jagged && 2==exists(':lcd') ? fnamemodify(f, ':t') : lines[i]
let lines[i] = substitute(cmd, '\V{}', escape(shellescape(f),'&\'), 'g')
endfor

if !empty(g:dirvish_shdo_before)
let lines = [substitute(g:dirvish_shdo_before, '\V{}', escape(shellescape(head),'&\'), 'g'), ''] + lines
endif

execute 'silent split' tmpfile '|' (2==exists(':lcd')?('lcd '.dir):'')
setlocal bufhidden=wipe
silent keepmarks keepjumps call setline(1, lines)
Expand Down
14 changes: 14 additions & 0 deletions doc/dirvish.txt
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,20 @@ can be overridden by handling that event. Example: >
\ gh :silent keeppatterns g@\v/\.[^\/]+/?$@d _<cr>:setl cole=3<cr>
augroup END
<
g:dirvish_shdo_before = '' *g:dirvish_shdo_before*
Inserts this text at the beginning of shell scripts generated with
|:Shdo|. The current dirvish directory is inserted wherever {} appears in
|g:dirvish_shdo_before|.
To ensure scripts always cd to the current dirvish directory, you could
idbrii marked this conversation as resolved.
Show resolved Hide resolved
add this to your vimrc: >

if has('win32')
" work across hard drives
let g:dirvish_shdo_before = 'pushd {}'
else
let g:dirvish_shdo_before = 'cd {}'
endif
<

==============================================================================
FAQ *dirvish-faq*
Expand Down
2 changes: 2 additions & 0 deletions plugin/dirvish.vim
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ if exists('g:loaded_dirvish') || &cp || v:version < 700 || &cpo =~# 'C'
endif
let g:loaded_dirvish = 1

let g:dirvish_shdo_before = get(g:, 'dirvish_shdo_before', '')

command! -bar -nargs=? -complete=dir Dirvish call dirvish#open(<q-args>)
command! -nargs=* -complete=file -range -bang Shdo call dirvish#shdo(<bang>0 ? argv() : getline(<line1>, <line2>), <q-args>)

Expand Down