I'm working on wsl bash and I have the following function defined in my ~/.bashrc
file:
function clip { /mnt/c/Windows/System32/clip.exe "${@%\n}"; }
However this does not remove the trailing \n
from the arugument.
How can I improve this to meet my specific needs?
Many thanks
EDIT:
With the help of Kamil's answer, I was able to figure out what was actually going on. turns out that the spawned subprocess (cmd.exe) is adding the carriage return which is being inserted into clip.exe
(because I was using pipes. ex. pwd | clip
).
I was able to get the desired result with the following:
function clip { /mnt/c/Windows/System32/WindowsPowershell/v1.0/powershell.exe Set-Clipboard "${@:-$(cat)}"; }
It's a bit slow as it relies on
- powershell
- cat (external binary which should be replaced with read builtin)
But not a problem for my needs :)