# Set the default editor for programs launch from terminal
EDITOR="code --wait"
VISUAL=$EDITOR  # Use the same value as for "EDITOR" in the line above


# Silence default shell note when launching bash
export BASH_SILENCE_DEPRECATION_WARNING=1

# Color text so it is easier to distinguish elements from each other
export CLICOLOR=1
export LSCOLORS=ExGxFxdxCxDxDxxbaDecac
export PS1="⚡️\[\033[01;32m\]\u\[\033[00m\]:\[\033[01;34m\]\w\[\e[38;5;236m\]\$(parse_git_branch)\[\033[00m\]: "

[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion

alias src="source ~/.bash_profile"
alias smsvpn="sudo openconnect vpn.smsequip.com -u jgordon"
alias sms="(cd ~/github/SMSEventLog && poetry run python -m run)"
alias gosms="cd ~/OneDrive/Python/SMS"
alias gopy="cd ~/OneDrive/Python"
alias jam="cd ~/OneDrive/Python/Jambot"
alias task="cd ~/OneDrive/Python/SMS && poetry run python -m scripts.actlog "
alias signsms='codesign --deep -s "SMS Event Log" "/Applications/SMS Event Log.app"'
alias profile='subl ~/.bash_profile'
alias p='poetry'
alias ps='poetry shell'
alias pr='poetry run'
alias prp='poetry run python -m'
alias ppl='pipenv run pip list'
alias bump='poetry run bumpversion --verbose'
alias flake='poetry run flake8'
alias test='poetry run pytest --log-cli-level=INFO -s'
alias pep='poetry run autopep8'
alias pepall='poetry run autopep8 --recursive --in-place'
alias sort='poetry run isort'
alias ghp='poetry run ghp-import -n -p -f docs/_build/html'
alias builddocs='jb clean docs && jb build docs'  # jupyterbook
alias makedocs='(cd docs && poetry run make html)'  # readthedocs
alias cleandocs='(cd docs && poetry run make clean)' # readthedocs
alias launch='code-insiders /Users/Jayme/.ipython/profile_default/startup/launch.py'

alias jl='jupyter-lab'
alias jn='jupyter notebook'
alias jb='poetry run jupyter-book'
alias l='ls -vlrthAF'
alias gl='git log --oneline'
alias gst='git status'
alias gs='git switch'
alias gsc='git switch -c'
alias gp='git push'
alias gpl='git pull'
alias gc='git commit -m'
alias ga='git add'
alias gap='git add -p'
alias gb='git branch'
alias gcl='git clone'

# Moving, removing, and copying ask before overwriting files
alias rm="rm -v"
alias mvi="mv -v"
alias mv="mv -vi"
alias cpi="cp -v"
alias cp="cp -vi"

alias mm='mergemain'
mergemain () {
    branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p') # get current branch as string

    git switch main
    git pull
    git switch $branch
    git merge main
}


# show git branch at prompt
parse_git_branch() {
     git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}


# TAB completion configuration
# TAB completion ignores case
bind "set completion-ignore-case on"
bind "set show-all-if-ambiguous on"

# History configuration
# Cycle through history based on characters already typed on the line
bind '"\e[A":history-search-backward'
bind '"\e[B":history-search-forward'
# Append to the history file, don't overwrite it.
shopt -s histappend
# Write commands to history one-by-one right after they are executed
# instead of all together when the terminal is closed.
# Make new terminals see all commands run in currently open terminals and
# prepend a newline to the prompt string to separate it from the last command's output
PROMPT_COMMAND='history -a; echo'
# Increase history size
HISTSIZE=50000
HISTFILESIZE=50000
# eval "$(/opt/homebrew/bin/brew shellenv)"
# eval "$(/opt/homebrew/bin/brew shellenv)"
