Getting a working clipboard in termux
I recently started testing out having an android device as my main compute. If you’re interested you can read more about that in My android setup. Termux has been a great help in that! I downloaded it through F-droid, set it up, and soon after found myself wanting to create a basic dotfile repo, which required ssh keys, which required me copying the output into the system clipboard.
I got paste working by using Ctrl-Alt-V, as recommended here. In another post, the author (I think) recommended Ctrl-Y and Ctrl-P which laos sometimes worked for me but were very hit-and-miss. Regardless, we want to copy and paste command output, so we need this: termux-clipboard-set and termux-clipboard-get. To get those, you need to run:
pkg install termux-api
You then also need to install the actual Termux-api app, e.g here in F-droid, otherwise your commands will do nothing, which is exactly the problem I run into and figured out thanks to this response.
That’s it! The set command works both with arguments (e.g termux-clipboard-set blaba) and with piping (e.g cat blabla.txt | termux-clipboard-set). I tend to alias these copy commands, so I added this to my ~/.bashrc:
alias cs=termux-clipboard-set
And now I can just use cat file.txt | cs