Skip to content

Instantly share code, notes, and snippets.

@Erkened
Last active January 30, 2018 15:14
Show Gist options
  • Save Erkened/01cfcff6bc7caf08920a08f8ada9a385 to your computer and use it in GitHub Desktop.
Save Erkened/01cfcff6bc7caf08920a08f8ada9a385 to your computer and use it in GitHub Desktop.
Personal bashrc and bash_profile for Terminal on Mac
#!/bin/bash
#
# echo "Loading ${HOME}/.bash_profile"
#source ~/.profile # get my PATH setup
source ~/.bashrc # get my Bash aliases
# Bash
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
# source: http://unix.stackexchange.com/questions/16120/in-bash-how-can-i-change-the-color-of-my-command-prompt
# colour codes: http://unix.stackexchange.com/questions/269077/tput-setaf-color-table-how-to-determine-color-codes
red=$(tput setaf 1)
green=$(tput setaf 2)
yellow=$(tput setaf 3)
blue=$(tput setaf 4)
reset=$(tput sgr0)
PS1='\[$red\]\u\[$reset\]@\[$green\]\h\[$reset\]:\[$blue\]\w\[$reset\]\[$yellow\]$(parse_git_branch)\[$reset\]\$ '
# Add a new line after each command output
PROMPT_COMMAND="echo"
# Ability to echo bold words
bold=$(tput bold)
normal=$(tput sgr0)
# Alias
alias ls="ls -GCF" #G for colour, C for columns, F to display a / after directories
alias clear='printf "\033c"' # Remove all the terminal output
alias purge='rm -rf ~/Library/Developer/Xcode/DerivedData' # Remove all the derived data from XCode
alias diff='git difftool'
# Functions
# Use like this: lazygit "My commit msg"
# Source: http://stackoverflow.com/questions/19595067/git-add-commit-and-push-commands-in-one
function lazygit() {
#branchName=$(git name-rev --name-only HEAD)
# You can use like git commit -a -m "$branchName $1"
echo "${bold}${green}Adding all files${reset}${normal}"
git add .
git commit -a -m "$1"
git push
}
# Use like this: lazydelete "Development"
function lazydelete() {
git push origin --delete "$1"
git branch -d "$1"
}
function lazyreload() {
#ssh-add -l #List all agent keys
ssh-add -D #Remove all agent keys
ssh-add ~/.ssh/id_rsa
}
# To check all remote branches: git branch -r
# To checkout and track a remote branch: git checkout -t origin/develop
# To stop tracking a file that is currently cached: git rm --cached ProjectFolder.xcodeproj/project.xcworkspace/xcuserdata/myUserName.xcuserdatad/UserInterfaceState.xcuserstate and git commit -m "Removed file that shouldn't be tracked"
# To define FileMerge as the default diff and merge tool:
# Tell system when Xcode utilities live:
# sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer
# Set "opendiff" as the default mergetool globally:
# git config --global merge.tool opendiff
# git config --global diff.tool opendiff
# Me
Host id_rsa
HostName gitlab.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
UseKeychain yes
AddKeysToAgent yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment