Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
O
oh-my-zsh
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
github
oh-my-zsh
Commits
dc06e96e
Commit
dc06e96e
authored
Oct 09, 2015
by
Robby Russell
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4254 from apjanke/copyfile-portability
Cross-platform clipboard clipcopy() and clippaste()
parents
b1173d4b
b6d78df6
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
99 additions
and
9 deletions
+99
-9
clipboard.zsh
lib/clipboard.zsh
+86
-0
coffee.plugin.zsh
plugins/coffee/coffee.plugin.zsh
+5
-5
copydir.plugin.zsh
plugins/copydir/copydir.plugin.zsh
+3
-1
copyfile.plugin.zsh
plugins/copyfile/copyfile.plugin.zsh
+5
-3
No files found.
lib/clipboard.zsh
0 → 100644
View file @
dc06e96e
# 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
if
which xclip &>/dev/null
;
then
if
[[
-z
$file
]]
;
then
xclip
-in
-selection
clipboard
else
xclip
-in
-selection
clipboard
$file
fi
elif
which xsel &>/dev/null
;
then
if
[[
-z
$file
]]
;
then
xsel
--clipboard
--input
else
cat
"
$file
"
| xsel
--clipboard
--input
fi
else
print
"clipcopy: Platform
$OSTYPE
not supported or xclip/xsel not installed"
>
&2
return
1
fi
fi
}
# clippaste - "Paste" data from clipboard to stdout
#
# Usage:
#
# clippaste - writes clipboard's contents to stdout
#
# clippaste | <command> - pastes contents and pipes it to another process
#
# clippaste > <file> - paste contents to a file
#
# Examples:
#
# # Pipe to another process
# clippaste | grep foo
#
# # Paste to a file
# clippaste > file.txt
function
clippaste
()
{
emulate
-L
zsh
if
[[
$OSTYPE
==
darwin
*
]]
;
then
pbpaste
elif
[[
$OSTYPE
==
cygwin
*
]]
;
then
cat
/dev/clipboard
else
if
which xclip &>/dev/null
;
then
xclip
-out
-selection
clipboard
elif
which xsel &>/dev/null
;
then
xsel
--clipboard
--output
else
print
"clipcopy: Platform
$OSTYPE
not supported or xclip/xsel not installed"
>
&2
return
1
fi
fi
}
plugins/coffee/coffee.plugin.zsh
View file @
dc06e96e
...
@@ -6,11 +6,11 @@ cf () {
...
@@ -6,11 +6,11 @@ cf () {
}
}
# compile & copy to clipboard
# compile & copy to clipboard
cfc
()
{
cfc
()
{
cf
"
$1
"
|
pb
copy
cf
"
$1
"
|
clip
copy
}
}
# compile from
paste
board & print
# compile from
clip
board & print
alias
cfp
=
'coffeeMe "$(
pb
paste)"'
alias
cfp
=
'coffeeMe "$(
clip
paste)"'
# compile from
paste
board and copy to clipboard
# compile from
clip
board and copy to clipboard
alias
cfpc
=
'cfp |
pb
copy'
alias
cfpc
=
'cfp |
clip
copy'
plugins/copydir/copydir.plugin.zsh
View file @
dc06e96e
# 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
}
}
plugins/copyfile/copyfile.plugin.zsh
View file @
dc06e96e
# 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
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment