1
1
Fork 0
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:
Tony Tkáčik 2019-01-28 06:22:49 +01:00
parent 6dafaf5b9d
commit fc1b5bbc87
19 changed files with 744 additions and 7 deletions

49
bin/mvln Executable file
View 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
View 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"
}

View file

@ -31,7 +31,7 @@
## fixmes::
## List all fixmes for nux-env
function :fixmes {
fgrep -n FIXME "$NUX_INC_DIR/..bin/"*
fgrep -n FIXME "$NUX_INC_DIR/..bin/"*
find "$NUX_INC_DIR" -iname "*.sh" | xargs fgrep -n FIXME
}
@ -39,6 +39,13 @@
## Displays help for specified nuxs-env library.
##
function :help.library name {
nux.help.comment $NUX_INC_DIR/$name.inc.sh
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
View 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

View file

@ -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 \