zsh:mvln(): Create relative symlinks
When using ln's `-a` flag, absolute paths are not necessary.
This commit is contained in:
@@ -340,7 +340,7 @@ if (( $+commands[trash] )); then
|
|||||||
}
|
}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Move one or more file(s) but keep a symlink to the new location.
|
# Move one or more file(s) but keep a relative symlink to the new location.
|
||||||
mvln() {
|
mvln() {
|
||||||
if (( # < 2 )); then
|
if (( # < 2 )); then
|
||||||
printf "$0: missing file operand\n"
|
printf "$0: missing file operand\n"
|
||||||
@@ -358,10 +358,7 @@ mvln() {
|
|||||||
|
|
||||||
local file reg=0
|
local file reg=0
|
||||||
for file in "${@[1,-2]}"; do
|
for file in "${@[1,-2]}"; do
|
||||||
# NOTE: We need absolute paths here for executions like `$0 foo/bar .`
|
target="${@[-1]}"
|
||||||
# TODO: When do we want/can we use relative links? Only when file is in
|
|
||||||
# current dir?
|
|
||||||
target="${@[-1]:A}"
|
|
||||||
# If the target is a directory, `file` will end up in it
|
# If the target is a directory, `file` will end up in it
|
||||||
[[ ! -d ${@[-1]} ]] || target+="/$file:t"
|
[[ ! -d ${@[-1]} ]] || target+="/$file:t"
|
||||||
|
|
||||||
@@ -371,7 +368,7 @@ mvln() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# NOTE: `ln` does not like trailing slashes on the last argument
|
# NOTE: `ln` does not like trailing slashes on the last argument
|
||||||
ln -s "$target" "${file%/}"
|
ln -sr "$target" "${file%/}"
|
||||||
done
|
done
|
||||||
|
|
||||||
return $reg
|
return $reg
|
||||||
|
|||||||
Reference in New Issue
Block a user