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

Added mark tool for managing .by directory

Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
This commit is contained in:
Tony Tkáčik 2019-11-28 11:20:24 +01:00
parent 93e9f20de7
commit b924ba5c29
3 changed files with 111 additions and 1 deletions

109
bin/mark Executable file
View file

@ -0,0 +1,109 @@
#!/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 {
mark_root=$(mark.dir "$pwd")
while [ "$#" -gt 0 ]; do
item="$1"; shift;
mark.mark "$mark_root" "$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

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

View file

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