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

Capture trailing newline in shell expansion. #3470

Closed
enricozb opened this issue May 8, 2020 · 4 comments
Closed

Capture trailing newline in shell expansion. #3470

enricozb opened this issue May 8, 2020 · 4 comments

Comments

@enricozb
Copy link
Contributor

enricozb commented May 8, 2020

If I have a file test.txt with three newlines in it, and I run :reg dquote %sh{cat ~/.clipboard}, the " register is empty. Whereas if I select three newlines in kakoune and yank them with y, and then do :echo %reg{"}, I have ␤␤␤. How can I get these newlines into the register as a result of a shell expansion?

@enricozb
Copy link
Contributor Author

enricozb commented May 8, 2020

I realize that subshells automatically trail newlines, and Kakoune has either also decided to do that or is using a POSIX subshell which is trailing the newlines. However, even if I append a dummy x to the end of my shell output to then be "discarded" later won't work because Kakoune has no built-in string manipulation tools.

So I figure some solution with the pipe keys might work, but I can't think of anything at the moment.

@enricozb
Copy link
Contributor Author

enricozb commented May 8, 2020

Here is what I ended up with. Hopefully there is a better way to do this...

%sh{
  printf "%s" ": edit -scratch *clip*<ret>";
  printf "%s" "|cat ~/.clipboard<ret>";
  printf "%s" "%Hy";
  printf "%s" ": delete-buffer *clip*<ret>";
}

@Screwtapello
Copy link
Contributor

Can you do something like:

reg dquote %file{/path/to/.clipboard}

I think %file{} expands to the contents of the named file without stripping whitespace; unfortunately it requires an absolute path and doesn't support abbreviations like ~ for $HOME.

@enricozb
Copy link
Contributor Author

enricozb commented May 8, 2020

@Screwtapello This is absolutely the right way to do it. If I wanted a relative path I could just do

eval %sh{
  dir=$(echo ~/.clipboard);
  printf "%s" "reg dquote %file{$dir}"
}

Thanks a ton

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

No branches or pull requests

2 participants