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

Conversation

idbrii
Copy link

@idbrii idbrii commented Oct 13, 2020

I want all of my scripts to explicitly start in the current dirvish working
directory, so I use the example from the doc:
let g:dirvish_shdo_preamble = 'cd {}'

Other users may tend to create scripts with arguments, want their
commands to be inside a function, or output some diagnostic data.

Using the same escaping that is applied on lines since that seems like
the safest thing to do.

plugin/dirvish.vim Outdated Show resolved Hide resolved
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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is motivating this example? :Shdo buffer already automatically sets (:lcd) its local-directory to the Dirvish directory.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three reasons:

  • Using something like 'autochdir' (Allow autochdir #19) or au BufReadPost * silent! cd %:p:h changes the shdo script cwd. In the latter case, I could block it but would have to block every temp script (*.tmp.bat or $TEMP/*)?
  • I'm not comfortable running scripts that rely on cwd. Instead of manually adding the path when doing something destructive like :%Shdo rm {}, this option automatically makes it explicit.
  • Gives a nice entry point back to the directory. If I :only, edit the script, finish with it, I can gf on the path since using - brings me to $TEMP (as expected).

@justinmk justinmk force-pushed the master branch 2 times, most recently from 2fc4551 to 90428be Compare July 13, 2022 01:04
I want all of my scripts to start in the current dirvish working
directory, so I use the example from the doc:
  let g:dirvish_shdo_before = 'cd {}'

Other users may tend to create scripts with arguments, want their
commands to be inside a function, or output some diagnostic data.

Using the same escaping that is applied on lines since that seems like
the safest thing to do.
@justinmk
Copy link
Owner

justinmk commented Jan 2, 2025

Open to merging this since it's harmless enough, but how about making it a callback? Then the callback can modify the dirvish-generated Shdo script arbitrarily, and also add a "after" script. Something like

g:dirvish_shdo_fmt Callback that accepts a `script:string` arg and returns a string.

Or alternatively, wouldn't it be natural for dirvish#shdo() to emit an event, or set a b:dirvish variable in the Shdo script buffer? Then you can define autocmd(s) that modify the Shdo buffer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants