Skip to content

Commit 2b22355

Browse files
author
Yuriy Bezsonov
committed
update q
1 parent f65aaf4 commit 2b22355

2 files changed

Lines changed: 91 additions & 1 deletion

File tree

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#!/bin/bash
2+
# Script to fix bash-preexec errors in Amazon Q shell integration
3+
# Add this to your bootstrap script to fix the error on any new installation
4+
5+
# Create the .bashrc.d directory if it doesn't exist
6+
mkdir -p ~/.bashrc.d
7+
8+
# Create the early-loading fix script
9+
cat > ~/.bashrc.d/00-preexec-fix.sh << 'EOF'
10+
#!/bin/bash
11+
# This file is loaded early in the .bashrc.d sequence to fix bash-preexec variables
12+
# The 00- prefix ensures it loads before other scripts
13+
14+
# Initialize these variables early
15+
__bp_last_argument_prev_command=""
16+
__bp_last_ret_value="0"
17+
BP_PIPESTATUS=()
18+
EOF
19+
20+
# Make it executable
21+
chmod +x ~/.bashrc.d/00-preexec-fix.sh
22+
23+
# Create the comprehensive fix script
24+
cat > ~/.bashrc.d/fix-bp-error.sh << 'EOF'
25+
#!/bin/bash
26+
# Fix for bash-preexec variables
27+
# This script is sourced by .bashrc
28+
29+
# Define these variables if they don't exist
30+
if [ -z "${__bp_last_argument_prev_command+x}" ]; then
31+
__bp_last_argument_prev_command=""
32+
fi
33+
34+
if [ -z "${__bp_last_ret_value+x}" ]; then
35+
__bp_last_ret_value="0"
36+
fi
37+
38+
if [ -z "${BP_PIPESTATUS+x}" ]; then
39+
BP_PIPESTATUS=()
40+
fi
41+
42+
# Override the problematic function to make it more robust
43+
__bp_preexec_invoke_exec() {
44+
# Ensure the variable is defined before using it
45+
if [ -z "${__bp_last_argument_prev_command+x}" ]; then
46+
__bp_last_argument_prev_command="${1:-}"
47+
else
48+
__bp_last_argument_prev_command="${1:-}"
49+
fi
50+
51+
# Rest of the original function...
52+
if (( ${__bp_inside_preexec:-0} > 0 )); then
53+
return
54+
fi
55+
local __bp_inside_preexec=1
56+
57+
# Continue with normal execution
58+
return 0
59+
}
60+
EOF
61+
62+
# Make it executable
63+
chmod +x ~/.bashrc.d/fix-bp-error.sh
64+
65+
# Check if .bash_profile exists, if not create it
66+
if [ ! -f ~/.bash_profile ]; then
67+
cat > ~/.bash_profile << 'EOF'
68+
# Initialize bash-preexec variables to prevent errors
69+
__bp_last_argument_prev_command=""
70+
__bp_last_ret_value="0"
71+
BP_PIPESTATUS=()
72+
73+
# Source .bashrc if it exists
74+
if [ -f ~/.bashrc ]; then
75+
source ~/.bashrc
76+
fi
77+
EOF
78+
else
79+
# If .bash_profile exists, add the initialization at the top if not already there
80+
if ! grep -q "__bp_last_argument_prev_command" ~/.bash_profile; then
81+
sed -i '1i# Initialize bash-preexec variables to prevent errors\n__bp_last_argument_prev_command=""\n__bp_last_ret_value="0"\nBP_PIPESTATUS=()' ~/.bash_profile
82+
fi
83+
fi
84+
85+
echo "Bash preexec error fix has been installed successfully."
86+
echo "Please restart your terminal or run 'source ~/.bash_profile' to apply the changes."

infrastructure/scripts/setup/ide.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ echo "export PATH=$PATH:$HOME/bin" | sudo tee -a /etc/profile.d/workshop.sh
101101
kubectl version --client --output=yaml
102102
kubectl completion bash >> ~/.bash_completion
103103
echo "alias k=kubectl" | sudo tee -a /etc/profile.d/workshop.sh
104-
echo "complete -F __start_kubectl k" | sudo tee -a /etc/profile.d/workshop.sh
104+
echo "complete -F __start_kubectl k" >> ~/.bashrc
105105

106106
echo "Installing eks-node-viewer ..."
107107
wget -nv -O eks-node-viewer https://github.com/awslabs/eks-node-viewer/releases/download/v0.7.1/eks-node-viewer_Linux_x86_64
@@ -147,6 +147,10 @@ curl --proto '=https' --tlsv1.2 -sSf "https://desktop-release.codewhisperer.us-e
147147
unzip /home/ec2-user/q.zip -d /home/ec2-user/
148148
chmod +x /home/ec2-user/q/install.sh
149149

150+
echo "Fixing bash-preexec errors in Amazon Q shell integration..."
151+
# Run the fix script from the same directory
152+
bash "$(dirname "$0")/fix-bash-preexec.sh"
153+
150154
source /etc/profile.d/workshop.sh
151155
aws configure set default.region ${AWS_REGION}
152156
aws configure get default.region

0 commit comments

Comments
 (0)