commit 87788da023bdb3587a75830cd9ee107b881358c0
parent 3a2ef27903e39a46d0b3c58a2ab28dc9d02944ee
Author: Alex Balgavy <a.balgavy@gmail.com>
Date: Tue, 28 Apr 2020 14:21:14 +0200
shell: port clipboard funcs to bash and make scripts
Former-commit-id: b68f138ab75618f6d1661013c57a62246920143c
Diffstat:
4 files changed, 72 insertions(+), 87 deletions(-)
diff --git a/scripts/clipcopy b/scripts/clipcopy
@@ -0,0 +1,40 @@
+#!/usr/bin/env bash
+# clipcopy - Copy data to clipboard
+#
+# Usage:
+#
+# <command> | clipcopy - copies stdin to clipboard
+#
+# clipcopy <file> - copies a file's contents to clipboard
+#
+file=$1
+if [[ $OSTYPE == darwin* ]]; then
+ if [[ -z $file ]]; then
+ pbcopy
+ else
+ pbcopy < "$file"
+ fi
+elif [[ $OSTYPE == cygwin* || $OSTYPE == msys* ]]; then
+ if [[ -z "$file" ]]; then
+ cat > /dev/clipboard
+ else
+ cat "$file" > /dev/clipboard
+ fi
+else
+ if command -v xclip &>/dev/null; then
+ if [[ -z $file ]]; then
+ xclip -in -selection clipboard
+ else
+ xclip -in -selection clipboard "$file"
+ fi
+ elif command -v 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
diff --git a/scripts/clippaste b/scripts/clippaste
@@ -0,0 +1,32 @@
+#!/usr/bin/env bash
+# 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
+if [[ $OSTYPE == darwin* ]]; then
+ pbpaste
+elif [[ $OSTYPE == cygwin* || $OSTYPE == msys* ]]; then
+ cat /dev/clipboard
+else
+ if command -v xclip &>/dev/null; then
+ xclip -out -selection clipboard
+ elif command -v 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/shell/oh-my-zsh-defaults/clipboard.zsh b/shell/oh-my-zsh-defaults/clipboard.zsh
@@ -1,86 +0,0 @@
-# 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|msys)* ]]; then
- if [[ -z $file ]]; then
- cat > /dev/clipboard
- else
- cat $file > /dev/clipboard
- fi
- else
- if (( $+commands[xclip] )); then
- if [[ -z $file ]]; then
- xclip -in -selection clipboard
- else
- xclip -in -selection clipboard $file
- fi
- elif (( $+commands[xsel] )); 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|msys)* ]]; then
- cat /dev/clipboard
- else
- if (( $+commands[xclip] )); then
- xclip -out -selection clipboard
- elif (( $+commands[xsel] )); then
- xsel --clipboard --output
- else
- print "clipcopy: Platform $OSTYPE not supported or xclip/xsel not installed" >&2
- return 1
- fi
- fi
-}
diff --git a/shell/zshrc b/shell/zshrc
@@ -46,7 +46,6 @@ fpath=($DOTFILES/shell/zsh-completions/src $DOTFILES/shell/zsh-completions-mine/
autoload -Uz compinit && compinit
source $DOTFILES/shell/oh-my-zsh-defaults/completion.zsh
source $DOTFILES/shell/oh-my-zsh-defaults/directories.zsh
-source $DOTFILES/shell/oh-my-zsh-defaults/clipboard.zsh
source $DOTFILES/shell/oh-my-zsh-defaults/history.zsh
source $DOTFILES/shell/oh-my-zsh-defaults/keys.zsh