-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodify_private_dot_bashrc
More file actions
executable file
·51 lines (48 loc) · 1.89 KB
/
modify_private_dot_bashrc
File metadata and controls
executable file
·51 lines (48 loc) · 1.89 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
#!/bin/bash
# Chezmoi modify script for .bashrc
# This script automatically adds sourcing of .bash_env and cleans up manual additions
# Read the current .bashrc content
bashrc_content=$(cat)
# Check if .bash_env sourcing is already present
if echo "$bashrc_content" | grep -q "\.bash_env"; then
# Already present, just clean up any manual additions and output
echo "$bashrc_content" | sed '/^export PATH=".*\.pixi\/bin.*"$/d' | \
sed '/^eval "$(pixi completion/d' | \
sed '/^export PATH="\$HOME\/\.local\/bin:\$PATH"$/d'
else
# Not present — try to add after .bash_aliases section, otherwise append at end
result=$(echo "$bashrc_content" | awk '
BEGIN { found=0 }
/if \[ -f ~\/\.bash_aliases \]; then/ {
found=1
print
getline; print # print the ". ~/.bash_aliases" line
getline; print # print the "fi" line
print ""
print "# Source environment configuration (managed by chezmoi)"
print "if [ -f ~/.bash_env ]; then"
print " . ~/.bash_env"
print "fi"
next
}
# Skip manual pixi/PATH additions
/^export PATH=".*\.pixi\/bin.*"$/ { next }
/^eval "\$\(pixi completion/ { next }
/^export PATH="\$HOME\/\.local\/bin:\$PATH"$/ { next }
{ print }
END { if (!found) exit 1 }
')
if [[ $? -eq 0 ]]; then
echo "$result"
else
# .bash_aliases block not found — append sourcing at the end
echo "$bashrc_content" | sed '/^export PATH=".*\.pixi\/bin.*"$/d' | \
sed '/^eval "$(pixi completion/d' | \
sed '/^export PATH="\$HOME\/\.local\/bin:\$PATH"$/d'
echo ""
echo "# Source environment configuration (managed by chezmoi)"
echo "if [ -f ~/.bash_env ]; then"
echo " . ~/.bash_env"
echo "fi"
fi
fi