diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/clipboard.zsh | 86 | ||||
-rw-r--r-- | lib/diagnostics.zsh | 30 |
2 files changed, 110 insertions, 6 deletions
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/lib/diagnostics.zsh b/lib/diagnostics.zsh index afc33829b..9c9905e4d 100644 --- a/lib/diagnostics.zsh +++ b/lib/diagnostics.zsh @@ -52,6 +52,9 @@ # * Consider whether to move default output file location to TMPDIR. More robust # but less user friendly. # + +autoload -Uz is-at-least + function omz_diagnostic_dump() { emulate -L zsh @@ -247,7 +250,7 @@ function _omz_diag_dump_one_big_text() { function _omz_diag_dump_check_core_commands() { builtin echo "Core command check:" - local redefined name builtins externals + local redefined name builtins externals reserved_words redefined=() # All the zsh non-module builtin commands # These are taken from the zsh reference manual for 5.0.2 @@ -255,17 +258,32 @@ function _omz_diag_dump_check_core_commands() { # (For back-compatibility, if any of these are newish, they should be removed, # or at least made conditional on the version of the current running zsh.) # "history" is also excluded because OMZ is known to redefine that + reserved_words=( do done esac then elif else fi for case if while function + repeat time until select coproc nocorrect foreach end '!' '[[' '{' '}' + ) builtins=( alias autoload bg bindkey break builtin bye cd chdir command comparguments compcall compctl compdescribe compfiles compgroups compquote comptags - comptry compvalues continue declare dirs disable disown echo echotc echoti emulate - enable eval exec exit export false fc fg float functions getln getopts hash - integer jobs kill let limit local log logout noglob popd print printf - pushd pushln pwd r read readonly rehash return sched set setopt shift - source suspend test times trap true ttyctl type typeset ulimit umask unalias + comptry compvalues continue dirs disable disown echo echotc echoti emulate + enable eval exec exit false fc fg functions getln getopts hash + jobs kill let limit log logout noglob popd print printf + pushd pushln pwd r read rehash return sched set setopt shift + source suspend test times trap true ttyctl type ulimit umask unalias unfunction unhash unlimit unset unsetopt vared wait whence where which zcompile zle zmodload zparseopts zregexparse zstyle ) + if is-at-least 5.1; then + reserved_word+=( declare export integer float local readonly typeset ) + else + builtins+=( declare export integer float local readonly typeset ) + fi builtins_fatal=( builtin command local ) externals=( zsh ) + for name in $reserved_words; do + if [[ $(builtin whence -w $name) != "$name: reserved" ]]; then + builtin echo "reserved word '$name' has been redefined" + builtin which $name + redefined+=$name + fi + done for name in $builtins; do if [[ $(builtin whence -w $name) != "$name: builtin" ]]; then builtin echo "builtin '$name' has been redefined" |