Skip to content

Instantly share code, notes, and snippets.

@dy-dx
Last active June 15, 2021 14:06
Show Gist options
  • Save dy-dx/8337481 to your computer and use it in GitHub Desktop.
Save dy-dx/8337481 to your computer and use it in GitHub Desktop.
My OSX .bash_profile
# shellcheck shell=bash
# shellcheck source=/dev/null
[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile
[[ -s "$HOME/.fzf.bash" ]] && source "$HOME/.fzf.bash"
export NVM_SYMLINK_CURRENT=true
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$HOME/.asdf/asdf.sh" ] && . "$HOME/.asdf/asdf.sh"
[ -s "$HOME/.asdf/completions/asdf.bash" ] && . "$HOME/.asdf/completions/asdf.bash"
# export PATH="/usr/local/bin:$PATH"
export PATH="$PATH:$HOME/bin"
export PATH="$PATH:/usr/local/sbin"
export PATH="$PATH:$HOME/.cabal/bin"
export GOPATH="$HOME/go"
export COMPOSER_HOME="$HOME/.composer"
export PATH="$PATH:$COMPOSER_HOME/vendor/bin"
export PATH="$PATH:./node_modules/.bin"
# http://docs.nvidia.com/cuda/cuda-getting-started-guide-for-mac-os-x/index.html
# export PATH="$PATH:/Developer/NVIDIA/CUDA-7.0/bin"
# export DYLD_LIBRARY_PATH="$DYLD_LIBRARY_PATH:/Developer/NVIDIA/CUDA-7.0/lib"
# alias deviceQuery="/Developer/NVIDIA/CUDA-7.0/samples/bin/x86_64/darwin/release/deviceQuery"
# http://stackoverflow.com/a/14086671/1924875
# export JAVA_HOME="$(/usr/libexec/java_home)"
# export ANT_HOME="/usr/local/opt/apache-ant"
# export HAXE_STD_PATH="/usr/local/lib/haxe/std"
export P4CONFIG="p4config.txt"
alias p4v='open /Applications/p4v.app'
export EDITOR=vim
# maxfiles
ulimit -n 8192
# maxproc
# ulimit -u 1024
# https://sanctum.geek.nz/arabesque/better-bash-history/
shopt -s histappend
HISTSIZE=100000
HISTFILESIZE=100000
HISTCONTROL=ignoreboth
HISTTIMEFORMAT="%F %T "
PROMPT_COMMAND="history -a"
### Integrate kill-ring and OSX clipboard. Requires Bash 4. ###
# https://gist.github.com/tavisrudd/1169093
# https://stackoverflow.com/questions/994563/integrate-readlines-kill-ring-and-the-x11-clipboard
shell_copy() { pbcopy; }
shell_yank() { pbpaste; }
_xdiscard() {
echo -n "${READLINE_LINE:0:$READLINE_POINT}" | shell_copy
READLINE_LINE="${READLINE_LINE:$READLINE_POINT}"
READLINE_POINT=0
}
_xkill() {
echo -n "${READLINE_LINE:$READLINE_POINT}" | shell_copy
READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}"
}
_xyank() {
CLIP=$(shell_yank)
COUNT=$(echo -n "$CLIP" | wc -c)
READLINE_LINE="${READLINE_LINE:0:$READLINE_POINT}${CLIP}${READLINE_LINE:$READLINE_POINT}"
READLINE_POINT=$((READLINE_POINT + COUNT))
}
# https://www.gnu.org/software/bash/manual/html_node/Is-this-Shell-Interactive_003f.html
if [[ "$-" =~ "i" ]]; then
bind -m emacs -x '"\eu": _xdiscard' # kill (cut) backwards from point
bind -m emacs -x '"\ek": _xkill' # kill (cut) forwards from point
bind -m emacs -x '"\ey": _xyank'
fi
shrug(){
echo -n "¯\_(ツ)_/¯" | pbcopy
echo "¯\_(ツ)_/¯ copied to your clipboard"
}
### LS colors. http://geoff.greer.fm/lscolors/ ###
export CLICOLOR=1
export LSCOLORS="gxBxhxDxfxhxhxhxhxcxcx"
export LS_COLORS="di=36;40:ln=1;;40:so=37;40:pi=1;;40:ex=35;40:bd=37;40:cd=37;40:su=37;40:sg=37;40:tw=32;40:ow=32;40:"
# These come with `brew install git`
[ -s "/usr/local/etc/bash_completion.d/git-completion.bash" ] && . "/usr/local/etc/bash_completion.d/git-completion.bash"
[ -s "/usr/local/etc/bash_completion.d/hub.bash_completion.sh" ] && . "/usr/local/etc/bash_completion.d/hub.bash_completion.sh"
### Display current Git branch name in command prompt. ###
function parse_git_branch {
ref=$(command git symbolic-ref HEAD 2> /dev/null) || return
echo " (${ref#refs/heads/})"
}
RED="\\[\\033[0;31m\\]"
YELLOW="\\[\\033[0;33m\\]"
GREEN="\\[\\033[0;32m\\]"
NO_COLOR="\\[\\033[0m\\]"
PS1="$GREEN\\u$NO_COLOR \\W$YELLOW\$(parse_git_branch)$NO_COLOR: "
# https://github.com/direnv/direnv/wiki/Node
export NODE_VERSIONS="$NVM_DIR/versions/node"
export NODE_VERSION_PREFIX="v"
eval "$(direnv hook bash)"
# https://gist.github.com/vitalybe/021d2aecee68178f3c52
#
# Open new Terminal tabs from the command line
#
# Author: Justin Hileman (http://justinhileman.com)
#
# Installation:
# Add the following function to your `.bashrc` or `.bash_profile`,
# or save it somewhere (e.g. `~/.tab.bash`) and source it in `.bashrc`
#
# Usage:
# tab Opens the current directory in a new tab
# tab [PATH] Open PATH in a new tab
# tab [CMD] Open a new tab and execute CMD
# tab [PATH] [CMD] ... You can prob'ly guess
function iterm_newtab () {
[ "$(uname -s)" != "Darwin" ] && return # Only for Mac users
local cmd=""
local cdto="$PWD"
local args="$@"
if [ -d "$1" ]; then
cdto="$(cd "$1"; pwd)"
args="${@:2}"
fi
if [ -n "$args" ]; then
cmd="; $args"
fi
osascript &>/dev/null <<EOF
tell application "iTerm"
tell current window
set newTab to (create tab with default profile)
tell newTab
tell current session
write text "cd \"$cdto\"$cmd"
end tell
end tell
end tell
end tell
EOF
}
function iterm_current () {
[ "$(uname -s)" != "Darwin" ] && return # Only for Mac users
local cmd="$1"
osascript &>/dev/null <<EOF
tell application "iTerm2"
tell current tab of current window
tell current session
write text "$cmd"
end tell
end tell
end tell
EOF
}
function iterm_newpane () {
[ "$(uname -s)" != "Darwin" ] && return # Only for Mac users
local cmd="$1"
local direction=${2:-horizontally}
local should_focus=${3:-focus}
local select_cmd="select"
if [ "$should_focus" = "nofocus" ]; then
select_cmd=""
fi
osascript &>/dev/null <<EOF
tell application "iTerm2"
tell current tab of current window
tell current session
set newSession to (split $direction with same profile)
end tell
tell newSession
write text "$cmd"
$select_cmd
end tell
end tell
end tell
EOF
}
function iterm_newwindow () {
[ "$(uname -s)" != "Darwin" ] && return # Only for Mac users
osascript &>/dev/null <<EOF
tell application "iTerm2"
set newWindow to (create window with default profile)
tell newWindow
select
end tell
end tell
EOF
}
### Alias definitions. ###
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
if [ -f ~/.bash_aliases ]; then
. ~/.bash_aliases
fi
#alias ll='ls -lAh'
#alias la='ls -AF'
#alias l='ls -CF'
alias ll='exa -lah'
alias la='exa -aF'
alias l='exa -F'
alias gls='gls --color=auto --tabsize=0'
alias git=hub
alias gl='git log'
alias gs='git status -sb'
alias gsl='git stash list'
alias gsh='git show -U0 --oneline'
alias gap='git add -p'
alias gca='git commit --amend --no-edit'
alias gco='git checkout'
alias gcb='git checkout -b'
alias gcl='git checkout -'
alias gcm='git checkout master'
alias gpu='git push -u origin head'
alias gpun='git push -u origin head --no-verify'
# alias gd='git diff'
# alias gdc='git diff --cached'
function git-diff-fancy() { git diff --color "$@" | diff-so-fancy | less --tabs=4 -RFX; }
alias gd='git-diff-fancy'
alias gdc='git-diff-fancy --cached'
alias gb="git for-each-ref --sort=-committerdate refs/heads/ --format='%1B[0;32m%(authorname)%09%1B[0;36m(%(committerdate:relative))%09%1B[0;33m%(refname:short)%09%1B[m%(subject)' --count 20 | tail -r | column -t -s $'\t'"
alias gball="git for-each-ref --sort=-committerdate --format='%1B[0;32m%(authorname)%09%1B[0;36m(%(committerdate:relative))%09%1B[0;33m%(refname:short)%09%1B[m%(subject)' --count 20 | tail -r | column -t -s $'\t'"
alias gr='git remote --verbose'
alias bx="bundle exec"
alias bi="bundle install"
alias ah="airhorn"
alias msg="terminal-notifier -remove ALL -title Terminal -message "
alias del="trash"
alias textedit="open -a 'TextEdit'"
alias re-source="source ~/.bash_profile"
alias editbp="subl ~/.bash_profile"
alias simpleserver="python -m SimpleHTTPServer"
function ipinfo () { for ip in "${@:-}"; do curl -w \\n -s "https://ipinfo.io/$ip"; done }
function ghub() { open "https://ghub.io/$1"; }
# Setup fzf
# ---------
if [[ ! "$PATH" == */usr/local/opt/fzf/bin* ]]; then
export PATH="$PATH:/usr/local/opt/fzf/bin"
fi
# Auto-completion
# ---------------
[[ $- == *i* ]] && source "/usr/local/opt/fzf/shell/completion.bash" 2> /dev/null
# Key bindings
# ------------
source "/usr/local/opt/fzf/shell/key-bindings.bash"
# custom
# anything
complete -F _fzf_path_completion -o default -o bashdefault subl
# dir
complete -F _fzf_dir_completion -o nospace -o dirnames l
complete -F _fzf_dir_completion -o nospace -o dirnames ll
complete -F _fzf_dir_completion -o nospace -o dirnames la
@djangofan
Copy link

This segment of my .bash_profile might give you more ideas:

export PATH=".:/usr/local/bin:/usr/local:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/sw/bin:$PATH"
export PATH="$PATH:/usr/local/git/bin"
export PATH="$PATH:$HOME/.pyenv/shims" # add Python version manager
echo "Python shimmed: " + $(pyenv which python)
export PATH="$PATH:$HOME/.rbenv/bin" # add Ruby version manager
eval "$(rbenv init -)"
echo "Ruby shimmed: " + $(rbenv which ruby)
export SDKMAN_DIR="$HOME/.sdkman"
[[ -s "${SDKMAN_DIR}/bin/sdkman-init.sh" ]] && source "${SDKMAN_DIR}/bin/sdkman-init.sh"
echo "Available SDKMAN libs: " + $(ls ~/.sdkman/candidates)
echo "Available BREW libs: " + $(brew list && brew cask list)
echo "------------------"
echo ""

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment