-
-
Save oficsu/8ca64136f9b8fb0d8a883bffd81e849b to your computer and use it in GitHub Desktop.
Simple ln wrapper with more intuitive syntax (link name and target path are swapped, symbolic by default)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
backup=false | |
control="" | |
force=false | |
interactive=false | |
logical=false | |
dereference=true | |
relative=false | |
symbolic=true | |
suffix="" | |
verbose=false | |
positional=() | |
count=0 | |
while [[ $# -gt 0 ]]; do | |
case "$1" in | |
-b) | |
backup=true | |
shift;; | |
--backup) | |
backup=true | |
control="$2" | |
shift; shift;; | |
-f|--force) | |
force=true | |
shift;; | |
-i|--interactive) | |
interactive=true | |
shift;; | |
-L|--logical) | |
logical=true | |
shift;; | |
-n|--no-dereference) | |
dereference=false | |
shift;; | |
-r|--relative) | |
relative=true | |
shift;; | |
-H|--hard) | |
symbolic=false | |
shift;; | |
-S|--suffix) | |
suffix="$2" | |
shift; shift;; | |
-v|--verbose) | |
verbose=true | |
shift;; | |
-*|--*) | |
echo "unknown option $1" | |
exit 1;; | |
*) | |
positional+=("$1") | |
((count++)) | |
shift;; | |
esac | |
done | |
if [ "$count" = 0 ]; then | |
echo -e 1>&2 you must specify link name and target path: \\n$ lk link-name target-path | |
exit 1 | |
fi | |
if [ "$count" = 1 ]; then | |
echo -e 1>&2 you must specify link target path: \\n$ lk link-name target-path | |
exit 1 | |
fi | |
if [ "$count" -gt 2 ]; then | |
echo 1>&2 too many files specified | |
exit 1 | |
fi | |
link="${positional[0]}" | |
target="${positional[1]}" | |
ln "$([ -n "$control" ] && echo --backup="$control" || $backup && echo -b)" \ | |
$($force && echo --force) \ | |
$($interactive && echo --interactive) \ | |
$($logical && echo --logical) \ | |
$(! $dereference && echo --no-dereference) \ | |
$($relative && echo --relative) \ | |
$($symbolic && echo --symbolic) \ | |
"$([ -n "$suffix" ] && echo --suffix="$suffix")" \ | |
$($verbose && echo --verbose) \ | |
"$target" \ | |
"$link" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment