diff options
author | EuAndreh <eu@euandre.org> | 2022-05-12 12:01:54 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2022-05-12 12:01:54 -0300 |
commit | 90eaebabcaaea74237f34cf05709625345f276cc (patch) | |
tree | 349e7609d20ecfb6567652a7e28595cec9647eb0 /bin/copy | |
parent | .usr/etc/i3/config: WIP setup extra bindings (diff) | |
download | dotfiles-90eaebabcaaea74237f34cf05709625345f276cc.tar.gz dotfiles-90eaebabcaaea74237f34cf05709625345f276cc.tar.xz |
Move Git repository into ~/.usr/.git/
Diffstat (limited to 'bin/copy')
-rwxr-xr-x | bin/copy | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/bin/copy b/bin/copy new file mode 100755 index 0000000..64e1e32 --- /dev/null +++ b/bin/copy @@ -0,0 +1,67 @@ +#!/bin/sh +set -eu + +usage() { + cat <<-'EOF' + Usage: + copy [-n] < STDIN + copy -h + EOF +} + +help() { + cat <<-'EOF' + + Options: + -n remove newlines + -h, --help show this message + + Examples: + + Copy numbers to clipboard: + seq 10 | copy + + Copy string without newline: + echo 'with automatic newline' | copy -n + EOF +} + +for flag in "$@"; do + case "$flag" in + --) + break + ;; + --help) + usage + help + exit + ;; + *) + ;; + esac +done + +TRIM=false +while getopts 'nh' flag; do + case "$flag" in + n) + TRIM=true + ;; + h) + usage + help + exit + ;; + *) + usage >&2 + exit 2 + ;; + esac +done +shift $((OPTIND - 1)) + +if [ "$TRIM" = true ]; then + cat - | tr -d '\n' | xclip -sel clip +else + cat - | xclip -sel clip +fi |