Last active
July 25, 2023 03:06
-
-
Save trouni/f57a2a38b906b3b7f861983569f37456 to your computer and use it in GitHub Desktop.
Add the Decision Science folder to the PYTHON PATH
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Get the remote URL of the 'origin' remote | |
remote_url=$(git config --get remote.origin.url) | |
# Function to extract username from 'https://' URL | |
extract_username_from_https() { | |
# Remove 'https://' and trailing '.git' from the URL | |
url_without_protocol=${remote_url#https://} | |
url_without_protocol=${url_without_protocol%.git} | |
# Extract the username from the URL (everything before the first '/') | |
username=${url_without_protocol%%/*} | |
echo "$username" | |
} | |
# Function to extract username from 'git@' URL | |
extract_username_from_git() { | |
# Remove 'git@' and trailing '.git' from the URL | |
url_without_protocol=${remote_url#git@} | |
url_without_protocol=${url_without_protocol%.git} | |
# Extract the username from the URL (everything between ':' and '/') | |
username=${url_without_protocol#*:} | |
username=${username%%/*} | |
echo "$username" | |
} | |
# Check if the remote URL exists and contains 'https://' or 'git@' | |
if [[ -n "$remote_url" && ( "$remote_url" == https://* || "$remote_url" == git@* ) ]]; then | |
if [[ "$remote_url" == https://* ]]; then | |
username=$(extract_username_from_https) | |
else | |
username=$(extract_username_from_git) | |
fi | |
echo "export PYTHONPATH=\"~/SageMaker/code/$username/data-analyst-challenges/04-Decision-Science:\$PYTHONPATH\"" >> ~/.bashrc | |
exec bash | |
echo "Successfully added the Decision Folder to the PYTHONPATH. Good luck with your challenges! 💪" | |
else | |
echo "Error: Remote 'origin' URL not found or invalid." | |
exit 1 | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment