diff options
author | Kutsan Kaplan <me@kutsankaplan.com> | 2017-10-25 16:46:08 +0300 |
---|---|---|
committer | Kutsan Kaplan <me@kutsankaplan.com> | 2017-10-25 16:46:08 +0300 |
commit | fa8d691e6a71754593821ebcd1fffe9efae78903 (patch) | |
tree | 4551953e9b18ec2ae8288dc6c2049628c9a423cd | |
parent | 09ffe85e47d55d7aa67da1853b775eaae7660a0f (diff) | |
download | zsh-system-clipboard.zsh-fa8d691e6a71754593821ebcd1fffe9efae78903.tar.xz zsh-system-clipboard.zsh-fa8d691e6a71754593821ebcd1fffe9efae78903.zip |
Add error functions to show errors when something bad happens
-rw-r--r-- | zsh-system-clipboard.zsh | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/zsh-system-clipboard.zsh b/zsh-system-clipboard.zsh index 06d7dc1..a0b0d88 100644 --- a/zsh-system-clipboard.zsh +++ b/zsh-system-clipboard.zsh @@ -7,6 +7,16 @@ ## function _zsh_system_clipboard_api() { + function _console.error() { + echo -e "\n\n \033[41;37m ERROR \033[0m \033[01mzsh-system-clipboard:\033[0m $@\n" >&2 + return true + } + + function _console.error_and_suggest_to_install() { + _console.error "Could not find any available clipboard manager. Make sure you have \033[01m${@}\033[0m installed." + return true + } + local -A CLIPBOARD function determinate_clipboard_manager() { @@ -15,6 +25,8 @@ function _zsh_system_clipboard_api() { if (hash pbcopy 2>/dev/null && hash pbpaste 2>/dev/null) { typeset -g CLIPBOARD[set]='pbcopy' typeset -g CLIPBOARD[get]='pbpaste' + } else { + _console.error_and_suggest_to_install 'pbcopy, pbpaste' } ;; @@ -22,15 +34,23 @@ function _zsh_system_clipboard_api() { if (hash termux-clipboard-set 2>/dev/null && hash termux-clipboard-get 2>/dev/null) { typeset -g CLIPBOARD[set]='termux-clipboard-set' typeset -g CLIPBOARD[get]='termux-clipboard-get' + } else { + _console.error_and_suggest_to_install 'Termux:API (from Play Store), termux-api (from apt package)' } ;; linux*) if (hash xsel 2>/dev/null) { - typeset -g CLIPBOARD[set]='xsel --clipboard --input' - typeset -g CLIPBOARD[get]='xsel --clipboard' + typeset -g CLIPBOARD[set]='xclip -in' + typeset -g CLIPBOARD[get]='xclip -out' + } else { + _console.error_and_suggest_to_install 'xclip' } ;; + + *) + _console.error 'Unsupported system.' + ;; } } determinate_clipboard_manager |