pbcopy & pbpaste for Linux

Bug #1854113 reported by psl
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
xclip (Ubuntu)
New
Undecided
Unassigned

Bug Description

This is not a bug report but request for enhancement. Ubuntu 18.04 doesn't have pbcopy & pbpaste commands.

Mac users can use two commands, pbcopy and pbpaste, to work with clipbopard in their scripts. No such "easy to use" solution is available at Linux! Could be pbcopy and pbpaste commands implemented at Linux? That will make migration of Mac user to Linux World easier... ;-)

There are several articles how to implement pbcopy and pbpaste at Linux, most of them use "alias", something like this:

```
# mimic osx pbcopy/pbpaste
alias pbcopy="xclip -selection clipboard -i"
alias pbpaste="xclip -selection clipboard -o"
```
or
```
alias pbcopy='xsel --clipboard --input'
alias pbpaste='xsel --clipboard --output'
```

I think that alias commands cannot be used in shell script, right? Is it possible to implement pbcopy and pbpaste in the way to be usable in scripts too? These commands could be included in "xclip" package.

BTW, pbcopy and pbpaste are binary executable files at OS X.

Revision history for this message
psl (slansky) wrote :

It looks like this bug report is not attractive at all :-(

Anyway, some ideas how to implement commands pbcopy and pbpaste are in bug report #1854092. It is not difficult...

Revision history for this message
psl (slansky) wrote :

I just copy possible implementation of pbcopy and pbpaste for Linux from #1854092. That issue has more examples of similar commands for PowerShell, etc

```
#!/bin/sh
# print data from clipboard to stdout, again and again...

MODE="xclip"
#MODE="xsel" # doesn't work well, clipboard is not cleaned and the same text is printed again and again :-(

pbcopy ()
{
   if [ "$MODE" = "xclip" ]; then
     xclip -selection clip -i
   else
     xsel --clipboard --input
   fi
}

pbpaste ()
{
   if [ "$MODE" = "xclip" ]; then
     xclip -selection clip -o
   else
     xsel --clipboard --output
   fi
}

# MAIN
pbcopy </dev/null # clear clipboard
while :; do
   TXT="$(pbpaste)"
   if [ -n "$TXT" ]; then
      echo "$TXT"
      pbcopy </dev/null # clear clipboard
   else
      sleep 0.1 # sleep 100ms
   fi
done
```

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.