Last active
February 14, 2019 00:57
-
-
Save rednebmas/2848a3567a15c0ede39394d0842af0c4 to your computer and use it in GitHub Desktop.
My bash profile
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
| ## homebrew | |
| export PATH="/usr/local/sbin:$PATH" | |
| ### aliases and functions | |
| alias gits='git status' | |
| alias gitbr='git branch ' | |
| alias reload='source ~/.bash_profile' | |
| alias b_p='vim ~/.bash_profile' | |
| alias grep='grep --color' | |
| alias ls='ls -1' # each file/folder on it's own line | |
| # Prevent 'Display all 1726 possibilities' message if you accidentally press tab with nothing at the command line | |
| shopt -s no_empty_cmd_completion | |
| function gitscp() { | |
| gits | egrep -o " .*$1.*$" | tr -d '\n'| pbcopy | |
| } | |
| # opens the first conflict in vim and copies the path to the clipboard so you can 'git add ' and paste after resolving | |
| function git-vim-conflict() { | |
| CONFLICT_FILE_PATH="$(git status | grep -m1 "both modified" | sed 's/.*both modified:[[:space:]]*//g')" | |
| echo $CONFLICT_FILE_PATH | tr -d '\n' | pbcopy | |
| vim $CONFLICT_FILE_PATH | |
| } | |
| function gitco() { | |
| git branch | grep -m1 "$1" | sed 's/ //g' | xargs git checkout | |
| } | |
| function git-() { | |
| git checkout - | |
| } | |
| function g-() { | |
| git checkout - | |
| } | |
| # git branch autocomplete | |
| # need to run the following curl command | |
| # curl https://raw.githubusercontent.com/git/git/master/contrib/completion/git-completion.bash -o ~/.git-completion.bash | |
| if [ -f ~/.git-completion.bash ]; then | |
| . ~/.git-completion.bash | |
| fi | |
| ## case insensitive cd autocomplete | |
| ## http://superuser.com/a/435127 | |
| bind "set completion-ignore-case on" | |
| bind "set show-all-if-ambiguous on" | |
| ## fuzzy cd http://stackoverflow.com/a/19987546/337934 | |
| function joinstr { local IFS="$1"; shift; echo "$*"; } | |
| function fcd { cd $(joinstr \* $(echo "$*" | fold -w1))*; } | |
| ######### | |
| ## Prompt Colors | |
| # https://wiki.archlinux.org/index.php/Color_Bash_Prompt#List_of_colors_for_prompt_and_Bash | |
| # http://www.cyberciti.biz/faq/bash-shell-change-the-color-of-my-shell-prompt-under-linux-or-unix/ | |
| ######### | |
| BRIGHT_GREEN="0;92m" | |
| BRIGHT_CYAN="0;96m" | |
| BRIGHT_WHITE="0;97m" | |
| BRIGHT_RED="1;91m" | |
| BRIGHT_PURPLE="1;95m" | |
| # Set these to values from above | |
| COLOR_1="$BRIGHT_WHITE" | |
| COLOR_2="$BRIGHT_RED" | |
| ## Command line prompt | |
| PS1_TEXT="\n\W \$(parse_git_branch_paren_wrapper)$" | |
| PS1="\e[$COLOR_1$PS1_TEXT\e[m " | |
| export PS1="\[\033[$BRIGHT_RED\]$PS1_TEXT \[\033[0m\]" | |
| # on enter, alternate colors | |
| # http://apple.stackexchange.com/questions/128998/how-to-open-a-new-terminal-tab-in-current-working-directory | |
| export PROMPT_COMMAND="update_terminal_cwd; alternate_color" | |
| function parse_git_branch_paren_wrapper() { | |
| local branch=$(parse_git_branch); | |
| if [ -z "$branch" ]; then | |
| echo "" | |
| else | |
| echo "($branch) " | |
| fi | |
| } | |
| function parse_git_branch() { | |
| git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' | |
| } | |
| function alternate_color { | |
| if [ "$PS1" = "\[\033[$BRIGHT_RED\]$PS1_TEXT \[\033[0m\]" ]; then | |
| export PS1="\[\033[$BRIGHT_WHITE\]$PS1_TEXT \[\033[0m\]" | |
| else | |
| export PS1="\[\033[$BRIGHT_RED\]$PS1_TEXT \[\033[0m\]" | |
| fi | |
| } | |
| # copy current git branch to clipboard | |
| function gitbrcp() { | |
| parse_git_branch | tr -d '\n' | pbcopy | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment