Skip to content

Instantly share code, notes, and snippets.

@hypersoft
Last active December 18, 2015 03:18
Show Gist options
  • Save hypersoft/5716912 to your computer and use it in GitHub Desktop.
Save hypersoft/5716912 to your computer and use it in GitHub Desktop.
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}\";
}
# selective broadcast recieve
file.cache.accept.line.stream() { # heading alias
readarray -O $1 $2;
}
# non-cumulative selective broadcast recieve
file.cache.construct.line.stream() {
unset $1; file.cache.accept.line.stream 1 $1;
}
# cache a file
file.cache.lines() { # path alias
# this procedure blatantly attempts to create a global variable.
# long story short, in usage, don't overwrite any variables you did not create.
file.cache.construct.line.stream "$2" < "$1";
printf -v "$2[0]" %s "# $PWD@cachevar://$1; linemode/array; `date +%s`; $FUNCNAME; Extended Mapfile; Closed"$'\n';
}
# cache a stream
file.cache.line.stream() { # alias
# this procedure blatantly attempts to create a global variable.
# long story short, in usage, don't overwrite any variables you did not create.
file.cache.construct.line.stream "$1";
printf -v "$2[0]" %s "# $UID@stream:///dev/stdin; linemode/array; `date +%s`; $FUNCNAME; Extended Mapfile; Closed"$'\n';
}
# copy stream var
file.cache.line.stream.dup2() { # new alias
file.cache.construct.line.stream $1 < <(file.cache.stream 1 $2);
printf -v "$1[0]" %s "# $UID@var://$2; linemode/array; `date +%s`; $FUNCNAME; Extended Mapfile; Closed"$'\n';
}
# selective width broadcast recieve
file.cache.accept.line.block() { # heading distance alias
readarray -O $1 -n $2 $3;
}
file.cache.void.line.block() { # heading distance alias
file.cache.construct.line.stream $3 < <(
file.cache.stream.block 1 "$(( $1 - 1 ))" $3;
file.cache.stream "$(( $1 + $2 ))" $3;
);
printf -v "$3[0]" %s "# $UID@var://$3; linemode/array; `date +%s`; $FUNCNAME; Extended Mapfile; Closed"$'\n';
}
file.cache.void.line.stream() { # heading alias
file.cache.construct.line.stream $2 < <(
file.cache.stream.block 1 "$(( $1 - 1 ))" $2;
);
printf -v "$2[0]" %s "# $UID@var://$2; linemode/array; `date +%s`; $FUNCNAME; Extended Mapfile; Closed"$'\n';
}
# content stream injection
file.cache.insert.line.stream() { # heading alias
file.cache.accept.line.stream 1 $2 < <(
file.cache.stream.block 1 "$(( $1 - 1 ))" $2; cat; file.cache.stream $1 $2;
);
}
# content block injection
file.cache.insert.line.block() { # heading depth alias
file.cache.accept.line.stream 1 $3 < <(file.cache.stream.block 1 "$(( $1 - 1 ))" $3;
file.cache.accept.line.block 1 $2 _Cache;
file.cache.stream 1 _Cache;
file.cache.stream $1 $3;
);
}
# tail stream mixer
file.cache.append.line.stream() { # alias
file.cache.accept.line.stream 1 $1 < <(file.cache.stream 1 $1; cat);
}
# head stream mixer
file.cache.prepend.line.stream() { # alias
file.cache.accept.line.stream 1 $1 < <(cat; file.cache.stream 1 $1);
}
# block tail mixer
file.cache.append.line.block() { # distance alias
file.cache.accept.line.stream 1 $2 < <(
file.cache.stream 1 $2;
file.cache.accept.line.block 1 $1 _Cache;
file.cache.stream 1 _Cache;
);
}
# block head mixer
file.cache.prepend.line.block() { # distance alias
file.cache.accept.line.stream 1 $2 < <(
file.cache.accept.line.block 1 $1 _Cache;
file.cache.stream 1 _Cache;
file.cache.stream 1 $2;
);
}
# reconstruct line stream data
file.cache.rescan.lines() { # alias
file.cache.line.stream $1 < <(file.cache.stream 1 $1);
}
# read an element from an array
file.cache.get.record() { # heading alias
eval printf %s \"\${$2[$1]}\";
}
# count the number of elements in an array type
file.cache.get.record.count() {
eval printf %i'\\n' '$(('\${#$1[@]}' - 1))';
}
# write data to an index
file.cache.set.record() { # heading alias
IFS='' read -rN0 $2 < <(echo "${!2/Closed/Dirty}");
IFS='' read -rN0 $2[$1];
}
file.cache.get.header() { # alias
printf %s\\n "${!1}";
}
# display the bash source code of this resource
file.cache.export() { # alias
declare -p $1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment