Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1 | #! /usr/bin/env python3 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2 | |
| 3 | # Create a *relative* symlink, just like ln --relative does but without needing |
| 4 | # coreutils 8.16. |
| 5 | |
| 6 | import sys, os |
| 7 | |
| 8 | if len(sys.argv) != 3: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 9 | print("$ lnr TARGET LINK_NAME") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 10 | sys.exit(1) |
| 11 | |
| 12 | target = sys.argv[1] |
| 13 | linkname = sys.argv[2] |
| 14 | |
| 15 | if os.path.isabs(target): |
| 16 | if not os.path.isabs(linkname): |
| 17 | linkname = os.path.abspath(linkname) |
| 18 | start = os.path.dirname(linkname) |
| 19 | target = os.path.relpath(target, start) |
| 20 | |
| 21 | os.symlink(target, linkname) |