#!/bin/bash show_help() { echo "ln+ - Enhanced symbolic link creator" echo "" echo "Usage: ln+ " echo "" echo "Creates symbolic links with interactive path options:" echo " f - filename only (relative path)" echo " p - full path from current directory (absolute path)" echo "" echo "Key difference between options:" echo " • Relative (f): Link uses source path as-is. May break if target is moved" echo " to a different directory, but works well for links in the" echo " same directory or predictable relative locations." echo "" echo " • Absolute (p): Link uses full system path. Works regardless of where" echo " the target link is moved, but ties the link to the" echo " current absolute location of the source." echo "" echo "Example usage:" echo " ln+ myfile.txt ~/Desktop/link_to_myfile" echo " → Prompts to choose between:" echo " f: Creates link pointing to 'myfile.txt'" echo " p: Creates link pointing to '/full/path/to/myfile.txt'" echo "" echo "Options:" echo " -h, --help Show this help message" } if [[ "$1" == "-h" || "$1" == "--help" ]]; then show_help exit 0 fi if [ "$#" -ne 2 ]; then echo "Error: Incorrect number of arguments" echo "" show_help exit 1 fi source="$1" target="$2" # Check if source exists if [ ! -e "$source" ]; then echo "Warning: Source '$source' does not exist" echo "Continue anyway? (y/n)" read -n 1 confirm echo "" if [[ "$confirm" != "y" && "$confirm" != "Y" ]]; then echo "Operation cancelled" exit 1 fi fi # Check if target already exists if [ -e "$target" ]; then echo "Target '$target' already exists. Overwrite? (y/n)" read -n 1 overwrite echo "" if [[ "$overwrite" != "y" && "$overwrite" != "Y" ]]; then echo "Operation cancelled" exit 1 fi fi echo "How do you want to link '$source' to '$target'?" echo "f - filename only (relative path)" echo "p - full path from current directory (absolute path)" echo "h - show help with detailed explanation" echo "any other key - cancel" read -n 1 choice echo "" # new line after choice case "$choice" in f) echo "Creating relative link..." echo "Running: ln -sf '$source' '$target'" ln -sf "$source" "$target" if [ $? -eq 0 ]; then echo "✓ Symbolic link created successfully" echo " Link: $target → $source" else echo "✗ Failed to create symbolic link" exit 1 fi ;; p) fullsource="$(pwd)/$source" echo "Creating absolute link..." echo "Running: ln -sf '$fullsource' '$target'" ln -sf "$fullsource" "$target" if [ $? -eq 0 ]; then echo "✓ Symbolic link created successfully" echo " Link: $target → $fullsource" else echo "✗ Failed to create symbolic link" exit 1 fi ;; h) echo "" show_help exit 0 ;; *) echo "Operation cancelled" exit 1 ;; esac