summaryrefslogtreecommitdiffstats
path: root/scripts/lnr
blob: a2ac4fec0f225dafdc93dd42dce8b646b3ea4e14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#! /usr/bin/env python3
#
# SPDX-License-Identifier: GPL-2.0-only
#

# 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)