commit 992bb22e3f4805ba9731a87ce486b284a5533c4c
parent e2e09f0246484ff5451484be85324972c10df05e
Author: Alex Balgavy <a.balgavy@gmail.com>
Date: Sun, 4 Oct 2020 15:20:38 +0200
clc/clp: posix compatibility
Former-commit-id: 3aeed9ac6c197b6907d1189726a1b0f4f7de9b8f
Diffstat:
M | scripts/clc | | | 60 | ++++++++++++++++++++++++++++++++++-------------------------- |
M | scripts/clp | | | 36 | ++++++++++++++++++++++-------------- |
2 files changed, 56 insertions(+), 40 deletions(-)
diff --git a/scripts/clc b/scripts/clc
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/bin/sh
# clc - Copy data to clipboard
#
# Usage:
@@ -8,33 +8,41 @@
# clc <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
+os=$(uname -s | tr '[:upper:]' '[:lower:]')
+case "$os" in
+ linux*)
+ if command -v xclip 1>/dev/null 2>&1; then
+ if [ -z "$file" ]; then
+ xclip -in -selection clipboard
+ else
+ xclip -in -selection clipboard "$file"
+ fi
+ elif command -v xsel 1>/dev/null 2>&1; then
+ if [ -z "$file" ]; then
+ xsel --clipboard --input
+ else
+ xsel --clipboard --input < "$file"
+ fi
else
- xclip -in -selection clipboard "$file"
+ printf "xclip/xsel not installed\n"
fi
- elif command -v xsel &>/dev/null; then
- if [[ -z $file ]]; then
- xsel --clipboard --input
+ ;;
+ darwin*)
+ if [ -z "$file" ]; then
+ pbcopy
else
- cat "$file" | xsel --clipboard --input
+ pbcopy < "$file"
fi
- else
- print "clc: Platform $OSTYPE not supported or xclip/xsel not installed" >&2
+ ;;
+ msys*|cygwin*|mingw*|nt|win*)
+ if [ -z "$file" ]; then
+ cat > /dev/clipboard
+ else
+ cat "$file" > /dev/clipboard
+ fi
+ ;;
+ *)
+ printf "clc: Platform %s not supported.\n" "$os"
return 1
- fi
-fi
+ ;;
+esac
diff --git a/scripts/clp b/scripts/clp
@@ -1,4 +1,4 @@
-#!/usr/bin/env bash
+#!/bin/sh
# clp - "Paste" data from clipboard to stdout
#
# Usage:
@@ -16,17 +16,25 @@
#
# # Paste to a file
# clp > 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 "clc: Platform $OSTYPE not supported or xclip/xsel not installed" >&2
+os=$(uname -s | tr '[:upper:]' '[:lower:]')
+case "$os" in
+ linux*)
+ if command -v xclip 1>/dev/null 2>&1; then
+ xclip -out -selection clipboard
+ elif command -v xsel 1>/dev/null 2>&1; then
+ xsel --clipboard --output
+ else
+ printf "clc: xclip/xsel not installed\n"
+ fi
+ ;;
+ darwin*)
+ pbpaste
+ ;;
+ msys*|cygwin*|mingw*|nt|win*)
+ cat /dev/clipboard
+ ;;
+ *)
+ printf "Operating system %s is unknown.\n" "$os"
return 1
- fi
-fi
+ ;;
+esac