mirror of
https://github.com/tonydamage/nux-env.git
synced 2025-12-11 13:24:28 +01:00
Added taskie configuration & other stuff.
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
This commit is contained in:
parent
6dafaf5b9d
commit
fc1b5bbc87
19 changed files with 744 additions and 7 deletions
49
bin/mvln
Executable file
49
bin/mvln
Executable file
|
|
@ -0,0 +1,49 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
declare -a sources
|
||||
|
||||
target=$1; shift;
|
||||
|
||||
i=0
|
||||
while [ "$#" -gt 0 ]; do
|
||||
sources[$i]="$1";
|
||||
shift;
|
||||
let i=i+1;
|
||||
done
|
||||
|
||||
function move-and-link-to-folder {
|
||||
local s="$1"; shift;
|
||||
local target="$1"; shift;
|
||||
local name=$(basename "$s");
|
||||
local sdir=$(dirname "$s");
|
||||
local target_path=$(realpath -Ls --relative-to="$sdir" "$target/$name" )
|
||||
mv "$s" "$target"
|
||||
ln -sf "$target_path" "$s"
|
||||
}
|
||||
|
||||
function move-and-link {
|
||||
local s="$1"; shift;
|
||||
local target="$1"; shift;
|
||||
local sdir=$(dirname "$s");
|
||||
local target_path=$(realpath -Ls --relative-to="$sdir" "$target" )
|
||||
mv "$s" "$target"
|
||||
ln -sf "$target_path" "$s"
|
||||
}
|
||||
|
||||
if [ "$i" -gt 1 ]; then
|
||||
if [ -d "$target" ]; then
|
||||
for s in "${sources[@]}"; do
|
||||
move-and-link-to-folder "$s" "$target"
|
||||
done
|
||||
else
|
||||
echo "Target $target is not directory."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
s="${sources[0]}"
|
||||
if [ -d "$target" ]; then
|
||||
move-and-link-to-folder "$s" "$target"
|
||||
else
|
||||
move-and-link "$s" "$target"
|
||||
fi
|
||||
fi
|
||||
43
bin/nudsl
Executable file
43
bin/nudsl
Executable file
|
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/env nux-runner
|
||||
|
||||
nux.use nudsl
|
||||
|
||||
## highlight:: <language> <file>
|
||||
|
||||
task.highlight() {
|
||||
nux.use nux/nuxsh
|
||||
nux.dsl.process highlight nux.nuxsh.language.def "$2"
|
||||
}
|
||||
|
||||
task.language.show() {
|
||||
nudsl.language.cache lang.yanglike.def
|
||||
}
|
||||
|
||||
task.plan() {
|
||||
nuxr.run.subtask "$@"
|
||||
}
|
||||
|
||||
task.plan.compile() {
|
||||
nux.use nudsl/$1
|
||||
nudsl.plan lang.$1.def "$2"
|
||||
}
|
||||
|
||||
task.plan.preview() {
|
||||
nux.use nux/nuxsh
|
||||
nux.dsl.plan nux.nuxsh.language "$2"
|
||||
plan="$(nudsl.plan.file "$1" "$2")"
|
||||
if [ -e "$plan" ]; then
|
||||
if [ -n "$(which pygmentize)" ]; then
|
||||
pygmentize -l bash "$plan";
|
||||
else
|
||||
cat "$plan";
|
||||
fi
|
||||
else
|
||||
echo "Plan not available"
|
||||
fi
|
||||
}
|
||||
|
||||
task.run() {
|
||||
echo "$@"
|
||||
nudsl.process "lang.yanglike.def" "$2"
|
||||
}
|
||||
|
|
@ -39,6 +39,13 @@
|
|||
## Displays help for specified nuxs-env library.
|
||||
##
|
||||
function :help.library name {
|
||||
nux.log debug "Library"
|
||||
if [ -e "$NUX_INC_DIR/$name.inc.sh" ] {
|
||||
nux.help.comment $NUX_INC_DIR/$name.inc.sh
|
||||
elif [ -e "$NUX_INC_DIR/$name.nuxsh.sh" ]; then
|
||||
nux.help.comment $NUX_INC_DIR/$name.nuxsh.sh
|
||||
else
|
||||
nux.fatal "Library not found"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
153
bin/nuxr.nuxsh
Normal file
153
bin/nuxr.nuxsh
Normal file
|
|
@ -0,0 +1,153 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
###
|
||||
### *nuxr-nuxsh* is wrapped bash interpreter for *nux-env* enhanced bash scripts
|
||||
### and provides out of the box support for command-style scripts (similar in
|
||||
### usage such as apt, git) with following features out of the box:
|
||||
###
|
||||
### task selection::
|
||||
### Automaticly selects correct tasks, displays help if
|
||||
### task does not exists.
|
||||
### logging::
|
||||
### Using *nux.log* function and changing output using
|
||||
### *debug*, *trace* prefixes
|
||||
### help display::
|
||||
### Automated help display when no arguments are provided.
|
||||
### Uses source comments as source for help.
|
||||
###
|
||||
###
|
||||
### # Writing nux-runner scripts
|
||||
###
|
||||
### *nux-runner* scripts are basicly bash scripts with some additional conventions.
|
||||
###
|
||||
###
|
||||
###
|
||||
###
|
||||
###
|
||||
### 1. Shebang::
|
||||
### Shebang (*#!*) at the start of file is *#!/usr/bin/env nuxr-nuxsh*
|
||||
### 2. Tasks::
|
||||
### Script usually does only defines functions in form task {taskname}
|
||||
### where taskname
|
||||
### ## Defining a task
|
||||
###
|
||||
###
|
||||
###
|
||||
###
|
||||
|
||||
|
||||
readonly NUX_RUNNER_BIN_DIR=$(dirname $(realpath ${BASH_SOURCE[0]}))
|
||||
source $NUX_RUNNER_BIN_DIR/../inc/nux.inc.sh
|
||||
readonly NUX_RUNNER=$NUX_RUNNER_BIN_DIR/nuxr-nuxsh;
|
||||
|
||||
nux.use nuxr
|
||||
nux.use nux.cfg
|
||||
|
||||
##
|
||||
## Additional commands provided by *nux-runner*:
|
||||
### *nux-runner* automaticly provides following tasks to any script it executes:
|
||||
|
||||
##
|
||||
|
||||
|
||||
|
||||
## debug:: <task> [<task arguments>]
|
||||
## Runs specified task with debug messages enabled.
|
||||
task.debug() {
|
||||
nux.log.level debug
|
||||
nuxr.run "$@"
|
||||
}
|
||||
|
||||
## trace:: <task> [<task arguments>]
|
||||
## Runs specified task with debug & trace enabled.
|
||||
task.trace() {
|
||||
nux.log.level trace
|
||||
nuxr.run "$@"
|
||||
}
|
||||
|
||||
## help:: [command]
|
||||
## Display help for command or topic if specified. Otherwise displays
|
||||
## documentation.
|
||||
task.help() {
|
||||
nuxr.task.help "$@"
|
||||
}
|
||||
|
||||
## config:: [type] name [value]
|
||||
## Reads or writes application specific configuration option.
|
||||
###
|
||||
### There are 3 *types* of configuration:
|
||||
### dist::
|
||||
### Distribution provided configuration. Read-only configuration.
|
||||
### global::
|
||||
### Global (user-specific) provided configuration. This configuration is
|
||||
### usually stored in *~/.config/{app-name}/config.yml*
|
||||
### local::
|
||||
### Local configuration.
|
||||
###
|
||||
### The resulting application configuration is merger of these three (if available)
|
||||
### with following preference (most-specific one):
|
||||
### local, global, dist
|
||||
###
|
||||
task.config() {
|
||||
nux.log trace "global is" $(nux.cfg.dir.global)
|
||||
nux.log trace "dist is" $(nux.cfg.dir.dist)
|
||||
nux.log trace "local is" $(nux.cfg.dir.local)
|
||||
|
||||
if [ "$#" -ge 3 ] ; then
|
||||
nux.cfg.write "$@"
|
||||
else
|
||||
nux.cfg.read "$@";
|
||||
fi
|
||||
}
|
||||
|
||||
task.() {
|
||||
task.help
|
||||
}
|
||||
|
||||
|
||||
## interactive::
|
||||
## Executes interactive application shell.
|
||||
task.interactive() {
|
||||
nuxr.task.interactive "$@"
|
||||
}
|
||||
###
|
||||
###
|
||||
|
||||
if [ "$NUX_RUNNER" = "$(realpath "$0")" ]
|
||||
then
|
||||
NUX_SCRIPT=$1;
|
||||
shift;
|
||||
else
|
||||
NUX_SCRIPT=$0;
|
||||
NUX_NO_INCLUDE="no include";
|
||||
fi
|
||||
|
||||
if [ -n "$NUX_SCRIPT" ]; then
|
||||
# Determines script
|
||||
NUX_SCRIPT_DIR=$(dirname "$NUX_SCRIPT")
|
||||
NUXR_APP_BIN=$(realpath "$NUX_SCRIPT")
|
||||
NUXR_APP_BIN_DIR=$(dirname "$NUXR_APP_BIN")
|
||||
NUXR_APP_DIR=$(dirname "$NUXR_APP_BIN_DIR")
|
||||
NUXR_APP_NAME=$(basename "$NUX_SCRIPT")
|
||||
|
||||
NUX_SCRIPTNAME=$(basename "$NUX_SCRIPT")
|
||||
|
||||
nux.log trace "NUX_SCRIPT env: " $(set | grep NUX_SCRIPT)
|
||||
if [ -z "$NUX_NO_INCLUDE" ]
|
||||
then
|
||||
nux.log debug "Including script: $NUX_SCRIPT"
|
||||
nux.log trace "NUX_SCRIPT env: " $(set | grep NUX_SCRIPT)
|
||||
|
||||
local tmpfile=$(realpath nux-env | md5sum | cut -d" " -f1)
|
||||
nux.nuxsh.use "$NUX_SCRIPT" "/tmp/nuxsh/$tmpfile"; # Includes script // FIXME: Add nuxsh support
|
||||
|
||||
NUX_NO_INCLUDE="no-include"
|
||||
fi
|
||||
nuxr.main "$@"
|
||||
else
|
||||
|
||||
echo Usage: nux-runner [script] [task] [options]
|
||||
echo
|
||||
grep "^\#\#" "$NUX_RUNNER" | sed -re "s/^#+ ?(.*)/\1/gi" | nux.help.shelldoc
|
||||
echo
|
||||
fi
|
||||
|
|
@ -26,7 +26,13 @@ function task.downscale {
|
|||
mkdir -p $TARGET;
|
||||
for image in "$@"; do
|
||||
let "i=i+1"
|
||||
target_file=$TARGET/$(basename $image)
|
||||
name=$(basename $image);
|
||||
target_file=$TARGET/$name;
|
||||
if [ -n "$PRESERVE" ]; then
|
||||
target_dir="${TARGET}/$(dirname "$image")";
|
||||
mkdir -p "$target_dir";
|
||||
target_file="${target_dir}/$name";
|
||||
fi
|
||||
echo "Image: $i/$count Downsampling $image -> $target_file"
|
||||
convert $image \
|
||||
-filter Lanczos -sampling-factor 1x1 \
|
||||
|
|
|
|||
10
config/nuxfs/templates/gnome-material.nuxfs
Normal file
10
config/nuxfs/templates/gnome-material.nuxfs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
dir ".ui"
|
||||
git "Flat-Remix" "https://github.com/daniruiz/Flat-Remix"
|
||||
git "Flat-Remix-GNOME-theme" "https://github.com/daniruiz/Flat-Remix-GNOME-theme"
|
||||
enddir
|
||||
dir ".themes"
|
||||
link "Flat Remix" "../.ui/Flat-Remix-GNOME-theme/Flat Remix/"
|
||||
enddir
|
||||
dir ".icons"
|
||||
link "Flat Remix" "../.ui/Flat-Remix/Flat Remix/"
|
||||
enddir
|
||||
8
config/nuxfs/templates/nux-app.nuxfs
Normal file
8
config/nuxfs/templates/nux-app.nuxfs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
name Nux Application Template
|
||||
dir bin
|
||||
|
||||
enddir bin
|
||||
|
||||
dir inc
|
||||
|
||||
enddir
|
||||
21
config/nuxfs/templates/tonydamage-public.nuxfs
Normal file
21
config/nuxfs/templates/tonydamage-public.nuxfs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
dir bin
|
||||
link mvn ../apps/maven/bin/mvn
|
||||
link eclipse ../apps/eclipse/eclipse
|
||||
enddir
|
||||
|
||||
dir .repos
|
||||
dir m2; enddir;
|
||||
dir p2; enddir;
|
||||
dir npm; enddir;
|
||||
enddir
|
||||
|
||||
|
||||
git "nux-env" "ssh://git@github.com/tonydamage/nux-env"
|
||||
link .bashrc nux-env/bashrc
|
||||
|
||||
link .m2 .repos/m2
|
||||
link .p2 .repos/p2
|
||||
link .npm .repos/npm
|
||||
|
||||
should-not-exists "*.tmp"
|
||||
should-not-exists "*.stl"
|
||||
6
config/taskie/config.yaml
Normal file
6
config/taskie/config.yaml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
backends:
|
||||
preference: gogs github
|
||||
colors:
|
||||
labels:
|
||||
bug: red
|
||||
enhancement: blue
|
||||
141
inc/nudsl.inc.sh
Normal file
141
inc/nudsl.inc.sh
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
## nulang - NUX Custom DSL Support Library
|
||||
##
|
||||
## # Language Definition
|
||||
##
|
||||
## Language is defined in terms of BASH REGEX matches and functions that process
|
||||
## or execute particular match.
|
||||
|
||||
NUDSL_CACHE_SUFFIX=".nudsl.sh"
|
||||
|
||||
nudsl.eval() {
|
||||
$nudsl_eval "$@"
|
||||
}
|
||||
|
||||
nudsl.dsl.func() {
|
||||
.process.highlight() {
|
||||
echo "$line";
|
||||
}
|
||||
.match._unmatched.highlight() {
|
||||
echo "${_gen_highlight_unmatched}$line${nc_end}"
|
||||
}
|
||||
|
||||
.gen.parser._unmatched.process() {
|
||||
nux.exec.or .match._unmatched.$action .process.$action
|
||||
}
|
||||
|
||||
.highlight() {
|
||||
nudsl.eval _gen_highlight_$1='$nc_'$2
|
||||
}
|
||||
.match() {
|
||||
local type=$1;
|
||||
local pattern=$2;
|
||||
shift; shift;
|
||||
i=0;
|
||||
local parse_body="";
|
||||
nudsl.eval _gen_parser_types='"$_gen_parser_types '$type'"'
|
||||
nudsl.eval _gen_parser_pattern_$type="'"$pattern"'"
|
||||
nudsl.eval """.gen.parser.$type.process() {
|
||||
$(
|
||||
for group in "$@"; do
|
||||
let i=$i+1;
|
||||
if [ "$group" != "-" ]; then
|
||||
echo local ${group}='${BASH_REMATCH['$i']}'
|
||||
fi
|
||||
done
|
||||
)
|
||||
nux.exec.or .match.$type.\$action .process.\$action
|
||||
}
|
||||
"""
|
||||
|
||||
nudsl.eval """.match.$type.highlight() {
|
||||
$(
|
||||
for group in "$@"; do
|
||||
let i=$i+1;
|
||||
if [ "$group" != "-" ]; then
|
||||
echo ' echo -n "${_gen_highlight_'$group'}$'$group'${nc_end}"'
|
||||
fi
|
||||
done
|
||||
)
|
||||
echo;
|
||||
}
|
||||
"""
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
nudsl_eval=eval
|
||||
|
||||
nudsl.process() {
|
||||
local action=$1;
|
||||
local language=$2;
|
||||
local file=$3;
|
||||
(
|
||||
nudsl.dsl.func
|
||||
$language
|
||||
cat "$file" | nudsl.process0 $action)
|
||||
}
|
||||
|
||||
nudsl.exec() {
|
||||
language="$1";
|
||||
file="$2";
|
||||
cached="$file${NUDSL_CACHE_SUFFIX}";
|
||||
if nudsl.plan "$language" "$file"; then
|
||||
source "$cached";
|
||||
fi
|
||||
}
|
||||
|
||||
nudsl.plan.file() {
|
||||
local language="$1"
|
||||
local file="$2";
|
||||
echo "$file${NUDSL_CACHE_SUFFIX}";
|
||||
}
|
||||
|
||||
nudsl.plan() {
|
||||
local language="$1";
|
||||
local file="$2";
|
||||
|
||||
cached="$(nudsl.plan.file $language $file)";
|
||||
if [ "$file" -ot "$cached" -a -e "$nudsl_refresh" ]; then
|
||||
nux.log debug nudsl: $file: No need to recompile.
|
||||
return;
|
||||
fi
|
||||
|
||||
nux.log debug Needs regeneration, creating new version.
|
||||
|
||||
local dirname=$(dirname "$file")
|
||||
local execution_plan=$(mktemp "$dirname/.nudsl.XXXX")
|
||||
if (nudsl.process plan "$language" "$file" > "$execution_plan") ; then
|
||||
mv -f "$execution_plan" "$cached";
|
||||
else
|
||||
echo "Plan could not be generated. See errors."
|
||||
rm "$execution_plan"
|
||||
return -1;
|
||||
fi
|
||||
}
|
||||
|
||||
nudsl.process.fail() {
|
||||
process_failed=true
|
||||
echo "$linenum:$@" >&2
|
||||
}
|
||||
|
||||
nudsl.process0() {
|
||||
local _gen_parser_pattern__unmatched='(.*)';
|
||||
local patterns="$_gen_parser_types _unmatched";
|
||||
local linenum=0;
|
||||
while IFS= read -r line ;
|
||||
do
|
||||
let linenum=$linenum+1
|
||||
for t in $patterns; do
|
||||
local pattern=_gen_parser_pattern_$t
|
||||
if [[ "$line" =~ ${!pattern} ]]; then
|
||||
.gen.parser.$t.process
|
||||
break;
|
||||
fi
|
||||
done
|
||||
if [ -n "$process_failed" ]; then
|
||||
return -1;
|
||||
fi
|
||||
done;
|
||||
}
|
||||
68
inc/nudsl/nuxdsl.inc.sh
Normal file
68
inc/nudsl/nuxdsl.inc.sh
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
nux.use nudsl/yanglike
|
||||
|
||||
|
||||
lang.nuxdsl.strict.def() {
|
||||
lang.yanglike.def
|
||||
|
||||
.keyword.plan() {
|
||||
nudsl.process.fail "undefined keyword: $keyword";
|
||||
}
|
||||
.block.start.plan() {
|
||||
nudsl.process.fail "undefined block: $keyword";
|
||||
}
|
||||
.block.end.plan() {
|
||||
echo "${indent}end${keyword}";
|
||||
}
|
||||
|
||||
.match._unmatched.plan() {
|
||||
nudsl.process.fail "invalid syntax: $line";
|
||||
}
|
||||
}
|
||||
|
||||
lang.nuxdsl.def() {
|
||||
lang.nuxdsl.strict.def
|
||||
|
||||
.keyword.plan() {
|
||||
echo "$indent$keyword $args";
|
||||
}
|
||||
.block.start.plan() {
|
||||
.keyword.plan
|
||||
}
|
||||
.block.end.plan() {
|
||||
echo "${indent}end${keyword}";
|
||||
}
|
||||
|
||||
.match._unmatched.plan() {
|
||||
echo "$line";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
.default.plan() {
|
||||
echo "$indent$keyword $args";
|
||||
}
|
||||
.blockend.plan() {
|
||||
echo "${indent}end${keyword}";
|
||||
}
|
||||
|
||||
.block() {
|
||||
eval """
|
||||
.block.$1.start.plan() {
|
||||
.default.plan
|
||||
}
|
||||
.block.$1.end.plan() {
|
||||
.blockend.plan
|
||||
}
|
||||
.keyword.$1.plan() {
|
||||
.default.plan
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
||||
.keyword() {
|
||||
eval """
|
||||
.keyword.$1.plan() {
|
||||
.default.plan
|
||||
}
|
||||
"""
|
||||
}
|
||||
10
inc/nudsl/nuxfs.inc.sh
Normal file
10
inc/nudsl/nuxfs.inc.sh
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
nux.use nudsl/nuxdsl
|
||||
|
||||
lang.nuxfs.def() {
|
||||
lang.nuxdsl.strict.def
|
||||
}
|
||||
|
||||
.block dir
|
||||
.keyword link
|
||||
.keyword git
|
||||
.keyword should-not-exists
|
||||
69
inc/nudsl/yanglike.inc.sh
Normal file
69
inc/nudsl/yanglike.inc.sh
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
nux.use nudsl/blocktrac
|
||||
|
||||
## # nudsl/yanglike - Basic skeleton for YANG-like languages
|
||||
|
||||
##
|
||||
## yanglike is barebones support for development of YANG-like languages
|
||||
## with two main concepts: blocks and simple statements.
|
||||
##
|
||||
## The syntax of language is following:
|
||||
##
|
||||
## *statement* = <*block*> | <*simple*>
|
||||
## *block* = <*keyword*> [*arg*]* **{**
|
||||
## [*statement*]*
|
||||
## *}*
|
||||
## *simple* = <*keyword*> [*arg*]*;
|
||||
## *arg* = <*uarg*> | <*darg*> | <*sarg*>
|
||||
## *uarg* - unquoted argument
|
||||
## *sarg* - single quoted argument
|
||||
## *darg* - double quoted argument
|
||||
##
|
||||
## Language support is basic with following restrictions:
|
||||
## - one statement per line
|
||||
|
||||
|
||||
##
|
||||
## lang.yanglike.def ::
|
||||
## Definition of *yanglike* language
|
||||
##
|
||||
lang.yanglike.def() {
|
||||
local comment='(( *)(#.*))?'
|
||||
local whitespace="([ ]*)"
|
||||
local uarg="([^ #\{\}\"'\"'\"';]+)";
|
||||
local sarg="('\"'\"'[^'\"'\"']+'\"'\"')";
|
||||
local darg='("[^"]*")';
|
||||
local args="((($uarg|$darg|$sarg) *)*)";
|
||||
.match.line() {
|
||||
local type="$1";
|
||||
local match="^( *)$2$comment$";
|
||||
shift;shift;
|
||||
.match "$type" "$match" indent "$@" - indent_comment comment;
|
||||
}
|
||||
|
||||
.match.line comment ''
|
||||
.match.line block_end '(\})' \
|
||||
syntax
|
||||
.match.line block_start "([^ ]+)( +)$args( *)(\{)" \
|
||||
keyword indent2 args - - - - - indent3 syntax
|
||||
.match.line keyword "([^ ]+)( +)$args?( *)(;)"\
|
||||
keyword indent2 args - - - - - indent3 syntax
|
||||
|
||||
|
||||
.highlight keyword green
|
||||
.highlight syntax blue
|
||||
.highlight args yellow
|
||||
.highlight unmatched bg_red
|
||||
}
|
||||
|
||||
|
||||
.match.comment.plan() {
|
||||
nux.exec.optional .comment.plan
|
||||
}
|
||||
|
||||
|
||||
.match.keyword.plan() {
|
||||
#nux.log trace "Executing plan for ''$keyword'"
|
||||
nux.exec.or .keyword.$keyword.plan .keyword.plan
|
||||
}
|
||||
124
inc/nux.xml.inc.sh
Normal file
124
inc/nux.xml.inc.sh
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
## #nux.json NUX Script JSON Helper library
|
||||
##
|
||||
## #Public functions
|
||||
|
||||
## nux.xml.start
|
||||
## Starts operation on new JSON. Resets write operations stack and JSON
|
||||
## source file to empty (useful for creating JSON from scratch.)
|
||||
function nux.xml.start {
|
||||
nux_xml_opstack="";
|
||||
nux_xml_source="";
|
||||
nux_xml_root="";
|
||||
}
|
||||
|
||||
## nux.xml.open <file>
|
||||
## Opens JSON File for reading and writing using *nux.xml.open* and
|
||||
## *nux.xml.write* commands.
|
||||
##
|
||||
## In order to work with empty JSON use *-n* as *file*. This allows
|
||||
## for creating new JSON from scratch.
|
||||
##
|
||||
## NOTE: Open does not reset operation stack. To reset operation stack
|
||||
## and opened file use *nux.xml.start*
|
||||
function nux.xml.open {
|
||||
local file="$1"
|
||||
if [ -f "$file" ]; then
|
||||
nux_xml_source="$file"
|
||||
fi
|
||||
}
|
||||
|
||||
## nux.xml.read <path>
|
||||
## Reads *path* from currently opened JSON file.
|
||||
## NOTE: Read does not see changes performed by *nux.xml.write* unless
|
||||
## these changes were flushed using *nux.xml.flush*.
|
||||
function nux.xml.read {
|
||||
local path=".$1";
|
||||
xmlstarlet -r "$path" "$nux_xml_source";
|
||||
}
|
||||
|
||||
## nux.xml.write <path> <value>
|
||||
## Adds write operation to action stack. Writes are not performed
|
||||
## immediately, but rather when *nux.xml.flush* is invoked.
|
||||
## This allows for batching of operations or opting out of actually
|
||||
## modifying file.
|
||||
function nux.xml.write {
|
||||
local path="/${1//\./\/}";
|
||||
if [ -z "$nux_xml_root" ] ; then
|
||||
nux_xml_root=$(cut -d "/" -f2 <<< "$path")
|
||||
nux.log debug "Root is $nux_xml_root";
|
||||
fi
|
||||
nux.log debug "Path to write is: $path";
|
||||
local value="$2";
|
||||
nux_xml_opstack="${nux_xml_opstack} -a $path -t elem -v \"$value\""
|
||||
}
|
||||
|
||||
function nux.xml.write.raw {
|
||||
local path=".$1";
|
||||
local value="$2";
|
||||
nux_xml_opstack="${nux_xml_opstack} | $path |= $value"
|
||||
}
|
||||
|
||||
## nux.xml.flush [<target>]
|
||||
## Flushes any write operations to specified *target* file.
|
||||
## If *target* is not specified JSON is outputted to *STDIN*.
|
||||
##
|
||||
## NOTE: Flush does not reset operation stack. To reset
|
||||
## operation stack and opened file use *nux.xml.start*
|
||||
##
|
||||
function nux.xml.flush {
|
||||
local target="$1"
|
||||
if [ -z "$nux_xml_source" ] ; then
|
||||
nux_xml_source=$(mktemp);
|
||||
echo "<$nux_xml_root></$nux_xml_root>";
|
||||
fi
|
||||
nux.log debug Opstack is: $nux_xml_opstack
|
||||
if [ -n "$target" ]; then
|
||||
local write_target="$target";
|
||||
if [ "$nux_xml_source" == "$target" ]; then
|
||||
write_target=$(mktemp "$(dirname "$target")/tempXXXXXX.json")
|
||||
fi
|
||||
xmlstarlet ed $nux_xml_opstack "$nux_xml_source" > "$write_target"
|
||||
if [ "$nux_xml_source" == "$target" ]; then
|
||||
mv -f "$write_target" "$target"
|
||||
fi
|
||||
else
|
||||
xmlstarlet ed $nux_xml_opstack "$nux_xml_source"
|
||||
fi
|
||||
}
|
||||
|
||||
## nux.xml.shorthands
|
||||
## Exposes shorthands for writing and reading from JSON file.
|
||||
## *njw* - nux.xml.write
|
||||
## *njr* - nux.xml.read
|
||||
##
|
||||
function nux.xml.shorthands {
|
||||
function nxw {
|
||||
nux.xml.write "$@"
|
||||
}
|
||||
function nxr {
|
||||
nux.xml.read "$@"
|
||||
}
|
||||
}
|
||||
|
||||
## # Usage Notes
|
||||
##
|
||||
## ## Operation stack and flush
|
||||
##
|
||||
## As mentioned in documentation for *nux.xml.flush* write stack
|
||||
## is not removed, but rather kept alone, separatly from reference
|
||||
## to open file. This allows for having modification template
|
||||
## which could be executed on multiple files.
|
||||
##
|
||||
## The following example adds meta.author and meta.email
|
||||
## to every JSON in directory.
|
||||
##
|
||||
## *nux.xml.start*
|
||||
## *nux.xml.write* meta.author "Tony Tkacik"
|
||||
## *nux.xml.write* meta.email "example@example.com"
|
||||
## *for* f *in* "*.xml";
|
||||
## *do*
|
||||
## *nux.xml.open* "$f"
|
||||
## *nux.xml.flush* "$f"
|
||||
## *done*;
|
||||
##
|
||||
##
|
||||
|
|
@ -2,8 +2,9 @@
|
|||
##
|
||||
function nux.check.function {
|
||||
nux.log trace "Checking if $1 is function."
|
||||
declare -f "$1" &>/dev/null && return 0
|
||||
test "$(type -t "$1")" = "function" && return 0
|
||||
return 1
|
||||
|
||||
}
|
||||
|
||||
function nux.check.nuxenv.file {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ nux.nuxsh.language.def() {
|
|||
|
||||
local args="((($uarg|$darg|$sarg) *)*)";
|
||||
|
||||
local prefixed_id="([^ :]*:)?($identifier)"
|
||||
local prefixed_id="([^= :]*:)?($identifier)"
|
||||
|
||||
.match.line() {
|
||||
local type="$1";
|
||||
|
|
@ -107,7 +107,12 @@ nux.nuxsh.language.def() {
|
|||
.identifier() {
|
||||
if [ -n "$prefix" ]; then
|
||||
local var=_import_prefix_${prefix%:}
|
||||
local prepend=${!var};
|
||||
local prepend;
|
||||
if [ -n "$var" ]; then
|
||||
prepend=${!var};
|
||||
else
|
||||
prepend=$_namespace;
|
||||
fi
|
||||
if [ -z "$prepend" ] ; then
|
||||
nudsl.process.fail "undefined prefix: $prefix";
|
||||
fi
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ nux.use nuxr/repl
|
|||
function :run TASK {
|
||||
if check:function task.$TASK {
|
||||
nux.log debug "Running task: $TASK";
|
||||
nux.log debug "Working dir: $(pwd)"
|
||||
task.$TASK "$@" # Runs task
|
||||
else
|
||||
echo "$NUX_SCRIPTNAME: Unrecognized task '$TASK' not available."
|
||||
|
|
@ -67,7 +68,6 @@ nux.use nuxr/repl
|
|||
topic="$@"
|
||||
topic_dot=$(tr " " "." <<< $topic)
|
||||
nux.log trace "Displaying topic for: '$topic' '$topic_dot'"
|
||||
|
||||
if check:function "task.help.$topic_dot" {
|
||||
shift;
|
||||
task.help.$topic "$@";
|
||||
|
|
|
|||
0
inc/nweb.inc.sh
Normal file
0
inc/nweb.inc.sh
Normal file
16
machine/bootstrap/x64-nuxenv.sh
Executable file
16
machine/bootstrap/x64-nuxenv.sh
Executable file
|
|
@ -0,0 +1,16 @@
|
|||
#!/bin/bash
|
||||
function .not_present() {
|
||||
if which "$1" &> /dev/null; then
|
||||
return 1
|
||||
fi
|
||||
return 0;
|
||||
}
|
||||
|
||||
if .not_present yaml; then
|
||||
wget https://github.com/mikefarah/yaml/releases/download/1.11/yaml_linux_amd64 -O ~/bin/yaml
|
||||
chmod +x ~/bin/yaml
|
||||
fi
|
||||
|
||||
if .not_present jq; then
|
||||
apt install jq
|
||||
fi
|
||||
Loading…
Add table
Add a link
Reference in a new issue