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

nux.fs: Added additional helper methods

This commit is contained in:
Tony Tkáčik 2023-08-24 10:56:03 +02:00
parent c270ae9d55
commit 8c3dd50750

View file

@ -7,8 +7,30 @@ nux.use nux/check
check:file.exists "$target";
}
function :check.absolute target {
case "$target" in
/*) return 0;;
esac
return 1
}
function :name file {
echo "${file##*/}";
}
function :dirname file {
case "$file" in
*/*)
echo "${file%/*}"
;;
*)
echo ".";;
esac
}
function :closest target {
cdir="${2:-$(pwd)}";
nux.log trace "Secondary Path" "$@"
cdir=$(realpath -m "${1:-$(pwd)}");
nux.log trace "Searching in: " $cdir;
until [ -e "$cdir/$target" -o "$cdir" == "/" ]; do
cdir=$(dirname "$cdir");
@ -20,17 +42,25 @@ nux.use nux/check
}
function :path.relative.pwd target {
realpath -Lms --relative-to="$(pwd)" "$target"
:path.relative "." "$target"
}
function :path.relative base target {
realpath -Lms --relative-to="$base" "$target"
}
function :symlink.target symlink {
readlink "$symlink";
}
function :path.display target {
echo $NC_LightPurple$(nux.fs.path.relative.pwd "$target")$NC_No;
}
function :move target {
:stage mv -t "$target" "$@"
}
function :symlink target dir name {
relative=$(nux.fs.path.relative "$dir" "$target")
nux.log debug "Relative path is: $relative"