diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..50b9edf --- /dev/null +++ b/AUTHORS @@ -0,0 +1,8 @@ +Console clipboard (https://github.com/zvezdochiot/cb) + +AUTHOR: + +zvezdochiot (https://github.com/zvezdochiot) + +--- +2018 diff --git a/CHANGELOG b/CHANGELOG new file mode 100644 index 0000000..9323caa --- /dev/null +++ b/CHANGELOG @@ -0,0 +1,4 @@ +Console clipboard (https://github.com/zvezdochiot/cb) + +0.20180620 zvezdochiot + init: cbc, cbf, cbp diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..5a87084 --- /dev/null +++ b/LICENSE @@ -0,0 +1,27 @@ +Simplified BSD License +http://www.opensource.org/licenses/bsd-license.html + +Copyright (c) 2018 zvezdochiot (https://github.com/zvezdochiot) +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the distribution. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2ffa3b7 --- /dev/null +++ b/Makefile @@ -0,0 +1,33 @@ +PNAME = cb +PVER = 0.20180620 +PROG1 = cbc +PROG2 = cbf +PROG3 = cbp +PROGS = $(PROG1) $(PROG2) $(PROG3) +PDOCS = AUTHORS CHANGELOG LICENSE README.md +CC = gcc +PREFIX = /usr/local +RM = @rm -fv +INSTALL = install + +.PHONY: all clean install + +all: $(PROGS) + +$(PROG1): + $(CC) src/$@.c -o $@ + +$(PROG2): + $(CC) src/$@.c -o $@ + +$(PROG3): + $(CC) src/$@.c -o $@ + +clean: + $(RM) $(PROGS) + +install: $(PROGS) + $(INSTALL) -d $(PREFIX) + $(INSTALL) -m 0755 $(PROGS) $(PREFIX)/bin/ + $(INSTALL) -d $(PREFIX)/share/doc/$(PNAME) + $(INSTALL) -m 0644 $(PDOCS) $(PREFIX)/share/doc/$(PNAME) diff --git a/README.md b/README.md new file mode 100644 index 0000000..0b1e9e5 --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +Console clipboard [copy/file/paste] (https://github.com/zvezdochiot/cb) +=================================== + +An easy to way to perform copy & paste operations in the terminal. + +Copy and paste using `stdin/stdout` + +```sh +# Copy a single line +cbc "This is some data" + +# Copy lots of data +cat ./sample.txt | cbf - + +# Copy a single file +cbf sample.txt + +# Now its time to paste the data... + +# Using stdout +cbp + +# Send clipboard data to file +cbp > output.txt +``` + +Building clip is very simple. Just use the predefined `Makefile` + +```sh +# Compile all the sources. +make + +# To install the application globally run +[sudo] make install +``` + +This will generate an executable called `cbc`, `cbf` and `cbp` in the working directory. + diff --git a/src/cb.h b/src/cb.h new file mode 100644 index 0000000..abe7659 --- /dev/null +++ b/src/cb.h @@ -0,0 +1,13 @@ +/** + * clip - A simple copy and paste utility for the terminal + * + * @author Matthew Cross + * @package clip + */ +#include +#include +#include + +const char* consoleclip = "/tmp/clipboard.tmp"; +FILE *fcc; +char buf[1024]; diff --git a/src/cbc.c b/src/cbc.c new file mode 100644 index 0000000..d4fb578 --- /dev/null +++ b/src/cbc.c @@ -0,0 +1,34 @@ +/** + * cbc - Console clipboard copy (no X11). + * + * @author zvezdochiot + */ +#include "cb.h" + +void usage() +{ + printf("Concole clipboard copy\n\n"); + printf("Usage: cbc \n\n"); +} + +int main(int argc, char** argv) { + int i; + if (argc < 2) { + usage(); + exit(0); + } + + if ((fcc = fopen(consoleclip, "w")) == NULL) + { + printf("can't open %s\n", consoleclip); + exit(1); + } + + for (i = 1; i < argc; i++) + { + fprintf(fcc, "%s ", argv[i]); + } + + fclose(fcc); +} + diff --git a/src/cbf.c b/src/cbf.c new file mode 100644 index 0000000..ace3afb --- /dev/null +++ b/src/cbf.c @@ -0,0 +1,42 @@ +/** + * cbc - Console clipboard copy file (no X11). + * + * @author zvezdochiot + */ +#include "cb.h" + +void usage() +{ + printf("Concole clipboard copy file\n\n"); + printf("Usage: cbf \n\n"); +} + +int main(int argc, char** argv) { + int i; + FILE *fin; + if (argc < 2) { + usage(); + exit(0); + } + + if ((fin = strcmp(argv[1], "-")? fopen(argv[1], "r") : stdin) == NULL) + { + printf("can't open %s\n", argv[1]); + exit(1); + } + + if ((fcc = fopen(consoleclip, "w")) == NULL) + { + printf("can't open %s\n", consoleclip); + exit(1); + } + + while (fgets(buf, 1024, fin) != NULL) + { + fprintf(fcc, "%s", buf); + } + + fclose(fin); + fclose(fcc); +} + diff --git a/src/cbp.c b/src/cbp.c new file mode 100644 index 0000000..5453be5 --- /dev/null +++ b/src/cbp.c @@ -0,0 +1,24 @@ +/** + * cbp - Console clipboard paste (no X11). + * + * @author zvezdochiot + */ +#include "cb.h" + +int main(int argc, char** argv) +{ + + if ((fcc = fopen(consoleclip, "r")) == NULL) + { + printf("can't open %s\n", consoleclip); + exit(1); + } + + while (fgets(buf, 1024, fcc) != NULL) + { + printf("%s", buf); + } + + fclose(fcc); +} +