1
1
Fork 0
mirror of https://github.com/tonydamage/nux-env.git synced 2025-12-13 13:44:28 +01:00

Compare commits

...

4 commits

Author SHA1 Message Date
8b3ae7ac0b Use graphicsmagick if possible.
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
2019-11-28 12:20:36 +01:00
8cc7401fe2 Mark: fixed relative link creation
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
2019-11-28 02:49:46 -08:00
384320ffad nux.dsl: Fixed mktemp call
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
2019-11-28 02:49:26 -08:00
b924ba5c29 Added mark tool for managing .by directory
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
2019-11-28 11:20:24 +01:00
6 changed files with 122 additions and 7 deletions

110
bin/mark Executable file
View file

@ -0,0 +1,110 @@
#!/usr/bin/env nuxr-nuxsh
nux.use nuxfs
MARK_DIR_NAME=.by
MARK_PREFIX=""
@namespace nuxfs. {
function :path.relative base target {
realpath -Lms --relative-to="$base" "$target"
}
function :path.display target {
echo $NC_LightPurple$(nuxfs.relative-to-pwd "$target")$NC_No
}
function :symlink target dir name {
relative=$(nuxfs.path.relative "$dir" "$target")
nux.log debug "Relative path is: $relative"
:stage mkdir -p "$dir"
if [ -n "$name" ]; then
:stage ln -sf "$relative" "$dir/$name"
else
:stage ln -sf "$relative" "$dir"
fi
}
function :stage {
if [ -n "$NUXFS_STAGE" ]; then
echo "[stage]" "$@"
else
"$@"
fi
}
}
## 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
echo $MARK_DIR;
else
nuxfs.closest "$MARK_DIR_NAME" "$item"
fi
}
function :mark root item mark {
nuxfs.info "$item" Creating symlink in $(nuxfs.path.display "$root/$mark")
nuxfs.symlink "$item" "$root/$mark"
}
}
@namespace task. {
## tag:: <task> <task arguments...>
## Performs specified task in tag namespace (marks prefixed with **tag/**)
function :tag task {
MARK_PREFIX="tag/"
nuxr.run "$task" "$@"
}
## this:: <mark> [marks...]
## Marks **current folder** with specific markers.
## This creates symlinks in **mark** folder pointing to **current folder**.
function :this mark {
nux.log debug "Args $#"
item=$(pwd)
mark_root=$(mark.dir "$item")
mark.mark "$mark_root" "$item" "$MARK_PREFIX$mark"
while [ "$#" -gt 0 ]; do
mark="$1"; shift;
mark.mark "$mark_root" "$item" "$MARK_PREFIX$mark"
done
}
## multiple:: <mark> <files...>
## Marks **files** with specific **mark**.
## This creates symlinks for files in **mark** folder.
function :multiple mark {
pwd=$(pwd)
mark_root=$(mark.dir "$pwd")
while [ "$#" -gt 0 ]; do
item="$1"; shift;
mark.mark "$mark_root" "$pwd/$item" "$MARK_PREFIX$mark"
done
}
## display:: [mark]
## Displays path to current mark folder and displays available marks.
## If **mark** is provided list nested marks.
function :display mark {
mark_root=$(mark.dir $pwd)
prefix="$MARK_PREFIX"
if [ -n "$mark" ]; then
prefix="$MARK_PREFIX$mark/";
fi
echo $mark_root:
(
cd $(mark_root);
for mark in "$prefix"* ; do
echo ${mark#$MARK_PREFIX};
done;
)
}
}

View file

@ -1,7 +1,9 @@
#!/usr/bin/env nuxr-nuxsh
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
QUALITY=${QUALITY:=90}
@ -36,10 +38,10 @@ QUALITY=${QUALITY:=90}
target_file="${target_dir}/$name";
fi
echo "Image: $i/$count Downsampling $image -> $target_file"
convert $image \
$NUX_MAGICK convert $image \
-filter Lanczos -sampling-factor 1x1 \
-resize "${SIZE}x${SIZE}>" \
-quality 90 \
-quality $QUALITY \
$target_file
done
}
@ -66,5 +68,5 @@ QUALITY=${QUALITY:=90}
}
function media.to.jpg {
convert "$1" -quality $QUALITY -auto-orient "$2"
$NUX_MAGICK convert "$1" -quality $QUALITY -auto-orient "$2"
}

View file

@ -107,7 +107,7 @@ nux.dsl.plan() {
local dirname=$(dirname "$cached")
mkdir -p "$dirname";
local execution_plan=$(mktemp "$dirname/.nux.dsl.XXXX")
local execution_plan=$(mktemp -p "$dirname" .nux.dsl.XXXXXXXX)
if (nux.dsl.process plan "$language" "$file" > "$execution_plan") ; then
mv -f "$execution_plan" "$cached";
else

View file

@ -3,7 +3,7 @@ function nuxfs.relative {
}
function nuxfs.relative-to-pwd {
realpath -m -s "$1" --relative-to "$(realpath "$(pwd)")"
realpath -Lms "$1" --relative-to "$(pwd)"
}
function nuxfs.error {

View file

@ -7,6 +7,7 @@ nux.use nuxr/repl
@namespace nuxr. {
function :run TASK {
# FIXME: Add default task
if check:function task.$TASK {
nux.log debug "Running task: $TASK";
nux.log debug "Working dir: $(pwd)"

View file

@ -1,5 +1,7 @@
nux.use nux.mime
type gm /dev/null 2>&1 && NUX_MAGICK=gm
function thumby.name.shared() {
echo $(basename "$1"|md5sum|cut -d " " -f1).png
}
@ -81,7 +83,7 @@ function thumby.thumb.get() {
$preexec "$path"
nux.log info "Source is : $source, Streamer is $streamer";
$streamer "$path" | convert -thumbnail '256x256>' -strip "$source" "$thumbpath" >&2
$streamer "$path" | $NUX_MAGICK convert -thumbnail '256x256>' -strip "$source" "$thumbpath" >&2
$postexec "$path"
echo $thumbpath;
fi
@ -89,7 +91,7 @@ function thumby.thumb.get() {
}
function thumby.thumb.generate() {
convert -thumbnail '256x256>' -strip "$path" "$thumbpath" >&2
$NUX_MAGICK convert -thumbnail '256x256>' -strip "$path" "$thumbpath" >&2
}
function thumby.get.thumb() {