Skip to content

Commit eba8203

Browse files
feat: symlink git commands
this ensures the home dir has a bin dir and is in the path, then symlinks the git commands
1 parent f812dcd commit eba8203

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

scripts/link-git-commands.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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

Comments
 (0)