|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Get the directory of the current script |
| 4 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 5 | + |
| 6 | +# Path to the 'add-bin-dir' script, assuming it's in the same directory as this script |
| 7 | +ADD_BIN_DIR_SCRIPT="$SCRIPT_DIR/add-bin-dir.sh" |
| 8 | + |
| 9 | +# Call the 'add-bin-dir' script to ensure 'bin' directory is created and in the PATH |
| 10 | +/bin/bash "$ADD_BIN_DIR_SCRIPT" |
| 11 | + |
| 12 | +# Define the directory where your 'git-' scripts are located, assuming the current directory |
| 13 | +GIT_SCRIPTS_DIR="$SCRIPT_DIR" |
| 14 | + |
| 15 | +# The 'bin' directory path |
| 16 | +BIN_DIR="$HOME/bin" |
| 17 | + |
| 18 | +# Check if the --dry flag is set |
| 19 | +DRY_RUN=false |
| 20 | +if [ "$1" == "--dry" ]; then |
| 21 | + DRY_RUN=true |
| 22 | +fi |
| 23 | + |
| 24 | +# Function to create symlinks or simulate creating them |
| 25 | +create_symlink() { |
| 26 | + local script=$1 |
| 27 | + local symlink_path="$BIN_DIR/$(basename "$script")" |
| 28 | + if [ -x "$script" ]; then # Check if the script file is executable |
| 29 | + if $DRY_RUN; then |
| 30 | + echo "Dry run: Would create symlink for $(basename "$script")" |
| 31 | + else |
| 32 | + ln -s "$script" "$symlink_path" |
| 33 | + echo "Symlink created for $(basename "$script")" |
| 34 | + fi |
| 35 | + else |
| 36 | + echo "Skipped $(basename "$script") as it is not executable." |
| 37 | + fi |
| 38 | +} |
| 39 | + |
| 40 | +# Now create symlinks for all 'git-' scripts in the 'bin' directory |
| 41 | +for script in "$GIT_SCRIPTS_DIR"/git-*; do |
| 42 | + if [[ -f "$script" ]]; then |
| 43 | + create_symlink "$script" |
| 44 | + fi |
| 45 | +done |
| 46 | + |
| 47 | +# Let the user know the operation is complete |
| 48 | +if $DRY_RUN; then |
| 49 | + echo "Dry run complete. No symlinks were actually created." |
| 50 | +else |
| 51 | + echo "All executable Git scripts have been symlinked to $BIN_DIR." |
| 52 | +fi |
0 commit comments