Change copydir, copyfile, and coffee plugins to use them, instead of the Mac-only `pbcopy` command.master
parent
192de6bcff
commit
5c8b0cc0c1
4 changed files with 80 additions and 9 deletions
@ -0,0 +1,67 @@ |
|||||||
|
# System clipboard integration |
||||||
|
# |
||||||
|
# This file has support for doing system clipboard copy and paste operations |
||||||
|
# from the command line in a generic cross-platform fashion. |
||||||
|
# |
||||||
|
# On OS X and Windows, the main system clipboard or "pasteboard" is used. On other |
||||||
|
# Unix-like OSes, this considers the X Windows CLIPBOARD selection to be the |
||||||
|
# "system clipboard", and the X Windows `xclip` command must be installed. |
||||||
|
|
||||||
|
# clipcopy - Copy data to clipboard |
||||||
|
# |
||||||
|
# Usage: |
||||||
|
# |
||||||
|
# <command> | clipcopy - copies stdin to clipboard |
||||||
|
# |
||||||
|
# clipcopy <file> - copies a file's contents to clipboard |
||||||
|
# |
||||||
|
function clipcopy() { |
||||||
|
emulate -L zsh |
||||||
|
local file=$1 |
||||||
|
if [[ $OSTYPE == darwin* ]]; then |
||||||
|
if [[ -z $file ]]; then |
||||||
|
pbcopy |
||||||
|
else |
||||||
|
cat $file | pbcopy |
||||||
|
fi |
||||||
|
elif [[ $OSTYPE == cygwin* ]]; then |
||||||
|
if [[ -z $file ]]; then |
||||||
|
cat > /dev/clipboard |
||||||
|
else |
||||||
|
cat $file > /dev/clipboard |
||||||
|
fi |
||||||
|
else |
||||||
|
which xclip &>/dev/null |
||||||
|
if [[ $? != 0 ]]; then |
||||||
|
print "clipcopy: Platform $OSTYPE not supported or xclip not installed" >&2 |
||||||
|
return 1 |
||||||
|
fi |
||||||
|
if [[ -z $file ]]; then |
||||||
|
xclip -in -selection clipboard |
||||||
|
else |
||||||
|
xclip -in -selection clipboard $file |
||||||
|
fi |
||||||
|
fi |
||||||
|
} |
||||||
|
|
||||||
|
# clippaste - "Paste" data from clipboard to stdout |
||||||
|
# |
||||||
|
# Usage: |
||||||
|
# |
||||||
|
# clippaste - writes clipboard's contents to stdout |
||||||
|
# |
||||||
|
function clippaste() { |
||||||
|
emulate -L zsh |
||||||
|
if [[ $OSTYPE == darwin* ]]; then |
||||||
|
pbpaste |
||||||
|
elif [[ $OSTYPE == cygwin* ]]; then |
||||||
|
cat /dev/clipboard |
||||||
|
else |
||||||
|
which xclip &>/dev/null |
||||||
|
if [[ $? != 0 ]]; then |
||||||
|
print "clipcopy: Platform $OSTYPE not supported or xclip not installed" >&2 |
||||||
|
return 1 |
||||||
|
fi |
||||||
|
xclip -out -selection clipboard |
||||||
|
fi |
||||||
|
} |
||||||
@ -1,3 +1,5 @@ |
|||||||
|
# Copies the pathname of the current directory to the system or X Windows clipboard |
||||||
function copydir { |
function copydir { |
||||||
pwd | tr -d "\r\n" | pbcopy |
emulate -L zsh |
||||||
|
print -n $PWD | clipcopy |
||||||
} |
} |
||||||
@ -1,5 +1,7 @@ |
|||||||
|
# Copies the contents of a given file to the system or X Windows clipboard |
||||||
|
# |
||||||
|
# copyfile <file> |
||||||
function copyfile { |
function copyfile { |
||||||
[[ "$#" != 1 ]] && return 1 |
emulate -L zsh |
||||||
local file_to_copy=$1 |
clipcopy $1 |
||||||
cat $file_to_copy | pbcopy |
|
||||||
} |
} |
||||||
|
|||||||
Loading…
Reference in new issue