├── LICENSE ├── Makefile ├── README.md ├── clip.sh ├── package.json └── test.sh /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Joseph Werle 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | 2 | BIN ?= clip 3 | PREFIX ?= /usr/local 4 | 5 | export CLIP_FILE ?= ./.test_clip 6 | 7 | install: 8 | cp $(BIN).sh $(PREFIX)/bin/$(BIN) 9 | 10 | uninstall: 11 | rm -f $(PREFIX)/bin/$(BIN) 12 | 13 | test: 14 | ./test.sh 15 | 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | clip(1) 2 | ======= 3 | 4 | Silly terminal clipboard 5 | 6 | ## install 7 | 8 | ```sh 9 | $ make install 10 | ``` 11 | 12 | ## usage 13 | 14 | **Store** 15 | 16 | *only stores single value* 17 | 18 | ```sh 19 | $ echo foo | clip 20 | ``` 21 | 22 | Read 23 | 24 | *read stored value* 25 | 26 | ```sh 27 | $ clip 28 | ``` 29 | 30 | ## license 31 | 32 | MIT 33 | -------------------------------------------------------------------------------- /clip.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | READ=0 4 | LAST_BYTE="" 5 | 6 | if [ -z "$CLIP_FILE" ]; then 7 | CLIP_FILE="$HOME/.clip" 8 | fi 9 | 10 | if [ -t 0 ]; then 11 | READ=1 12 | fi 13 | 14 | debug () { 15 | if ! [ -z "$DEBUG" ]; then 16 | { 17 | printf "clip: debug: " 18 | echo "$@" 19 | } >&2 20 | fi 21 | } 22 | 23 | clip_empty () { 24 | if [ -z "`cat $CLIP_FILE`" ]; then 25 | return 0 26 | else 27 | LAST_BYTE="$byte" 28 | return 1 29 | fi 30 | } 31 | 32 | clip_exists () { 33 | if test -f "$CLIP_FILE"; then 34 | return 0 35 | else 36 | return 1 37 | fi 38 | } 39 | 40 | clip_create () { 41 | if ! clip_exists; then 42 | touch "$CLIP_FILE" 43 | fi 44 | } 45 | 46 | clip_destroy () { 47 | if clip_exists; then 48 | rm -f "$CLIP_FILE" 49 | fi 50 | } 51 | 52 | clip_read () { 53 | clip_create 54 | if clip_empty; then 55 | debug "empty" 56 | return 1 57 | else 58 | cat "$CLIP_FILE" | { 59 | while read line; do 60 | debug "read '$line'" 61 | echo $line 62 | done 63 | } 64 | return 1 65 | fi 66 | } 67 | 68 | clip_write () { 69 | clip_create 70 | while read -r line; do 71 | debug "write '$line'" 72 | echo "$line" 73 | done >> "$CLIP_FILE" 74 | } 75 | 76 | _clip () { 77 | if [ "1" == "$READ" ]; then 78 | clip_read 79 | return 0 80 | else 81 | clip_destroy 82 | clip_write 83 | return 0 84 | fi 85 | } 86 | 87 | _clip 88 | exit $? 89 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "clip", 3 | "version": "0.0.1", 4 | "description": "Silly terminal clipboard", 5 | "scripts": [ "clip.sh" ], 6 | "install": "make install" 7 | } 8 | -------------------------------------------------------------------------------- /test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | debug () { 4 | if ! [ -z "$DEBUG" ]; then 5 | { 6 | printf "debug: " 7 | echo "$@" 8 | } >&2 9 | fi 10 | } 11 | 12 | clip=./clip.sh 13 | 14 | debug "ensuring empty clip" 15 | { 16 | curr="`$clip`" 17 | if ! [ -z "$curr" ]; then 18 | { 19 | echo "error: invalid clip state" 20 | exit 1 21 | } >&2 22 | fi 23 | } 24 | 25 | debug "ensuring write" 26 | { 27 | out=foo 28 | echo $out | $clip 29 | curr="`$clip`" 30 | if [ "$out" != "$curr" ]; then 31 | { 32 | echo "error: '$out' != '$curr'" 33 | exit 1 34 | } >&2 35 | fi 36 | } 37 | 38 | debug "cleaning up" 39 | rm -f "$CLIP_FILE"; 40 | 41 | echo "ok!" 42 | --------------------------------------------------------------------------------