mirror of
https://github.com/tonydamage/nux-env.git
synced 2025-12-13 13:44:28 +01:00
Compare commits
5 commits
77c7079784
...
c1f365db70
| Author | SHA1 | Date | |
|---|---|---|---|
| c1f365db70 | |||
| cceebef784 | |||
| e148c76fbe | |||
| 27f3986528 | |||
| 47c123e947 |
16 changed files with 272 additions and 368 deletions
|
|
@ -9,5 +9,7 @@ alias m2-clean-snapshots="find ~/.m2/repository/ -name \"*-SNAPSHOT\" -type d |
|
|||
# GIT and GITK Aliases
|
||||
alias gitk-all="(git branch -l) | sed "s/^*//" | xargs gitk"
|
||||
|
||||
alias fav="mark multiple fav"
|
||||
alias mark-this="mark this"
|
||||
# alias analyse-java-name-conflict="find -iname *.java | grep -v package-info.java | grep -v yang-gen | grep -v target | sed "s/[\\.a-z0-9\\/\\-]*\\/\([\\\$a-zA-Z0-9]*\)\.java/\1/g" | sort | uniq -c | grep -v " 1 ""
|
||||
# alias analyse-java-annotation=find -iname "*.java" | xargs grep "@$1" | sed "s/@$1\\(.*\\)/\\1/g"
|
||||
|
|
|
|||
31
bin/mark
31
bin/mark
|
|
@ -5,6 +5,7 @@ nux.use nuxfs
|
|||
MARK_DIR_NAME=.by
|
||||
MARK_PREFIX=""
|
||||
|
||||
# FIXME: This should be probably in nux/fs
|
||||
@namespace nuxfs. {
|
||||
function :path.relative base target {
|
||||
realpath -Lms --relative-to="$base" "$target"
|
||||
|
|
@ -34,10 +35,6 @@ MARK_PREFIX=""
|
|||
}
|
||||
}
|
||||
|
||||
## Manages symlinks in closest mark (**.by**) directory, provides functionality to batch create
|
||||
## them with relative paths.
|
||||
##
|
||||
## #Available tasks:
|
||||
@namespace mark. {
|
||||
function :dir item {
|
||||
if [ -n "$MARK_DIR" ]; then
|
||||
|
|
@ -48,18 +45,27 @@ MARK_PREFIX=""
|
|||
}
|
||||
|
||||
function :mark root item mark {
|
||||
nuxfs.info "$item" Creating symlink in $(nuxfs.path.display "$root/$mark")
|
||||
nuxfs.symlink "$item" "$root/$mark"
|
||||
name=""
|
||||
if [ -e "$root/.path-names" ]; then
|
||||
rel_path=$(nuxfs.path.relative "$root/.." "$item");
|
||||
name=${rel_path//\//-}
|
||||
nuxfs.info "$item" Creating symlink: $(nuxfs.path.display "$root/$mark/$name")
|
||||
else
|
||||
nuxfs.info "$item" Creating symlink in $(nuxfs.path.display "$root/$mark")
|
||||
fi
|
||||
nuxfs.symlink "$item" "$root/$mark" "$name"
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
## Manages symlinks in closest mark (**.by**) directory, provides functionality to batch create
|
||||
## them with relative paths.
|
||||
##
|
||||
## #Available tasks:
|
||||
@namespace task. {
|
||||
|
||||
## tag:: <task> <task arguments...>
|
||||
## Performs specified task in tag namespace (marks prefixed with **tag/**)
|
||||
function :tag task {
|
||||
@command tag task {
|
||||
MARK_PREFIX="tag/"
|
||||
nuxr.run "$task" "$@"
|
||||
}
|
||||
|
|
@ -67,7 +73,7 @@ MARK_PREFIX=""
|
|||
## this:: <mark> [marks...]
|
||||
## Marks **current folder** with specific markers.
|
||||
## This creates symlinks in **mark** folder pointing to **current folder**.
|
||||
function :this mark {
|
||||
@command this mark {
|
||||
nux.log debug "Args $#"
|
||||
item=$(pwd)
|
||||
mark_root=$(mark.dir "$item")
|
||||
|
|
@ -81,7 +87,7 @@ MARK_PREFIX=""
|
|||
## multiple:: <mark> <files...>
|
||||
## Marks **files** with specific **mark**.
|
||||
## This creates symlinks for files in **mark** folder.
|
||||
function :multiple mark {
|
||||
@command multiple mark {
|
||||
pwd=$(pwd)
|
||||
mark_root=$(mark.dir "$pwd")
|
||||
while [ "$#" -gt 0 ]; do
|
||||
|
|
@ -93,7 +99,7 @@ MARK_PREFIX=""
|
|||
## display:: [mark]
|
||||
## Displays path to current mark folder and displays available marks.
|
||||
## If **mark** is provided list nested marks.
|
||||
function :display mark {
|
||||
@command display mark {
|
||||
mark_root=$(mark.dir $pwd)
|
||||
prefix="$MARK_PREFIX"
|
||||
if [ -n "$mark" ]; then
|
||||
|
|
@ -107,4 +113,3 @@ MARK_PREFIX=""
|
|||
done;
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
33
bin/taskie
33
bin/taskie
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env nux-runner
|
||||
#!/usr/bin/env nuxr-nuxsh
|
||||
|
||||
# FIXME: Check for configuration
|
||||
|
||||
|
|
@ -12,19 +12,19 @@ nux.use taskie/backend.github
|
|||
nux.use taskie/backend.gogs
|
||||
nux.use taskie/backend.dir
|
||||
|
||||
with.backend() {
|
||||
backendId="$1";
|
||||
function with.backend backendId {
|
||||
backend=$(echo $backendId | cut -d: -f1);
|
||||
nux.exec.optional backend.$backend.with;
|
||||
}
|
||||
|
||||
endwith.backend() {
|
||||
function endwith.backend {
|
||||
unset backendId;
|
||||
unset backendEngine;
|
||||
}
|
||||
|
||||
|
||||
task.labels() {
|
||||
|
||||
@command labels {
|
||||
with.backend $(backend.detect);
|
||||
backend.$backend.labels "$@";
|
||||
endwith.backend;
|
||||
|
|
@ -35,7 +35,7 @@ task.labels() {
|
|||
## Adds issue to the task repository. If issue of same title is
|
||||
## already known locally this fails.
|
||||
##
|
||||
task.add() {
|
||||
@command add {
|
||||
with.backend $(backend.detect);
|
||||
if ! backend.$backend.issue.exists "$@" ; then
|
||||
local labels=$(backend.$backend.labels.id)
|
||||
|
|
@ -58,14 +58,15 @@ task.add() {
|
|||
}
|
||||
|
||||
nuxr.repl.expose cd pwd ls clear
|
||||
nuxr.repl.prompt() {
|
||||
|
||||
function nuxr.repl.prompt {
|
||||
echo "${nc_green}$NUX_SCRIPTNAME${nc_end}:${nc_blue}$(pwd)${nc_end}> "
|
||||
}
|
||||
|
||||
##
|
||||
##
|
||||
##
|
||||
task.list() {
|
||||
@command list {
|
||||
with.backend $(backend.detect);
|
||||
backend.$backend.issue.list "$@";
|
||||
endwith.backend;
|
||||
|
|
@ -73,18 +74,18 @@ task.list() {
|
|||
|
||||
taskie_backends=$(nux.cfg.read backends.preference);
|
||||
|
||||
git.origins() {
|
||||
function git.origins {
|
||||
nux.log debug Closest git parent is $closest_git;
|
||||
if [ -n "$closest_git" ]; then
|
||||
grep -E "url *=" "$closest_git/config" | cut -d= -f2
|
||||
fi
|
||||
}
|
||||
|
||||
task.detect() {
|
||||
@command detect {
|
||||
backend.detect --all "$@";
|
||||
}
|
||||
|
||||
backend.detect() {
|
||||
function backend.detect {
|
||||
all=$1;
|
||||
if [ "$all" = "--all" ]; then
|
||||
shift;
|
||||
|
|
@ -101,16 +102,10 @@ backend.detect() {
|
|||
done;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
gogs.config.site() {
|
||||
function gogs.config.site {
|
||||
nux.cfg.read "gogs.\"$1\"$2";
|
||||
}
|
||||
|
||||
backend.file.detect() {
|
||||
function backend.file.detect {
|
||||
:
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,13 +3,12 @@
|
|||
|
||||
type ffmpeg > /dev/null 2>&1 && FFMPEG_OR_LIBAV=ffmpeg
|
||||
type avconv > /dev/null 2>&1 && FFMPEG_OR_LIBAV=avconv
|
||||
type gm /dev/null 2>&1 && NUX_MAGICK=gm
|
||||
type gm > /dev/null 2>&1 && NUX_MAGICK=gm
|
||||
|
||||
QUALITY=${QUALITY:=90}
|
||||
|
||||
@namespace task. {
|
||||
|
||||
function :video.change.container {
|
||||
@command video.change.container {
|
||||
CONTAINER=$1;
|
||||
shift;
|
||||
echo "Using $FFMPEG_OR_LIBAV for conversion."
|
||||
|
|
@ -20,11 +19,11 @@ QUALITY=${QUALITY:=90}
|
|||
done
|
||||
}
|
||||
|
||||
function :nikon-mp4 {
|
||||
@command function :nikon-mp4 {
|
||||
task.video.change.container mp4 "$@"
|
||||
}
|
||||
|
||||
function :downscale TARGET SIZE {
|
||||
@command downscale TARGET SIZE {
|
||||
local i=0;
|
||||
local count="$#";
|
||||
mkdir -p $TARGET;
|
||||
|
|
@ -47,11 +46,10 @@ QUALITY=${QUALITY:=90}
|
|||
}
|
||||
|
||||
|
||||
## to:: <jpg|png> <image...>
|
||||
##
|
||||
## Convert image to
|
||||
##
|
||||
function :to target {
|
||||
## to:: <jpg|png> <image...>
|
||||
## Convert image to specified format
|
||||
##
|
||||
@command to target {
|
||||
if ! nux.check.function "media.to.$target" ; then
|
||||
echo Target type "$target" is not supported.
|
||||
return -1
|
||||
|
|
@ -65,7 +63,7 @@ QUALITY=${QUALITY:=90}
|
|||
done
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
function media.to.jpg {
|
||||
$NUX_MAGICK convert "$1" -quality $QUALITY -auto-orient "$2"
|
||||
|
|
|
|||
87
bin/vfs
87
bin/vfs
|
|
@ -30,35 +30,42 @@ function vfs.path.real file {
|
|||
}
|
||||
|
||||
|
||||
@namespace task. {
|
||||
|
||||
|
||||
## list::
|
||||
## Lists all **mergerfs** based virtual filesystems managed by **vfs** tool
|
||||
function :list {
|
||||
echo "1"
|
||||
}
|
||||
@command list {
|
||||
echo "1"
|
||||
}
|
||||
|
||||
## info::
|
||||
## Displays info about current path
|
||||
function :info {
|
||||
nux.log debug "VFS mount: ${CURRENT_MOUNT}";
|
||||
echo "path:" $CURRENT_MOUNT;
|
||||
echo "sources:"
|
||||
for key in "${!CURRENT_SOURCES[@]}"; do
|
||||
echo " $key: ${CURRENT_SOURCES[$key]}";
|
||||
done
|
||||
@command info {
|
||||
nux.log debug "VFS mount: ${CURRENT_MOUNT}";
|
||||
echo "path:" $CURRENT_MOUNT;
|
||||
echo "sources:"
|
||||
for key in "${!CURRENT_SOURCES[@]}"; do
|
||||
echo " $key: ${CURRENT_SOURCES[$key]}";
|
||||
done
|
||||
}
|
||||
|
||||
}
|
||||
## switch:: <storage> <path+>
|
||||
## Moves specified **paths** to named **storage** for particular **vfs**.
|
||||
## This is ideal for marking files as keep or migrating them to remote,
|
||||
## rather then local.
|
||||
function :switch storage {
|
||||
|
||||
###
|
||||
### The switch uses **.vfs.sources** file to determine location of target
|
||||
### directory and creates necessary directory structures in target directory
|
||||
### to preserve local rooted path.
|
||||
###
|
||||
### FIXME: Switch does not support merging of directories
|
||||
|
||||
|
||||
@command switch storage {
|
||||
target="$(vfs.path "$storage")"
|
||||
nux.log debug "Target path $target"
|
||||
for arg_path in "$@" ; do
|
||||
rooted_path="/$(realpath -Lms --relative-to="$CURRENT_MOUNT" ${arg_path%/})";
|
||||
rooted_path="/$(realpath -m --relative-to="$CURRENT_MOUNT" ${arg_path%/})";
|
||||
target_dir="${target}${rooted_path%/*}"
|
||||
real_file="$(vfs.path.real "$rooted_path")"
|
||||
nux.log trace "Rooted path: $rooted_path";
|
||||
|
|
@ -73,35 +80,37 @@ function vfs.path.real file {
|
|||
fi
|
||||
done
|
||||
}
|
||||
|
||||
## mount:: <target> <name:path> [<name:path>+]
|
||||
## Creates **mergerfs** mount for specified pairs of storage **name** and
|
||||
## **path**
|
||||
function :mount target {
|
||||
local mount_paths="";
|
||||
nux.log debug "MergerFS mount: $target"
|
||||
## Mounts **mergerfs** on **target**. The mount is merge of specified pairs
|
||||
## of storage **name** and **path**.
|
||||
##
|
||||
|
||||
source_tempfs="$(mktemp -d)"
|
||||
for source in "$@" ; do
|
||||
source_name="${source%%:*}"
|
||||
source_path="$(realpath "${source#*:}")"
|
||||
source_path="${source_path%/}"
|
||||
nux.log debug " Source: $source_name Path: $source_path";
|
||||
mount_paths="$mount_paths:${source_path}"
|
||||
echo "$source_name $source_path" >> "$source_tempfs/.vfs.sources"
|
||||
done
|
||||
echo "temp $source_tempfs" >> "$source_tempfs/$VFS_SOURCES_FILE="
|
||||
@command mount target {
|
||||
local mount_paths="";
|
||||
nux.log debug "MergerFS mount: $target"
|
||||
|
||||
mergerfs_options="$source_tempfs:${mount_paths}"
|
||||
nux.log debug "MergerFS command:" $mergerfs_options;
|
||||
mergerfs "$mergerfs_options" "$target"
|
||||
(cd $target; vfs info )
|
||||
source_tempfs="$(mktemp -d)"
|
||||
for source in "$@" ; do
|
||||
source_name="${source%%:*}"
|
||||
source_path="$(realpath "${source#*:}")"
|
||||
source_path="${source_path%/}"
|
||||
nux.log debug " Source: $source_name Path: $source_path";
|
||||
mount_paths="$mount_paths:${source_path}"
|
||||
echo "$source_name $source_path" >> "$source_tempfs/.vfs.sources"
|
||||
done
|
||||
echo "temp $source_tempfs" >> "$source_tempfs/$VFS_SOURCES_FILE="
|
||||
|
||||
mergerfs_options="$source_tempfs:${mount_paths}"
|
||||
nux.log debug "MergerFS command:" $mergerfs_options;
|
||||
mergerfs "$mergerfs_options" "$target"
|
||||
(cd $target; vfs info )
|
||||
}
|
||||
## unmount:: <target>
|
||||
## Unmounts target VFS filesystem.
|
||||
function :unmount target {
|
||||
fusermount -u "$target"
|
||||
nuxfs.info "${CURRENT_SOURCES[temp]}" removing temporary metadata.
|
||||
rm -rf "${CURRENT_SOURCES[temp]}"
|
||||
@command :unmount target {
|
||||
fusermount -u "$target"
|
||||
nuxfs.info "${CURRENT_SOURCES[temp]}" removing temporary metadata.
|
||||
rm -rf "${CURRENT_SOURCES[temp]}"
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,5 +2,7 @@ backends:
|
|||
preference: gogs github
|
||||
colors:
|
||||
labels:
|
||||
bug: red
|
||||
bug: bg_red
|
||||
enhancement: blue
|
||||
state:
|
||||
open: bg_green
|
||||
|
|
|
|||
141
inc/nudsl.inc.sh
141
inc/nudsl.inc.sh
|
|
@ -1,141 +0,0 @@
|
|||
#!/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;
|
||||
}
|
||||
|
|
@ -17,8 +17,8 @@
|
|||
## #Usage
|
||||
##
|
||||
## Basic usage of nux.cfg is really simple:
|
||||
## - use *nux.cfg.read* function to read configuration value
|
||||
## - use *nux.cfg.write* to write configuration value.
|
||||
## - use *:read* function to read configuration value
|
||||
## - use *:write* to write configuration value.
|
||||
##
|
||||
## If you are using *nux-runner* for your scripts, it automaticly add *config*
|
||||
## task which can be used by user to read / modify configuration values.
|
||||
|
|
@ -31,13 +31,14 @@ nux_cfg_config_file=config.yaml
|
|||
## #Public functions:
|
||||
##
|
||||
|
||||
@namespace nux.cfg. {
|
||||
|
||||
## nux.cfg.read:: [<store>] <path>
|
||||
## :read:: [<store>] <path>
|
||||
## Reads configuration value stored at *path* from specified *store*.
|
||||
## If no store is specified returns first found value in all stores
|
||||
## in following order *local, global, dist*.
|
||||
##
|
||||
function nux.cfg.read {
|
||||
function :read {
|
||||
nux.log trace "Reading configuration $@"
|
||||
maybe_store="$1";
|
||||
local read_from="local global dist"
|
||||
|
|
@ -61,125 +62,125 @@ function nux.cfg.read {
|
|||
|
||||
}
|
||||
|
||||
## nux.cfg.write:: <global | local> <path> <value>
|
||||
## :write:: <global | local> <path> <value>
|
||||
## Writes specified value to *global* or *local* store.
|
||||
## If configuration file does not exists, it creates it.
|
||||
##
|
||||
function nux.cfg.write {
|
||||
store="$1";
|
||||
nux.log trace "Store is: $1";
|
||||
case $store in
|
||||
global ) ;;
|
||||
local ) ;;
|
||||
dist )
|
||||
nux.fatal "Write to dist store is disabled."
|
||||
;;
|
||||
* )
|
||||
nux.fatal "Unknown config store $1".
|
||||
;;
|
||||
esac
|
||||
shift;
|
||||
nux.cfg.write.direct "$(nux.cfg.file.$store)" "$@"
|
||||
}
|
||||
function :write store {
|
||||
nux.log trace "Store is: $store";
|
||||
case $store in
|
||||
global ) ;;
|
||||
local ) ;;
|
||||
dist )
|
||||
nux.fatal "Write to dist store is disabled."
|
||||
;;
|
||||
* )
|
||||
nux.fatal "Unknown config store $store".
|
||||
;;
|
||||
esac
|
||||
shift;
|
||||
:write.direct "$(nux.cfg.file.$store)" "$@"
|
||||
}
|
||||
|
||||
## nux.cfg.dir.global::
|
||||
## :dir.global::
|
||||
## Returns path of *global* config directory. May be overriden
|
||||
## by library for customization of path format.
|
||||
##
|
||||
function nux.cfg.dir.global {
|
||||
echo "$HOME/.config/$NUX_APP_NAME"
|
||||
}
|
||||
## nux.cfg.dir.dist::
|
||||
function :dir.global {
|
||||
echo "$HOME/.config/$NUX_APP_NAME"
|
||||
}
|
||||
## :dir.dist::
|
||||
## Returns path of *dist* config directory. SHOULD be overriden
|
||||
## by library for customization of path format.
|
||||
|
||||
function nux.cfg.dir.dist {
|
||||
echo "$NUX_APP_DIR/config/$NUX_APP_NAME"
|
||||
}
|
||||
## nux.cfg.dir.local::
|
||||
function :dir.dist {
|
||||
echo "$NUX_APP_DIR/config/$NUX_APP_NAME"
|
||||
}
|
||||
## :dir.local::
|
||||
## Returns path of *local* config directory. SHOULD be overriden
|
||||
## by library for customization of path format.
|
||||
##
|
||||
function nux.cfg.dir.local {
|
||||
nux.cfg.dir.global
|
||||
}
|
||||
function :dir.local {
|
||||
:dir.global
|
||||
}
|
||||
|
||||
## nux.cfg.file.global::
|
||||
## nux.cfg.file.local::
|
||||
## nux.cfg.file.dist::
|
||||
## :file.global::
|
||||
## :file.local::
|
||||
## :file.dist::
|
||||
## Returns path of *global* config file. Default implementation appends
|
||||
## *config.yaml* to the respective path. May be overriden if main config
|
||||
## file is determined in different way.
|
||||
##
|
||||
function nux.cfg.file.global {
|
||||
echo $(nux.cfg.dir.global)/$nux_cfg_config_file
|
||||
}
|
||||
function :file.global {
|
||||
echo $(nux.cfg.dir.global)/$nux_cfg_config_file
|
||||
}
|
||||
|
||||
function nux.cfg.file.dist {
|
||||
echo $(nux.cfg.dir.dist)/$nux_cfg_config_file
|
||||
}
|
||||
function :file.dist {
|
||||
echo $(nux.cfg.dir.dist)/$nux_cfg_config_file
|
||||
}
|
||||
|
||||
function nux.cfg.file.local {
|
||||
echo $(nux.cfg.dir.local)/$nux_cfg_config_file
|
||||
}
|
||||
function :file.local {
|
||||
echo $(nux.cfg.dir.local)/$nux_cfg_config_file
|
||||
}
|
||||
|
||||
function nux.cfg.read.direct {
|
||||
local file="$1";shift
|
||||
nux.log trace "Direct read from $file";
|
||||
local path="$@";
|
||||
if nux.check.file.exists "$file"; then
|
||||
if [ -n "$path" ]; then
|
||||
value=$(yaml r "$file" "$path")
|
||||
if [ "$value" != null ]; then
|
||||
echo "$value"
|
||||
fi
|
||||
else
|
||||
cat "$file";
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
|
||||
function nux.cfg.write.direct {
|
||||
file="$1";
|
||||
if ! nux.check.file.exists "$1" ; then
|
||||
mkdir -p "$(dirname "$file")";
|
||||
touch "$file";
|
||||
fi
|
||||
shift;
|
||||
yaml w "$file" "$@" -i
|
||||
}
|
||||
|
||||
|
||||
|
||||
function nux.cfg.get.path {
|
||||
nux.log trace "Reading configuration $@"
|
||||
local only_first=""
|
||||
if [ "$1" = "--first" ]; then
|
||||
only_first="$1"; shift;
|
||||
fi
|
||||
|
||||
maybe_store="$1";
|
||||
local read_from="local global dist"
|
||||
case "$maybe_store" in
|
||||
global ) ;&
|
||||
local ) ;&
|
||||
dist )
|
||||
shift;
|
||||
read_from=$maybe_store
|
||||
;;
|
||||
* ) ;;
|
||||
esac
|
||||
nux.log trace "Reading from $read_from"
|
||||
for store in $read_from ; do
|
||||
path="$(nux.cfg.dir.$store)/$@"
|
||||
nux.log trace "Testing $path"
|
||||
if [ -e "$path" ] ; then
|
||||
echo $path;
|
||||
if [ -n "$only_first" ]; then
|
||||
break;
|
||||
function :read.direct {
|
||||
local file="$1";shift
|
||||
nux.log trace "Direct read from $file";
|
||||
local path="$@";
|
||||
if nux.check.file.exists "$file"; then
|
||||
if [ -n "$path" ]; then
|
||||
value=$(yaml r "$file" "$path")
|
||||
if [ "$value" != null ]; then
|
||||
echo "$value"
|
||||
fi
|
||||
else
|
||||
cat "$file";
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
||||
|
||||
function :write.direct file {
|
||||
if ! nux.check.file.exists "$file" ; then
|
||||
mkdir -p "$(dirname "$file")";
|
||||
touch "$file";
|
||||
fi
|
||||
shift;
|
||||
yaml w "$file" "$@" -i
|
||||
}
|
||||
|
||||
|
||||
|
||||
function :get.path {
|
||||
nux.log trace "Reading configuration $@"
|
||||
local only_first=""
|
||||
if [ "$1" = "--first" ]; then
|
||||
only_first="$1"; shift;
|
||||
fi
|
||||
|
||||
maybe_store="$1";
|
||||
local read_from="local global dist"
|
||||
case "$maybe_store" in
|
||||
global ) ;&
|
||||
local ) ;&
|
||||
dist )
|
||||
shift;
|
||||
read_from=$maybe_store
|
||||
;;
|
||||
* ) ;;
|
||||
esac
|
||||
nux.log trace "Reading from $read_from"
|
||||
for store in $read_from ; do
|
||||
path="$(nux.cfg.dir.$store)/$@"
|
||||
nux.log trace "Testing $path"
|
||||
if [ -e "$path" ] ; then
|
||||
echo $path;
|
||||
if [ -n "$only_first" ]; then
|
||||
break;
|
||||
fi
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,11 +1,12 @@
|
|||
## #nux.json NUX Script JSON Helper library
|
||||
##
|
||||
## #Public functions
|
||||
|
||||
@namespace nux.json. {
|
||||
## nux.json.start
|
||||
## Starts operation on new JSON. Resets write operations stack and JSON
|
||||
## source file to empty (useful for creating JSON from scratch.)
|
||||
function nux.json.start {
|
||||
|
||||
function :start {
|
||||
nux_json_opstack=".";
|
||||
nux_json_source="-n";
|
||||
}
|
||||
|
|
@ -19,8 +20,7 @@ function nux.json.start {
|
|||
##
|
||||
## NOTE: Open does not reset operation stack. To reset operation stack
|
||||
## and opened file use *nux.json.start*
|
||||
function nux.json.open {
|
||||
local file="$1"
|
||||
function :open file {
|
||||
if [ -f "$file" ]; then
|
||||
nux_json_source="$file"
|
||||
fi
|
||||
|
|
@ -30,9 +30,8 @@ function nux.json.open {
|
|||
## Reads *path* from currently opened JSON file.
|
||||
## NOTE: Read does not see changes performed by *nux.json.write* unless
|
||||
## these changes were flushed using *nux.json.flush*.
|
||||
function nux.json.read {
|
||||
local path=".$1";
|
||||
jq -r "$path" "$nux_json_source";
|
||||
function :read path {
|
||||
jq -r ".$path" "$nux_json_source";
|
||||
}
|
||||
|
||||
## nux.json.write <path> <value>
|
||||
|
|
@ -40,16 +39,12 @@ function nux.json.read {
|
|||
## immediately, but rather when *nux.json.flush* is invoked.
|
||||
## This allows for batching of operations or opting out of actually
|
||||
## modifying file.
|
||||
function nux.json.write {
|
||||
local path=".$1";
|
||||
local value="$2";
|
||||
nux_json_opstack="${nux_json_opstack} | $path |= \"$value\""
|
||||
function :write path value {
|
||||
nux_json_opstack="${nux_json_opstack} | .$path |= \"$value\""
|
||||
}
|
||||
|
||||
function nux.json.write.raw {
|
||||
local path=".$1";
|
||||
local value="$2";
|
||||
nux_json_opstack="${nux_json_opstack} | $path |= $value"
|
||||
function :write.raw path value {
|
||||
nux_json_opstack="${nux_json_opstack} | .$path |= $value"
|
||||
}
|
||||
|
||||
## nux.json.flush [<target>]
|
||||
|
|
@ -59,8 +54,7 @@ function nux.json.write.raw {
|
|||
## NOTE: Flush does not reset operation stack. To reset
|
||||
## operation stack and opened file use *nux.json.start*
|
||||
##
|
||||
function nux.json.flush {
|
||||
local target="$1"
|
||||
function :flush target {
|
||||
if [ -n "$target" ]; then
|
||||
local write_target="$target";
|
||||
if [ "$nux_json_source" == "$target" ]; then
|
||||
|
|
@ -80,7 +74,7 @@ function nux.json.flush {
|
|||
## *njw* - nux.json.write
|
||||
## *njr* - nux.json.read
|
||||
##
|
||||
function nux.json.shorthands {
|
||||
function :shorthands {
|
||||
function njw {
|
||||
nux.json.write "$@"
|
||||
}
|
||||
|
|
@ -111,3 +105,5 @@ function nux.json.shorthands {
|
|||
## *done*;
|
||||
##
|
||||
##
|
||||
|
||||
}
|
||||
|
|
@ -42,6 +42,5 @@ if [ -t 1 ] {
|
|||
|
||||
readonly NC_error=$NC_Red
|
||||
|
||||
nux.log trace Terminal colors enabled
|
||||
}
|
||||
|
||||
nux.log trace Terminal colors enabled
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
#!/usr/bin/env nuxsh
|
||||
@namespace nux.help. {
|
||||
|
||||
## nux.help.shelldoc::
|
||||
## Reads input from std-in and perform terminal-based colorization based on
|
||||
## shelldoc format.
|
||||
function :shelldoc {
|
||||
sed -r \
|
||||
-e "s/^## ?(.*)/${NC_White}\1${NC_No}/gI" \
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ if [ -t 1 ]; then
|
|||
NC_LOG_No=`tput sgr0`
|
||||
fi
|
||||
|
||||
NC_LOG_current=${NC_LOG_current:=3}
|
||||
|
||||
NC_LOG_id_none=0
|
||||
NC_LOG_id_error=1
|
||||
|
|
@ -19,6 +18,10 @@ NC_LOG_id_info=3
|
|||
NC_LOG_id_debug=4
|
||||
NC_LOG_id_trace=5
|
||||
|
||||
NC_LOG_current=${NC_LOG_current:=3}
|
||||
|
||||
|
||||
|
||||
##
|
||||
## NUX Script environment provides basic logging capabilities.
|
||||
##
|
||||
|
|
@ -55,4 +58,8 @@ function nux.log.level {
|
|||
NC_LOG_current=${!level_id}
|
||||
}
|
||||
|
||||
if [ -n "$NUX_LOG_LEVEL" ]; then
|
||||
nux.log.level "$NUX_LOG_LEVEL";
|
||||
fi
|
||||
|
||||
nux.log trace Nux Logger included
|
||||
|
|
|
|||
|
|
@ -30,13 +30,19 @@ nux.nuxsh.language.def() {
|
|||
.match.line block_end '(\})' \
|
||||
syntax
|
||||
|
||||
|
||||
.match.line if_start "(if)( +)$prefixed_id( +)$args?( *)(\{)" \
|
||||
keyword indent2 prefix identifier indent3 args - - - - - indent4 syntax3
|
||||
|
||||
|
||||
.match.line task_start "((@command)( +))($identifier)((\()|( *))(($identifier,? *)*)(\))?( *)(\{)" \
|
||||
- keyword indent2 identifier - syntax indent3 args - syntax2 indent4 syntax3
|
||||
|
||||
|
||||
.match.line function_start "((function)( +))($identifier)((\()|( *))(($identifier,? *)*)(\))?( *)(\{)" \
|
||||
- keyword indent2 identifier - syntax indent3 args - syntax2 indent4 syntax3
|
||||
|
||||
|
||||
|
||||
.match.line block_start "($identifier)(( +)$args)?( *)(\{)" \
|
||||
identifier - indent2 args - - - - - indent3 syntax3
|
||||
|
||||
|
|
@ -51,12 +57,12 @@ nux.nuxsh.language.def() {
|
|||
|
||||
.highlight prefix cyan
|
||||
.highlight identifier green
|
||||
.highlight keyword blue
|
||||
.highlight keyword cyan
|
||||
.highlight args yellow
|
||||
|
||||
.highlight comment magenta
|
||||
|
||||
.highlight unmatched red
|
||||
.highlight unmatched white
|
||||
|
||||
.highlight syntax white
|
||||
.highlight syntax2 white
|
||||
|
|
@ -172,6 +178,20 @@ nux.nuxsh.language.def() {
|
|||
done
|
||||
}
|
||||
|
||||
.match.task_start.plan() {
|
||||
.block.push task
|
||||
case $identifier in
|
||||
:*) identifier="task.${identifier#:}";;
|
||||
*) identifier="task.$identifier"
|
||||
esac;
|
||||
echo "${indent}$identifier() {";
|
||||
echo "${indent} nux.log trace $identifier: invoked";
|
||||
for arg in ${args//,/ }; do
|
||||
echo "${indent} local $arg="'"$1"'";shift;"
|
||||
echo "${indent} nux.log trace ' ' arg $arg: "'$'$arg";"
|
||||
done
|
||||
}
|
||||
|
||||
.block.start.plan() {
|
||||
case $identifier in
|
||||
function) echo "$line";;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
nux.use nux/color
|
||||
nux.use nuxr/repl
|
||||
|
||||
|
|
@ -86,7 +85,7 @@ nux.use nuxr/repl
|
|||
local task_dot=$(tr " " "." <<< "$task")
|
||||
nux.log trace "Trying to figure task documentation location for $task $task_dot"
|
||||
doc_start=$(grep -hn -E "## +($task)::" "$script" | cut -d: -f1)
|
||||
code_start=$(grep -hn -E "((function +task.$task_dot)|(task.$task_dot *\(\))) +{" "$script" | cut -d: -f1)
|
||||
code_start=$(grep -hn -E "((@command +:?$task_dot .*)|(function +task.$task_dot)|(task.$task_dot *\(\))) +{" "$script" | cut -d: -f1)
|
||||
nux.log trace "doc_start" $doc_start $code_start
|
||||
if [ -n "$doc_start" -a -n "$code_start" ] {
|
||||
sed -n "$doc_start,$code_start"p "$script" \
|
||||
|
|
@ -96,6 +95,6 @@ nux.use nuxr/repl
|
|||
return 0
|
||||
else
|
||||
return -1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,3 +30,8 @@ backend.github.detect() {
|
|||
echo $repo:$closest_git
|
||||
done
|
||||
}
|
||||
|
||||
backend.github.labels.id() {
|
||||
githublike.get "labels" \
|
||||
| jq -r ".[] | .name + \":\" + .name"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,9 +9,12 @@ githublike.common.issue.list() {
|
|||
|
||||
githublike.common.issue.exists() {
|
||||
local message="$@"
|
||||
nux.json.start
|
||||
nux.json.open "$githublike_issuemap"
|
||||
id=$(nux.json.read "\"$githublike_api\".\"$githublike_repository\".\"$message\"")
|
||||
id="null"
|
||||
if [ -e "$githublike_issuemap" ]; then
|
||||
nux.json.start
|
||||
nux.json.open "$githublike_issuemap"
|
||||
id=$(nux.json.read "\"$githublike_api\".\"$githublike_repository\".\"$message\"")
|
||||
fi
|
||||
nux.log debug "Message Id is $id"
|
||||
test "$id" != null #-o -n "$id";
|
||||
}
|
||||
|
|
@ -29,8 +32,8 @@ githublike.common.issue.add() {
|
|||
|
||||
nux.json.write title "$message"
|
||||
nux.json.write message "$message"
|
||||
if [ -n "labelId" ]; then
|
||||
nux.json.write.raw labels[0] $labelId
|
||||
if [ -n "$labelId" ]; then
|
||||
nux.json.write labels[0] $labelId
|
||||
fi
|
||||
local payload=$(nux.json.flush)
|
||||
|
||||
|
|
@ -58,16 +61,15 @@ githublike.get() {
|
|||
nux.log debug Repository is $githublike_repository, message is $message
|
||||
nux.log debug API call: $api Payload: $payload
|
||||
header_tmp=$(mktemp);
|
||||
while [ -n "$api" ];
|
||||
do
|
||||
curl $githublike_curl_params -s -D "$header_tmp" -H "Content-Type: application/json" "$api"
|
||||
next=$(grep "Link: " "$header_tmp" | tr "," "\n" | grep rel=\"next\" | cut -d"<" -f2 | cut -d">" -f1)
|
||||
nux.log debug Next "$next";
|
||||
if [ -n "$next" ]; then
|
||||
api="${next}${githublike_next_append}"
|
||||
else
|
||||
api=""
|
||||
fi
|
||||
while [ -n "$api" ]; do
|
||||
curl $githublike_curl_params -s -D "$header_tmp" -H "Content-Type: application/json" "$api"
|
||||
next=$(grep "Link: " "$header_tmp" | tr "," "\n" | grep rel=\"next\" | cut -d"<" -f2 | cut -d">" -f1)
|
||||
nux.log debug Next "$next";
|
||||
if [ -n "$next" ]; then
|
||||
api="${next}${githublike_next_append}"
|
||||
else
|
||||
api=""
|
||||
fi
|
||||
done;
|
||||
rm -f $header_tmp;
|
||||
}
|
||||
|
|
@ -77,6 +79,7 @@ githublike.post() {
|
|||
local api="${githublike_api}/repos/${githublike_repository}/${resource}${githublike_api_append}"
|
||||
local payload="$2"
|
||||
nux.log debug POST API call: $api Payload: $payload
|
||||
nux.log trace curl $githublike_curl_params -s -H "Content-Type: application/json" -X POST -d "$payload" "$api"
|
||||
curl $githublike_curl_params -s -H "Content-Type: application/json" -X POST -d "$payload" "$api"
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue