mirror of
https://github.com/tonydamage/nux-env.git
synced 2025-12-11 13:24:28 +01:00
Added linky and uuidify
This commit is contained in:
parent
5dcb3024c4
commit
2bf96feb5e
2 changed files with 60 additions and 0 deletions
48
bin/linky
Executable file
48
bin/linky
Executable file
|
|
@ -0,0 +1,48 @@
|
||||||
|
#!/usr/bin/env nuxsh
|
||||||
|
|
||||||
|
nux.use nux/fs
|
||||||
|
|
||||||
|
## Symlink management tool
|
||||||
|
##
|
||||||
|
|
||||||
|
## relativize:: <link>
|
||||||
|
## Converts absolute symlinks to relative ones
|
||||||
|
##
|
||||||
|
@command relativize {
|
||||||
|
for p in "$@"; do
|
||||||
|
if nux.check.file.symlink "$p"; then
|
||||||
|
target=$(nux.fs.symlink.target "$p");
|
||||||
|
|
||||||
|
if nux.fs.check.absolute "$target"; then
|
||||||
|
link_dir=$(nux.fs.dirname "$p")
|
||||||
|
link_name=$(nux.fs.name "$p")
|
||||||
|
nux.fs.info "$p" Relativizing symlink
|
||||||
|
nux.fs.symlink "$target" "$link_dir" "$link_name"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
## remove-source:: <link>
|
||||||
|
## Removes the source of a symlink and any symbolic links that were encountered
|
||||||
|
## during dereferencing.
|
||||||
|
##
|
||||||
|
@command remove-source {
|
||||||
|
for p in "$@"; do
|
||||||
|
if nux.check.file.symlink "$p"; then
|
||||||
|
target="$(realpath "$p")"
|
||||||
|
next="$p"
|
||||||
|
while [ -L "$next" ]; do
|
||||||
|
current="$next"
|
||||||
|
next=$(nux.fs.symlink.target "$current")
|
||||||
|
nux.fs.info "$current" Deleting symlink
|
||||||
|
rm "$current"
|
||||||
|
done
|
||||||
|
if [ -e "$target" ]; then
|
||||||
|
nux.fs.info "$target" Deleting source
|
||||||
|
rm "$target"
|
||||||
|
fi
|
||||||
|
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
12
bin/uuidify
Executable file
12
bin/uuidify
Executable file
|
|
@ -0,0 +1,12 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
for file in "$@"; do
|
||||||
|
name="${file##*/}";
|
||||||
|
if [[ ! "$name" =~ \.[0-9a-fA-F]{32}\. ]]; then
|
||||||
|
prefix="${file%.*}";
|
||||||
|
suffix="${file##*.}";
|
||||||
|
uuid=$(cat /proc/sys/kernel/random/uuid | tr -d "-");
|
||||||
|
echo "$file" uuidifying
|
||||||
|
mv -v "$file" "${prefix}.${uuid}.${suffix}";
|
||||||
|
fi
|
||||||
|
done
|
||||||
Loading…
Add table
Add a link
Reference in a new issue