summaryrefslogtreecommitdiff
path: root/scripts/lnr
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lnr')
-rwxr-xr-xscripts/lnr21
1 files changed, 21 insertions, 0 deletions
diff --git a/scripts/lnr b/scripts/lnr
new file mode 100755
index 0000000..9dacebe
--- /dev/null
+++ b/scripts/lnr
@@ -0,0 +1,21 @@
+#! /usr/bin/env python
+
+# Create a *relative* symlink, just like ln --relative does but without needing
+# coreutils 8.16.
+
+import sys, os
+
+if len(sys.argv) != 3:
+ print "$ lnr TARGET LINK_NAME"
+ sys.exit(1)
+
+target = sys.argv[1]
+linkname = sys.argv[2]
+
+if os.path.isabs(target):
+ if not os.path.isabs(linkname):
+ linkname = os.path.abspath(linkname)
+ start = os.path.dirname(linkname)
+ target = os.path.relpath(target, start)
+
+os.symlink(target, linkname)