Repository: xonsh/xonsh

Issue:
PTK clipboard integration
<!--- Provide a general summary of the issue in the Title above -->
<!--- If you have a question along the lines of "How do I do this Bash command in xonsh"
please first look over the Bash to Xonsh translation guide: https://xon.sh/bash_to_xsh.html
If you don't find an answer there, please do open an issue! -->

## xonfig

<details>

```
+------------------+----------------------+
| xonsh            | 0.9.24               |
| Git SHA          | 74543ea9             |
| Commit Date      | Oct 10 15:12:47 2020 |
| Python           | 3.8.6                |
| PLY              | 3.11                 |
| have readline    | True                 |
| prompt toolkit   | 3.0.3                |
| shell type       | prompt_toolkit       |
| pygments         | 2.7.2                |
| on posix         | True                 |
| on linux         | True                 |
| distro           | manjaro              |
| on darwin        | False                |
| on windows       | False                |
| on cygwin        | False                |
| on msys2         | False                |
| is superuser     | False                |
| default encoding | utf-8                |
| xonsh encoding   | utf-8                |
| encoding errors  | surrogateescape      |
| on jupyter       | False                |
| jupyter kernel   | None                 |
| xontrib 1        | abbrevs              |
| xontrib 2        | argcomplete          |
| xontrib 3        | autovox              |
| xontrib 4        | back2dir             |
| xontrib 5        | cmd_done             |
| xontrib 6        | hist_navigator       |
| xontrib 7        | jedi                 |
| xontrib 8        | kitty                |
| xontrib 9        | pdb                  |
| xontrib 10       | prompt_ret_code      |
| xontrib 11       | vox                  |
| xontrib 12       | voxapi               |
+------------------+----------------------+

```

</details>

## Expected Behavior
<!--- Tell us what should happen -->
PTK is able to use [system's clipboard](https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/examples/prompts/system-clipboard-integration.py) with pyperclip library. I'd expect the same with xonsh. 

## Current Behavior
<!--- Tell us what happens instead of the expected behavior -->
<!--- If part of your bug report is a traceback, please first enter debug mode before triggering the error
To enter debug mode, set the environment variable `XONSH_DEBUG=1` _before_ starting `xonsh`.
On Linux and OSX, an easy way to to do this is to run `env XONSH_DEBUG=1 xonsh` -->
The PTK shell doesn't fillup the clipboard param.

### Traceback (if applicable)

<details>

```
traceback
```

</details>

## Steps to Reproduce
<!--- Please try to write out a minimal reproducible snippet to trigger the bug, it will help us fix it! -->

## For community
⬇️  **Please click the 👍 reaction instead of leaving a `+1` or 👍  comment**



Discussion:

Resolving patch:
diff --git a/setup.py b/setup.py
--- a/setup.py
+++ b/setup.py
@@ -342,7 +342,7 @@ def main():
     }
     skw["cmdclass"]["develop"] = xdevelop
     skw["extras_require"] = {
-        "ptk": ["prompt-toolkit>=3.0"],
+        "ptk": ["prompt-toolkit>=3.0", "pyperclip"],
         "pygments": ["pygments>=2.2"],
         "mac": ["gnureadline"],
         "linux": ["distro"],
diff --git a/xonsh/ptk_shell/shell.py b/xonsh/ptk_shell/shell.py
--- a/xonsh/ptk_shell/shell.py
+++ b/xonsh/ptk_shell/shell.py
@@ -35,6 +35,12 @@
 from prompt_toolkit.styles import merge_styles, Style
 from prompt_toolkit.styles.pygments import pygments_token_to_classname
 
+try:
+    from prompt_toolkit.clipboard.pyperclip import PyperclipClipboard
+
+    HAVE_SYS_CLIPBOARD = True
+except ImportError:
+    HAVE_SYS_CLIPBOARD = False
 
 ANSI_OSC_PATTERN = re.compile("\x1b].*?\007")
 CAPITAL_PATTERN = re.compile(r"([a-z])([A-Z])")
@@ -146,7 +152,12 @@ def __init__(self, **kwargs):
             winutils.enable_virtual_terminal_processing()
         self._first_prompt = True
         self.history = ThreadedHistory(PromptToolkitHistory())
-        self.prompter = PromptSession(history=self.history)
+
+        ptk_args = {"history": self.history}
+        if HAVE_SYS_CLIPBOARD:
+            ptk_args["clipboard"] = PyperclipClipboard()
+        self.prompter = PromptSession(**ptk_args)
+
         self.prompt_formatter = PTKPromptFormatter(self.prompter)
         self.pt_completer = PromptToolkitCompleter(self.completer, self.ctx, self)
         self.key_bindings = load_xonsh_bindings()


Test patch: