1
1
Fork 0
mirror of https://github.com/tonydamage/nux-env.git synced 2025-12-11 13:24:28 +01:00
nux-env/bin/mvln
Tony Tkacik fc1b5bbc87 Added taskie configuration & other stuff.
Signed-off-by: Tony Tkacik <tonydamage@gmail.com>
2019-01-28 06:22:49 +01:00

49 lines
989 B
Bash
Executable file

#!/usr/bin/env bash
declare -a sources
target=$1; shift;
i=0
while [ "$#" -gt 0 ]; do
sources[$i]="$1";
shift;
let i=i+1;
done
function move-and-link-to-folder {
local s="$1"; shift;
local target="$1"; shift;
local name=$(basename "$s");
local sdir=$(dirname "$s");
local target_path=$(realpath -Ls --relative-to="$sdir" "$target/$name" )
mv "$s" "$target"
ln -sf "$target_path" "$s"
}
function move-and-link {
local s="$1"; shift;
local target="$1"; shift;
local sdir=$(dirname "$s");
local target_path=$(realpath -Ls --relative-to="$sdir" "$target" )
mv "$s" "$target"
ln -sf "$target_path" "$s"
}
if [ "$i" -gt 1 ]; then
if [ -d "$target" ]; then
for s in "${sources[@]}"; do
move-and-link-to-folder "$s" "$target"
done
else
echo "Target $target is not directory."
exit 1
fi
else
s="${sources[0]}"
if [ -d "$target" ]; then
move-and-link-to-folder "$s" "$target"
else
move-and-link "$s" "$target"
fi
fi