Skip to content

Add option for preamble before shdo scripts #200

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

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
8 changes: 8 additions & 0 deletions autoload/dirvish.vim
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ let s:noau = 'silent noautocmd keepjumps'
let s:cb_map = {} " callback map
let s:rel = get(g:, 'dirvish_relative_paths', 0)

augroup dirvish_dummy_events
autocmd!
autocmd User Dirvish* "
augroup END

" Debug:
" echo '' > dirvish.log ; tail -F dirvish.log
" nvim +"let g:dirvish_dbg=1" -- b1 b2
Expand Down Expand Up @@ -169,6 +174,9 @@ func! dirvish#shdo(paths, cmd) abort
augroup END

nnoremap <buffer><silent> Z! :silent write<Bar>exe '!'.(has('win32')?fnameescape(escape(expand('%:p:gs?\\?/?'), '&\')):join(map(split(&shell), 'shellescape(v:val)')).' %')<Bar>if !v:shell_error<Bar>close<Bar>endif<CR>

let b:dirvish_dir = escape(shellescape(head),'&\')
doautocmd <nomodeline> User DirvishShdoCreated
endf

" Returns true if the buffer was modified by the user.
Expand Down
22 changes: 22 additions & 0 deletions doc/dirvish.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,28 @@ dirvish#remove_icon_fn(fn_id)
Unregisters the function associated with {fn_id} returned from
|dirvish#add_icon_fn()|.

==============================================================================
AUTOCOMMANDS *dirvish-autocommands*

DirvishShdoCreated *User_DirvishShdoCreated*
A |User| |autocommand| invoked after creating a |:Shdo| buffer.
b:dirvish_dir is set to the previous Dirvish buffer's path.

To ensure scripts always cd to the current dirvish directory, you could
add this to your vimrc: >

autocmd User DirvishShdoCreated call OnShdoCreated()
function! OnShdoCreated() abort
if has('win32')
" work across hard drives
let chdir = 'pushd '
else
let chdir = 'cd '
endif
call append(0, [chdir .. b:dirvish_dir, ''])
endf
<

==============================================================================
OPTIONS *dirvish-options*

Expand Down