mirror of
https://github.com/tonydamage/nux-env.git
synced 2025-12-11 13:24:28 +01:00
nux.fs: Migrated functionality from nuxfs
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
This commit is contained in:
parent
c1f365db70
commit
7ed7cc48ed
3 changed files with 90 additions and 48 deletions
67
inc/nux/fs.nuxsh.sh
Normal file
67
inc/nux/fs.nuxsh.sh
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
nux.use nux/check
|
||||
@prefix check nux.check.
|
||||
|
||||
@namespace nux.fs. {
|
||||
|
||||
function :exists target {
|
||||
check:file.exists "$target";
|
||||
}
|
||||
|
||||
function :closest target {
|
||||
cdir="${2:-$(pwd)}";
|
||||
nux.log trace "Searching in: " $cdir;
|
||||
until [ -e "$cdir/$target" -o "$cdir" == "/" ]; do
|
||||
cdir=$(dirname "$cdir");
|
||||
nux.log trace "Searching in: " $cdir;
|
||||
done;
|
||||
if [ -e "$cdir/$target" ]; then
|
||||
echo "$cdir/$target";
|
||||
fi
|
||||
}
|
||||
|
||||
function :path.relative.pwd target {
|
||||
realpath -Lms --relative-to="$(pwd)" "$target"
|
||||
}
|
||||
|
||||
function :path.relative base target {
|
||||
realpath -Lms --relative-to="$base" "$target"
|
||||
}
|
||||
|
||||
function :path.display target {
|
||||
echo $NC_LightPurple$(nux.fs.path.relative.pwd "$target")$NC_No;
|
||||
}
|
||||
|
||||
function :symlink target dir name {
|
||||
relative=$(nux.fs.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
|
||||
}
|
||||
|
||||
function :error file {
|
||||
local filename=$(nux.fs.path.relative.pwd "$file");
|
||||
nux.echo.error "$filename$NC_No: $@$NC_No";
|
||||
}
|
||||
|
||||
function :warning file {
|
||||
local filename=$(nux.fs.path.relative.pwd "$file");
|
||||
nux.echo.warning "$filename$NC_No: $@$NC_No";
|
||||
}
|
||||
|
||||
function :info file {
|
||||
local filename=$(nux.fs.path.relative.pwd "$file");
|
||||
echo -e "$NC_White$filename$NC_No: $@$NC_No";
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue