diff options
-rw-r--r-- | README.markdown | 2 | ||||
-rw-r--r-- | lib/clipboard.zsh | 86 | ||||
-rw-r--r-- | plugins/coffee/coffee.plugin.zsh | 10 | ||||
-rw-r--r-- | plugins/colored-man-pages/colored-man-pages.plugin.zsh (renamed from plugins/colored-man/colored-man.plugin.zsh) | 0 | ||||
-rw-r--r-- | plugins/copydir/copydir.plugin.zsh | 6 | ||||
-rw-r--r-- | plugins/copyfile/copyfile.plugin.zsh | 8 | ||||
-rw-r--r-- | plugins/encode64/encode64.plugin.zsh | 4 |
7 files changed, 103 insertions, 13 deletions
diff --git a/README.markdown b/README.markdown index a29df81ab..779ce77c3 100644 --- a/README.markdown +++ b/README.markdown @@ -5,7 +5,7 @@ Oh My Zsh is an open source, community-driven framework for managing your [zsh]( __Oh My Zsh is a way of life!__ Once installed, your terminal prompt will become the talk of the town _or your money back!_ Each time you interact with your command prompt, you'll be able take advantage of the hundreds of bundled plugins and pretty themes. Strangers will come up to you in cafés and ask you, _"that is amazing. are you some sort of genius?"_ Finally, you'll begin to get the sort of attention that you always felt that you deserved. ...or maybe you'll just use the time that you saved to start flossing more often. -To learn more, visit http://ohmyz.sh and/or follow [ohmyzsh](https://twitter.com/ohmyzsh) on Twitter. +To learn more, visit [ohmyz.sh](http://ohmyz.sh) and/or follow [ohmyzsh](https://twitter.com/ohmyzsh) on Twitter. ## Getting Started diff --git a/lib/clipboard.zsh b/lib/clipboard.zsh new file mode 100644 index 000000000..b663800a4 --- /dev/null +++ b/lib/clipboard.zsh @@ -0,0 +1,86 @@ +# 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 +} diff --git a/plugins/coffee/coffee.plugin.zsh b/plugins/coffee/coffee.plugin.zsh index 4e98e0228..77cb663f7 100644 --- a/plugins/coffee/coffee.plugin.zsh +++ b/plugins/coffee/coffee.plugin.zsh @@ -6,11 +6,11 @@ cf () { } # compile & copy to clipboard cfc () { - cf "$1" | pbcopy + cf "$1" | clipcopy } -# compile from pasteboard & print -alias cfp='coffeeMe "$(pbpaste)"' +# compile from clipboard & print +alias cfp='coffeeMe "$(clippaste)"' -# compile from pasteboard and copy to clipboard -alias cfpc='cfp | pbcopy' +# compile from clipboard and copy to clipboard +alias cfpc='cfp | clipcopy' diff --git a/plugins/colored-man/colored-man.plugin.zsh b/plugins/colored-man-pages/colored-man-pages.plugin.zsh index 5c613f49d..5c613f49d 100644 --- a/plugins/colored-man/colored-man.plugin.zsh +++ b/plugins/colored-man-pages/colored-man-pages.plugin.zsh diff --git a/plugins/copydir/copydir.plugin.zsh b/plugins/copydir/copydir.plugin.zsh index 37bb5e086..c45106240 100644 --- a/plugins/copydir/copydir.plugin.zsh +++ b/plugins/copydir/copydir.plugin.zsh @@ -1,3 +1,5 @@ +# Copies the pathname of the current directory to the system or X Windows clipboard function copydir { - pwd | tr -d "\r\n" | pbcopy -}
\ No newline at end of file + emulate -L zsh + print -n $PWD | clipcopy +} diff --git a/plugins/copyfile/copyfile.plugin.zsh b/plugins/copyfile/copyfile.plugin.zsh index 944a903c6..f4eca5acf 100644 --- a/plugins/copyfile/copyfile.plugin.zsh +++ b/plugins/copyfile/copyfile.plugin.zsh @@ -1,5 +1,7 @@ +# Copies the contents of a given file to the system or X Windows clipboard +# +# copyfile <file> function copyfile { - [[ "$#" != 1 ]] && return 1 - local file_to_copy=$1 - cat $file_to_copy | pbcopy + emulate -L zsh + clipcopy $1 } diff --git a/plugins/encode64/encode64.plugin.zsh b/plugins/encode64/encode64.plugin.zsh index 4dbd1b453..53de6478a 100644 --- a/plugins/encode64/encode64.plugin.zsh +++ b/plugins/encode64/encode64.plugin.zsh @@ -1,4 +1,4 @@ -encode64(){ echo -n $1 | base64 } -decode64(){ echo -n $1 | base64 --decode } +encode64(){ printf '%s' $1 | base64 } +decode64(){ printf '%s' $1 | base64 --decode } alias e64=encode64 alias d64=decode64 |