Skip to content

Instantly share code, notes, and snippets.

View hypersoft's full-sized avatar

Triston J. Taylor hypersoft

View GitHub Profile
@hypersoft
hypersoft / printfx.sh
Last active August 25, 2017 18:58
Extended printf (printfx)
#
# This file is a part of Hypersoft bash-masters
#
# Copyright (C) 2013, Triston J. Taylor ([email protected])
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
@hypersoft
hypersoft / lib.input.file.forEach
Last active December 13, 2015 18:18
Automatic I/O loop executive with environment sanitation, predefined macro source expansion, and optional script output to file, for consecutive cached calls / common operations / examination. The generated script, or executed function takes multiple files, or stdin as its arguments.
lib.input.file.forEach ()
{
# BOOT STRAPS
[[ "$1$2$3" == --buildprintfxchar ]] && {
echo "builtin printf -- '\\x`builtin printf '%02X' "'${4}"`';";
return;
}
@hypersoft
hypersoft / lib.file.slurp.each
Created February 14, 2013 16:58
Slurp each file to a var (with optional append) or standard output.
lib.file.slurp.each ()
{
# slurp each file to optional var or output with optional append to var
declare data="REPLY" record='' file='';
declare -i echo=1 append=0;
while [[ ${1:0:1} == - ]]; do
[[ $1 == -- ]] && { shift; break; };
[[ $1 == -a ]] && { append=1; shift; continue; };
[[ $1 =~ ^(-v|--var)$ ]] && { data=$2; shift 2; continue; };
[[ $1 =~ ^(-n|--no-echo)$ ]] && { shift; echo=0; continue; };
@hypersoft
hypersoft / lib.read.for.sh
Last active December 13, 2015 19:18
I/O function callback shell.
lib.read.for ()
{
# Usage: lib.read.for [line|char|record delimiter "char"] [do command] [in file ...]
declare -A env[line]=0 env[delimited]=0 env[binary]=0; declare -i EOF;
if [[ "$1" == char ]]; then env[binary]=1; shift;
elif [[ "$1" == line ]]; then env[line]=1; shift;
elif [[ "$1$2" == recorddelimiter ]]; then env[delimited]=1 env[delimiter]="$3";
shift 2; shift; fi;
@hypersoft
hypersoft / libcore.sh
Last active June 4, 2022 00:53
libcore.sh Generated from auto chained library using lib.cache.
lib.array.count ()
{
eval echo \${#$1[@]};
}
lib.array.dump ()
{
@hypersoft
hypersoft / parse.nested.block.sh
Last active December 14, 2015 09:09
Hand me your stream beginning with the first TOKEN, and I will return to you, the content of your first TOKEN, the data that lies between the first TOKEN, and the matching closing TOKEN or, I will return detailed data fields on What Went Wrong, along with full content of the buffer I have searched through.
parse.nested.block() # char start, char end[, buffer]
{ declare \
_Usage="
USAGE: $FUNCNAME [-u|-h|--help|-c|--chained] START END [BUFFER]
" \
_Help="
My name is \`$FUNCNAME' I was constructed by Triston J. Taylor (pc.wiz.tt)
as a generic method to parse nested blocks at my standard input on the
@hypersoft
hypersoft / file.cache.sh
Last active December 18, 2015 03:18
Some line thingy
# file.cache.sh;
# selective broadcast
file.cache.stream() { # heading alias
eval printf %s \"\${$2[@]:$1}\";
}
# selective width broadcast
file.cache.stream.block () { # heading distance alias
eval printf %s \"\${$3[@]:$1:$2}\";
@hypersoft
hypersoft / bin2inc.sh
Created June 24, 2013 01:45
Translate binary/text file to single zero terminated char * buffer with content length.
#!/bin/bash
hash sed fold || {
printf "%s\n" "bin2inc: error: missing program dependencies";
exit 1; # if you don't have sed or fold, get them.
} >&2;
[[ -n $2 ]] && {
[[ -f "$2" && -r "$2" ]] || {
printf "%s\n" "bin2inc: error: argument 2 is not a valid file: $2";
@hypersoft
hypersoft / buildnum.sh
Last active December 19, 2015 13:19
Build No. Automated build number tracking utility
#!/bin/bash
declare -i MAJOR="0"
declare -i MINOR="0"
declare -i MINORMAX="99"
declare -i REVISION="0"
declare -i REVISIONMAX="9999"
buildnum ()
{
@hypersoft
hypersoft / globlines
Last active August 29, 2015 13:56
Path Tools
#!/bin/sh
pipe=cat;
ifilter=./ifilter; [ -e "$ifilter" ] || ifilter=ifilter;
if [ "${1:0:1}" == '-' ]; then
pipe="$ifilter $1";
shift;
fi;