Skip to content

Commit

Permalink
0.20180620
Browse files Browse the repository at this point in the history
init
  • Loading branch information
zvezdochiot committed Jun 20, 2018
0 parents commit 6bc5fdc
Show file tree
Hide file tree
Showing 9 changed files with 223 additions and 0 deletions.
8 changes: 8 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Console clipboard (https://github.com/zvezdochiot/cb)

AUTHOR:

zvezdochiot (https://github.com/zvezdochiot)

---
2018
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Console clipboard (https://github.com/zvezdochiot/cb)

0.20180620 zvezdochiot
init: cbc, cbf, cbp
27 changes: 27 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -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.
33 changes: 33 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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)
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.

13 changes: 13 additions & 0 deletions src/cb.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/**
* clip - A simple copy and paste utility for the terminal
*
* @author Matthew Cross <[email protected]>
* @package clip
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

const char* consoleclip = "/tmp/clipboard.tmp";
FILE *fcc;
char buf[1024];
34 changes: 34 additions & 0 deletions src/cbc.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* cbc - Console clipboard copy (no X11).
*
* @author zvezdochiot <[email protected]>
*/
#include "cb.h"

void usage()
{
printf("Concole clipboard copy\n\n");
printf("Usage: cbc <copy_text>\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);
}

42 changes: 42 additions & 0 deletions src/cbf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* cbc - Console clipboard copy file (no X11).
*
* @author zvezdochiot <[email protected]>
*/
#include "cb.h"

void usage()
{
printf("Concole clipboard copy file\n\n");
printf("Usage: cbf <file_name>\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);
}

24 changes: 24 additions & 0 deletions src/cbp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* cbp - Console clipboard paste (no X11).
*
* @author zvezdochiot <[email protected]>
*/
#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);
}

0 comments on commit 6bc5fdc

Please sign in to comment.