Inital commit for simple tools repo
This commit is contained in:
commit
8f862e91e0
7 changed files with 285 additions and 0 deletions
27
color.sh
Executable file
27
color.sh
Executable file
|
|
@ -0,0 +1,27 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# This file echoes a bunch of color codes to the
|
||||
# terminal to demonstrate what's available. Each
|
||||
# line is the color code of one forground color,
|
||||
# out of 17 (default + 16 escapes), followed by a
|
||||
# test use of that color on all nine background
|
||||
# colors (default + 8 escapes).
|
||||
#
|
||||
|
||||
T='gYw' # The test text
|
||||
|
||||
echo -e "\n 40m 41m 42m 43m\
|
||||
44m 45m 46m 47m";
|
||||
|
||||
for FGs in ' m' ' 1m' ' 30m' '1;30m' ' 31m' '1;31m' ' 32m' \
|
||||
'1;32m' ' 33m' '1;33m' ' 34m' '1;34m' ' 35m' '1;35m' \
|
||||
' 36m' '1;36m' ' 37m' '1;37m';
|
||||
do FG=${FGs// /}
|
||||
echo -en " $FGs \033[$FG $T "
|
||||
for BG in 40m 41m 42m 43m 44m 45m 46m 47m;
|
||||
do echo -en "$EINS \033[$FG\033[$BG $T \033[0m";
|
||||
done
|
||||
echo;
|
||||
done
|
||||
echo
|
||||
|
||||
11
color.simple.sh
Executable file
11
color.simple.sh
Executable file
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/sh
|
||||
# Print four lines showing blocks of colors: 0-7 | 0-7bold | 8-15 | 8-15bold
|
||||
perl -CADS -lwe '
|
||||
my $block = shift || (chr(0x2588) x 3);
|
||||
for (["", 0], ["1;", 0], ["", 8], ["1;", 8]) {
|
||||
my ($bold, $offset) = @$_;
|
||||
my @range = map $offset + $_, 0..7;
|
||||
printf "%s %-6s ", $bold ? "bold" : "norm", "$range[0]-$range[-1]";
|
||||
print map("\e[${bold}38;5;${_}m$block", @range), "\e[0m"
|
||||
}
|
||||
' "$@"
|
||||
22
justify
Executable file
22
justify
Executable file
|
|
@ -0,0 +1,22 @@
|
|||
#!/bin/sh
|
||||
|
||||
aligncols="72"
|
||||
if [ $# -gt 0 ];
|
||||
then
|
||||
aligncols="$1"
|
||||
fi
|
||||
|
||||
TMPFILE="/tmp/justify.$USER.$$"
|
||||
|
||||
cat > $TMPFILE
|
||||
|
||||
length=`wc -l $TMPFILE`
|
||||
|
||||
echo ".ll $aligncols
|
||||
.pl $length
|
||||
.nh
|
||||
.fi
|
||||
`cat $TMPFILE`" | sed 's,\\,\\\\,g' | groff -kT utf8 | cat -s
|
||||
|
||||
rm $TMPFILE
|
||||
|
||||
22
removenl
Executable file
22
removenl
Executable file
|
|
@ -0,0 +1,22 @@
|
|||
#!/usr/bin/tcc -run
|
||||
/* vim: set syn=c: */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
* 0x0a - linefeed
|
||||
* 0x0d - carriage return
|
||||
**/
|
||||
|
||||
int
|
||||
main() {
|
||||
char buffer;
|
||||
size_t nread;
|
||||
|
||||
while ((nread = fread(&buffer, 1, sizeof buffer, stdin)) > 0)
|
||||
if (buffer != 0x0a && buffer != 0x0d)
|
||||
fwrite(&buffer, 1, nread, stdout);
|
||||
|
||||
return 0;
|
||||
}
|
||||
41
spacesbreak
Executable file
41
spacesbreak
Executable file
|
|
@ -0,0 +1,41 @@
|
|||
#!/usr/bin/tcc -run
|
||||
/* vim: set syn=c: */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define WORD_BREAK " ()<>[]\""
|
||||
|
||||
static unsigned int is_word_break(char c);
|
||||
|
||||
int
|
||||
main() {
|
||||
char buffer, prevbuffer;
|
||||
size_t nread;
|
||||
|
||||
while ((nread = fread(&buffer, 1, sizeof buffer, stdin)) > 0) {
|
||||
if (is_word_break(buffer))
|
||||
buffer = '\n';
|
||||
|
||||
if (buffer != '\n' || prevbuffer != '\n')
|
||||
fwrite(&buffer, 1, nread, stdout);
|
||||
|
||||
prevbuffer = buffer;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
is_word_break(char c) {
|
||||
static char *word_break = WORD_BREAK;
|
||||
char *s = word_break;
|
||||
|
||||
while (*s) {
|
||||
if (*s == c)
|
||||
return 1;
|
||||
s++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
95
stpaster
Executable file
95
stpaster
Executable file
|
|
@ -0,0 +1,95 @@
|
|||
#!/usr/bin/tcc -run
|
||||
/* vim: set syn=c: */
|
||||
|
||||
/*
|
||||
* stpaster intends to pass st(1) terminal content to dmenu(1) for rapid
|
||||
* selection and finaly in xclip(1) for pasting easily.
|
||||
*
|
||||
* Remove empty lines from stdin and output full‐lines, WORDS splited by
|
||||
* space/tab, words splited by work breakers.
|
||||
*
|
||||
* see st & externalpipe patch.
|
||||
* http://st.suckless.org/
|
||||
* http://st.suckless.org/patches/externalpipe
|
||||
*
|
||||
* is_word_break() comes from :
|
||||
* http://st.suckless.org/patches/configwordbreak
|
||||
*
|
||||
* Add to config.h shortcuts :
|
||||
* { MODKEY, 'u', externalpipe, { .s = "stpaster | sort | uniq | dmenu | removenl | xclip -in -selection primary" } },
|
||||
*
|
||||
* memo :
|
||||
* 0x09 - horizontal tab
|
||||
* 0x0a - linefeed
|
||||
* 0x0b - vertical tab
|
||||
* 0x0c - form feed
|
||||
* 0x0d - carriage return
|
||||
* 0x20 - space
|
||||
**/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define WORD_BREAK " ()<>[]\",/:'."
|
||||
|
||||
static unsigned int is_word_break(char c);
|
||||
|
||||
int
|
||||
main() {
|
||||
char *line = NULL;
|
||||
size_t len = 0;
|
||||
ssize_t nread = 0;
|
||||
unsigned int i = 0;
|
||||
|
||||
unsigned int wasblank = 1;
|
||||
unsigned int emptyline = 1;
|
||||
|
||||
while ((nread = getline(&line, &len, stdin)) != -1) {
|
||||
/* remove empty lines */
|
||||
emptyline = 1;
|
||||
for (i = 0; i < nread; ++i)
|
||||
if(line[i] != 0x20 && line[i] != 0x09 && line[i] != 0x0a)
|
||||
emptyline = 0;
|
||||
if (emptyline)
|
||||
continue;
|
||||
|
||||
/* print each lines as is*/
|
||||
printf("%s", line);
|
||||
|
||||
/* split each lines on space/tab */
|
||||
for (i = 0; i < nread; ++i)
|
||||
if (line[i] != 0x20 && line[i] != 0x09) {
|
||||
wasblank = 0;
|
||||
printf("%c", line[i]);
|
||||
} else if (!wasblank) {
|
||||
wasblank = 1;
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
wasblank = 1;
|
||||
/* split each lines on word breaker */
|
||||
for (i = 0; i < nread; ++i)
|
||||
if (!is_word_break(line[i])) {
|
||||
wasblank = 0;
|
||||
printf("%c", line[i]);
|
||||
} else if (!wasblank) {
|
||||
wasblank = 1;
|
||||
printf("\n");
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
is_word_break(char c) {
|
||||
static char *word_break = WORD_BREAK;
|
||||
char *s = word_break;
|
||||
while (*s) {
|
||||
if (*s == c)
|
||||
return 1;
|
||||
s++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
67
trim
Executable file
67
trim
Executable file
|
|
@ -0,0 +1,67 @@
|
|||
#!/usr/bin/tcc -run
|
||||
/* vim: set syn=c: */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
* 0x09 - horizontal tab
|
||||
* 0x0a - linefeed
|
||||
* 0x0b - vertical tab
|
||||
* 0x0c - form feed
|
||||
* 0x0d - carriage return
|
||||
* 0x20 - space
|
||||
**/
|
||||
|
||||
int
|
||||
main() {
|
||||
char *linein = NULL, *lineout = NULL;
|
||||
size_t len = 0, lastblankchar = 0;
|
||||
ssize_t nread;
|
||||
|
||||
unsigned int trimmingleft = 1;
|
||||
|
||||
unsigned int i, j;
|
||||
|
||||
while ((nread = getline(&linein, &len, stdin)) > 0) {
|
||||
trimmingleft = 1;
|
||||
lastblankchar = j = 0;
|
||||
|
||||
lineout = malloc(nread+1);
|
||||
|
||||
for (i = 0; i < nread; ++i) {
|
||||
if (trimmingleft) {
|
||||
if(linein[i] != 0x09 &&
|
||||
linein[i] != 0x0a &&
|
||||
linein[i] != 0x0b &&
|
||||
linein[i] != 0x0c &&
|
||||
linein[i] != 0x0d &&
|
||||
linein[i] != 0x20) {
|
||||
trimmingleft = 0;
|
||||
}
|
||||
}
|
||||
if (!trimmingleft){
|
||||
if(linein[i] != 0x09 &&
|
||||
linein[i] != 0x0a &&
|
||||
linein[i] != 0x0b &&
|
||||
linein[i] != 0x0c &&
|
||||
linein[i] != 0x0d &&
|
||||
linein[i] != 0x20) {
|
||||
lastblankchar = j + 1;
|
||||
}
|
||||
}
|
||||
if (!trimmingleft) {
|
||||
lineout[j++] = linein[i];
|
||||
}
|
||||
}
|
||||
|
||||
lineout[lastblankchar] = '\n';
|
||||
lineout[lastblankchar+1] = '\0';
|
||||
|
||||
printf("%s", lineout);
|
||||
|
||||
free(lineout);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue