-
Notifications
You must be signed in to change notification settings - Fork 0
/
lnk
executable file
·48 lines (44 loc) · 1.09 KB
/
lnk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/bash
# A generic linker
# Usage
if [ $# != 2 -o "$1" = -h -o "$1" = --help ] ; then
echo "${0##*/} <source> <directory,linkname> — a generic linker"
exit 1
fi
# Source absolute path resolution
if [ ! -e "$1" ]; then
echo "Nonexist: "$1""
exit 1
else
if [ -d "$1" ] ; then
cd "$1"
srcname="$(pwd)"
cd "$OLDPWD"
else
dirname="${1%/*}" ; [ "$1" = "$dirname" ] && dirname="."
bsename="${1##*/}"
cd "$dirname"
srcname="$(pwd)"/"$bsename"
cd "$OLDPWD"
fi
fi
# Directory absolute path resolution
if [ -e "$2" ] ; then
if [ -d "$2" ] ; then
cd "$2"
lnkname="$(pwd)"
cd "$OLDPWD"
else
echo "Existent or non-dir.: "$2""
exit 1
fi
# Linkname absolute path resolution
else
dirname="${2%/*}" ; [ "$2" = "$dirname" ] && dirname="."
bsename="${2##*/}"
[ ! -d "$dirname" ] && { echo "Non-dir.: "$dirname"" ; exit 1 ; }
cd "$dirname"
lnkname="$(pwd)"/"$bsename"
cd "$OLDPWD"
fi
ln -svi "$srcname" "$lnkname" | awk -F ' -> ' '{ print $2 " -> " $1 }' | GREP_COLOR='1;36' grep --color=always " ‘.*$"