Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pipe from clipboard in linux subsytem for windows

Using the Linux Subsystem for Windows (LSW), clip.exe can be used to copy data to the windows clipboard:

$ clip.exe /?

CLIP

Description:
    Redirects output of command line tools to the Windows clipboard.
    This text output can then be pasted into other programs.

Parameter List:
    /?                  Displays this help message.

Examples:
    DIR | CLIP          Places a copy of the current directory
                        listing into the Windows clipboard.

    CLIP < README.TXT   Places a copy of the text from readme.txt
                        on to the Windows clipboard.

Is there any way to pipe FROM the clipboard? Examples of intended use:

$ paste.exe > foo.txt

$ paste.exe | tr , '\n' | clip.exe
like image 651
Gordon Bean Avatar asked May 03 '19 17:05

Gordon Bean


1 Answers

Solution

This prints the Windows' clipboard to stdout:

powershell.exe Get-Clipboard

Examples

$ echo "hello" | clip.exe
$ powershell.exe Get-Clipboard
hello

$ date +%Y-%m-%d | clip.exe
$ powershell.exe Get-Clipboard
2019-06-13

$ alias paste.exe='powershell.exe Get-Clipboard'
$ echo "world" | clip.exe
$ paste.exe
world

paste() {  # Add me to your .bashrc, perhaps.
    powershell.exe Get-Clipboard | sed 's/\r//'
    # The `sed` will remove the unwelcome carriage-returns
}

source: https://github.com/Microsoft/WSL/issues/1069#issuecomment-391968532

like image 134
NonlinearFruit Avatar answered Dec 08 '22 02:12

NonlinearFruit