Repository navigation
Expand file tree
/
Copy pathsetup
More file actions
executable file
·76 lines (58 loc) · 1.91 KB
/
Copy pathsetup
File metadata and controls
executable file
·76 lines (58 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
echo "Linking git configs..."
ln -sf $PWD/git/.gitconfig ~/
ln -sf $PWD/git/.gitignore ~/
echo "...done"
echo "Linking Claude config..."
mkdir -p ~/.claude
ln -sf $PWD/CLAUDE.md ~/.claude/CLAUDE.md
echo "...done"
echo "Linking tmux config..."
ln -sf $PWD/tmux/.tmux.conf ~/
echo "...done"
# 1. Force Bash to allow aliases inside this script environment
if [ -n "$BASH_VERSION" ]; then
shopt -s expand_aliases
export PS1='$ ' # Tricks .bashrc into bypassing its non-interactive guard
fi
DATA_FILE="aliases.txt"
# Verify the data file exists
if [ ! -f "$DATA_FILE" ]; then
echo "Error: $DATA_FILE not found!"
return 1 2>/dev/null || exit 1
fi
# Detect the active shell
USER_SHELL=$(basename "$SHELL")
case "$USER_SHELL" in
bash) TARGET_FILE="$HOME/.bashrc" ;;
zsh) TARGET_FILE="$HOME/.zshrc" ;;
fish) TARGET_FILE="$HOME/.config/fish/config.fish"; mkdir -p "$(dirname "$TARGET_FILE")" ;;
*) echo "Unsupported shell: $USER_SHELL"; return 1 2>/dev/null || exit 1 ;;
esac
echo "Reading shortcuts from $DATA_FILE and updating $TARGET_FILE..."
# Read file line by line
while IFS='=' read -r NAME CMD || [ -n "$NAME" ]; do
[[ -z "$NAME" || "$NAME" =~ ^[[:space:]]*# ]] && continue
NAME=$(echo "$NAME" | xargs)
CMD=$(echo "$CMD" | xargs)
if [ "$USER_SHELL" = "fish" ]; then
LINE_TO_ADD="alias $NAME '$CMD'"
else
LINE_TO_ADD="alias $NAME='$CMD'"
fi
if grep -qF "$LINE_TO_ADD" "$TARGET_FILE" 2>/dev/null; then
echo " [Skipped] '$NAME' already exists."
else
echo "$LINE_TO_ADD" >> "$TARGET_FILE"
echo " [Added] '$NAME'."
fi
done < "$DATA_FILE"
# 2. Instant reload logic tailored to shell behavior
echo "Reloading environment..."
if [ "$USER_SHELL" = "fish" ]; then
source "$TARGET_FILE"
else
# Sourcing directly into the active layer
. "$TARGET_FILE"
fi
echo "All aliases from $DATA_FILE are now live!"