diff --git a/scripts/ezlink b/scripts/ezlink new file mode 100755 index 0000000..13ae9f6 --- /dev/null +++ b/scripts/ezlink @@ -0,0 +1,60 @@ +#! /usr/bin/env python +import argparse +import sys +import logging +import subprocess +from pathlib import Path + +logger = logging.getLogger(__name__) + + +def main() -> int: + # Handle program arguments + ap = argparse.ArgumentParser(prog="ezlink", description="Easier symlink took") + ap.add_argument("pointer", help="Link that points to the destination", type=Path) + ap.add_argument("destination", help="Destination of the link", type=Path) + ap.add_argument( + "-f", "--force", help="Force the link to be created", action="store_true" + ) + ap.add_argument( + "--hard", help="Link directly to the destination inode", action="store_true" + ) + ap.add_argument("--absolute", "-a", help="Use absolute paths", action="store_true") + ap.add_argument( + "--dereference-destination", + help="Follow the destination if it is also a pointer", + action="store_true", + ) + ap.add_argument( + "--dry-run", help="Don't actually create the link", action="store_true" + ) + args = ap.parse_args() + + # Convert to absolute paths if requested + if args.absolute: + args.pointer = args.pointer.absolute() + args.destination = args.destination.absolute() + + # Construct the appropriate LN command + command = ["ln"] + if not args.dereference_destination: + command.append("-n") + if not args.hard: + command.append("-s") + if args.force: + command.append("-f") + command.append(str(args.destination)) + command.append(str(args.pointer)) + + # Print the command + print(" ".join(command)) + + # Run the command if not a dry run + if not args.dry_run: + return subprocess.run(command).returncode + + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/scripts/ezlink3 b/scripts/ezlink3 new file mode 100755 index 0000000..627dea3 --- /dev/null +++ b/scripts/ezlink3 @@ -0,0 +1,4 @@ +#! /bin/bash +set -e + +python3 $(which ezlink) $@ \ No newline at end of file