Created
November 2, 2017 20:01
-
-
Save alisonspencer/28da1964113d7d7cb5d8e5fc16916069 to your computer and use it in GitHub Desktop.
.d bash profile config
This file contains 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
# .bash_profile | |
# added by Anaconda3 5.0.0 installer | |
export PATH="/Users/aspencer/anaconda3/bin:$PATH" | |
# Source global definitions | |
if [ -f /etc/bashrc ]; then | |
. /etc/bashrc | |
fi | |
# Source bash autocompletion | |
if [ -f $(brew --prefix)/etc/bash_completion ]; then | |
. $(brew --prefix)/etc/bash_completion | |
fi | |
# Uncomment the following line if you don't like systemctl's auto-paging feature: | |
# export SYSTEMD_PAGER= | |
# User specific aliases and functions | |
# [ -r /home/aspencer/.byobu/prompt ] && . /home/aspencer/.byobu/prompt #byobu-prompt# | |
# User specific environment and startup programs | |
# PATH=$PATH:$HOME/.local/bin:$HOME/bin | |
# export PATH | |
# aliases | |
# sublime | |
alias subl="open -a /Applications/Sublime\ Text.app" | |
# git | |
alias g="git status" | |
# jupyter | |
alias j3="source activate py3 && jupyter notebook" | |
alias j="jupyter notbook" | |
# some more ls aliases | |
alias ll='ls -alFGh' | |
alias la='ls -AGh' | |
alias l='ls -CFGh' | |
alias grep='grep --color=auto' | |
alias fgrep='fgrep --color=auto' | |
alias egrep='egrep --color=auto' | |
alias ..="cd .." | |
alias ...="cd ../.." | |
alias ....="cd ../../.." | |
alias .....="cd ../../../.." | |
alias histg="history | grep" | |
# Make Sure deletes are prompted | |
#alias rm='rm –i' | |
# parse_git_branch() { | |
# git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/' | |
# } | |
# export PS1="\u \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] $ " | |
# export PS1="\n \$(parse_git_branch)\[\033[00m\] \$ \u \[\033[32m\]\w -> \[\e[0m\]" | |
#PS1='${debian_chroot:+($debian_chroot)}\u(\h):\w\$ ' | |
# PS1="\n\[\e[32;1m\](\[\e[37;1m\]\u\[\e[32;1m\])-(\[\e[37;1m\]jobs:\j\[\e[32;1m\])-(\[\e[37;1m\]\w\[\e[32;1m\])\n(\[\[\e[37;1m\]! \!\[\e[32;1m\])-> \[\e[0m\]" | |
# PS1="\n\[\e[32;1m\](\[\e[37;1m\]\u\[\e[32;1m\])-(\[\e[37;1m\]jobs:\j\[\e[32;1m\])-(\[\e[37;1m\]\w\[\e[32;1m\])\n(\[\[\e[37;1m\]! \!\[\e[32;1m\])-> \[\e[0m\]" | |
# username \n\[\e[32;1m\](\[\e[37;1m\]\u\[\e[32;1m\])- | |
# jobs (\[\e[37;1m\]jobs:\j\[\e[32;1m\])- | |
# (\[\e[37;1m\]\w\[\e[32;1m\])\n | |
# (\[\[\e[37;1m\]! \!\[\e[32;1m\])-> \[\e[0m\]" | |
function color_my_prompt { | |
local reset=$(tput sgr0) | |
local bold=$(tput bold) | |
local black=$(tput setaf 0) | |
local red=$(tput setaf 1) | |
local green=$(tput setaf 2) | |
local yellow=$(tput setaf 3) | |
local blue=$(tput setaf 4) | |
local magenta=$(tput setaf 5) | |
local cyan=$(tput setaf 6) | |
local white=$(tput setaf 7) | |
# local __user_and_host="\[\e[1m\]\[\033[37m\]\u" | |
# local __user_and_host="\[\033[37m\]\u" | |
# local __user_and_host="\[\033[01;32m\]\u@\h" | |
# local __cur_location="\[\033[32m\]\w" | |
# local __git_branch_color="\[\033[33m\]" | |
local __git_branch='`git branch 2> /dev/null | grep -e ^* | sed -E s/^\\\\\*\ \(.+\)$/\(\\\\\1\)\ /`' | |
local __prompt_tail="\[\033[35m\]$" | |
local __last_color="\[\033[00m\]" | |
PS1="\[$reset\]\[$bold\]\[$white\]\u \[$reset\]\[$yellow\]\w \[$reset\]\[$blue\]$__git_branch \[$magenta\]$\[$reset\] " | |
# $__user_and_host - \[$reset\]\[$(tput setaf 2)\]$__cur_location - $__git_branch_color$__git_branch$__prompt_tail$__last_color " | |
# PS1="$__user_and_host - $__cur_location - $__git_branch_color$__git_branch$__prompt_tail$__last_color " | |
} | |
color_my_prompt | |
# handy extract function for various archives | |
extract () { | |
if [ -f $1 ] ; then | |
case $1 in | |
*.tar.bz2) tar xjf $1 ;; | |
*.tar.gz) tar xzf $1 ;; | |
*.bz2) bunzip2 $1 ;; | |
*.rar) rar x $1 ;; | |
*.gz) gunzip $1 ;; | |
*.tar) tar xf $1 ;; | |
*.tbz2) tar xjf $1 ;; | |
*.tgz) tar xzf $1 ;; | |
*.zip) unzip $1 ;; | |
*.Z) uncompress $1 ;; | |
*.7z) 7z x $1 ;; | |
*) echo "'$1' cannot be extracted via extract()" ;; | |
esac | |
else | |
echo "'$1' is not a valid file" | |
fi | |
} | |
# aws | |
export USERNAME="aspencer" | |
export PEMPATH="~/Documents/abtsciences.pem" | |
alias sshaws="ssh -i ${PEMPATH} -X -o ServerAliveInterval=120" | |
alias myec2="aws ec2 describe-instances --filters \"Name=tag:user,Values=${USERNAME}\" --query 'Reservations[*].Instances[*].{Name:Tags[?Key==\`Name\`].Value|[0],PublicDns:PublicDnsName,Type:InstanceType,InstanceId:InstanceId,State:State.Name}'" | |
alias myec2_full="aws ec2 describe-instances --filters \"Name=tag:user,Values=${USERNAME}\"" | |
spinup() { aws ec2 start-instances --instance-ids "$1"; } | |
spindown() { aws ec2 stop-instances --instance-ids "$1"; } | |
ec2id() { echo `aws ec2 describe-instances --filters "Name=tag:Name,Values=${1}" --query 'Reservations[*].Instances[*].{InstanceId:InstanceId}' --output text`; } | |
ec2ssh() { | |
EC2_INSTANCE_NAME=$1; | |
AWSOUT=`aws ec2 describe-instances --filters "Name=tag:Name,Values=${EC2_INSTANCE_NAME}" --query 'Reservations[*].Instances[*].{InstanceId:InstanceId,State:State.Name,IP:PrivateIpAddress}' --output text`; | |
IFS=$'\t' read -r -a ec2_array <<< "$AWSOUT"; | |
EC2_IP=${ec2_array[0]}; | |
EC2_ID=${ec2_array[1]}; | |
EC2_STATUS=${ec2_array[2]}; | |
echo -e "\033[1;34mInstance Name:\033[0m\t${EC2_INSTANCE_NAME}"; | |
echo -e "\033[1;34mInstance ID:\033[0m\t${EC2_ID}"; | |
echo -e "\033[1;34mPrivate IP:\033[0m\t${EC2_IP}\n"; | |
EC2_LAUNCHED=0; | |
case ${EC2_STATUS} in | |
running) | |
echo -e "\033[1;34mStatus:\033[0m\t\t\033[32m${EC2_STATUS}\033[0m\n"; | |
echo -e "Connecting...\n" | |
sshaws ec2-user@${EC2_IP} | |
;; | |
stopped|terminated) | |
echo -e "\033[1;34mStatus:\033[0m\t\t\033[31m${EC2_STATUS}\033[0m" | |
echo -e "Launching...\n" | |
aws ec2 start-instances --instance-ids "${EC2_ID}" | |
printf "\nWaiting" | |
until [ ${EC2_LAUNCHED} -eq 1 ]; do | |
CURRENT_STATUS=`aws ec2 describe-instances --filters "Name=tag:Name,Values=${EC2_INSTANCE_NAME}" --query 'Reservations[*].Instances[*].{State:State.Name}' --output text`; | |
case ${CURRENT_STATUS} in | |
running) | |
printf "\n" | |
echo -e "Connecting...\n" | |
EC2_LAUNCHED=1 | |
sleep 2 | |
sshaws ec2-user@${EC2_IP} | |
;; | |
pending) | |
printf "." | |
sleep 1 | |
;; | |
*) | |
printf "\n" | |
echo -e "Unexpected status:\t\033[31m${CURRENT_STATUS}\033[0m" | |
exit 1; | |
esac | |
done | |
;; | |
*) | |
echo -e "\033[1;34mStatus:\033[0m\t\t${EC2_STATUS}\n"; | |
echo -e "\033[31mNot connecting\033[0m" | |
esac | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment