Skip to content

Instantly share code, notes, and snippets.

@brayhoward
Created March 16, 2021 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brayhoward/f15922744607bca79df03172450dee17 to your computer and use it in GitHub Desktop.
Save brayhoward/f15922744607bca79df03172450dee17 to your computer and use it in GitHub Desktop.
# LINKED
txtblk='[\e[0;30m]' # Black
txtred='\[\e[0;31m\]' # Red
txtgrn='\[\e[0;32m\]' # Green
txtylw='\[\e[0;33m\]' # Yellow
txtblu='\[\e[0;34m\]' # Blue
txtpur='\[\e[0;35m\]' # Purple
txtcyn='\[\e[0;36m\]' # Cyan
txtwht='\[\e[0;37m\]' # White
txtrst='\[\e[0m\]' # Text Reset
export EDITOR=vim
export SHELL=/bin/bash
export CLICOLOR=1
export LSCOLORS=GxFxCxDxBxegedabagaced
export NODE_HOME=/usr/local/node/bin
PATH=$HOME/bin:./node_modules/.bin:$PATH
export PATH="/usr/local/sbin:$PATH"
############## Path Shortcuts ###################################################
#################################################################################
set_code_aliases() {
local code maind
code="~/Desktop/code"
alias co="cd $code"
}
set_code_aliases
alias dt='cd ~/Desktop'
##################################################################################
############ brew ################################################################
##################################################################################
# list local versions <package>
alias blv='brew list --versions'
# brew list availible <packages>
alias bs='brew search'
# brew switch
# ex: bs <package> <version>
# defaults to latest version if version not specified
# ex: bs <package>
bswitch() {
local versions latest version_specified
versions=$(blv $1 | sed 's/ /, /g')
latest=$(echo $versions | awk '{print $NF}')
version_specified=${2:-$latest}
echo "local versions availible: $versions"
echo -e "\nswitching to $1@$version_specified"
brew switch $1 $version_specified
}
##################################################################################
######## Terminal Commands ##
############################
alias h='cd ~'
alias pd='cd -'
alias lsa='ls -a'
alias ll='ls -lahp'
alias b='cd ..'
alias c='clear'
alias t='touch'
alias rmr='rm -rf'
alias cp='cp -r'
# touch and open
tao () {
touch $1;
open $1;
}
alias m='mkdir'
alias md="mkdir -p"
# make directory and move into it
mkcd () {
md $1
cd $1
}
# list directories
alias lsd="ls -d */"
# list files
alias lsf="find . -maxdepth 1 -type f"
alias ls="ls -p"
#---------------------------
#------>|Secure Remove File|
alias srm='rm -Pv'
#------>|Secure Remove Dir|
alias srmd='rm -Pvrf'
#---------------------------
############################
############# All Things Git ###################################
################################################################
alias stash='git stash -u'
alias pop='git stash pop'
alias pull='git pull'
alias push='git push'
pushf() {
git push $@ --force
}
alias fetch='git fetch'
alias grh='git reset HEAD'
alias gco='git checkout'
# previous branch
alias pb='git checkout -'
alias gcd='git checkout develop && pulld'
alias gcb='git checkout -b'
alias grab='git rebase --abort'
alias gma='git merge --abort'
# git rebase head interactive
gri() {
git rebase -i HEAD~${1:-2}
}
# git merge with color
gm() {
git merge $1 | egrep --color 'CONFLICT .*|$';
}
# git rebase with color
grb() {
git rebase $1 | egrep --color 'CONFLICT .*|$';
}
grc() {
git rebase --continue | egrep --color 'CONFLICT .*|$';
}
# git reset
# ex: gr 2
gr() {
local id
id=$(git rev-parse HEAD)
echo "old head commit: $id"
git reset HEAD~${1:-'1'} ${2:-"--soft"}
}
# git checkout head~<level>
# ex: gch 3
gch() {
level="~${1:-1}"
echo $level
git checkout HEAD$level
}
alias reset='git reset HEAD~1'
alias gd='git diff'
alias gds='gd --staged'
## git diff head - view diff for last commit
alias gdh='git diff HEAD^'
# git diff commmit - git diff COMMIT^ COMMIT
gdc() {
git diff "$1^" $1
}
alias gl='git log'
alias gs='git status'
alias gap='git add -p'
alias ga='git add'
alias gra='git remote add'
alias cl='git clone'
alias gca='git commit -m "added new alias" && push'
# git commit settings
alias gcs='git commit -m "Changed some settings" && push'
alias gb='git branch'
alias grv='git remote -v'
alias amend='git commit --amend'
############# delete branch
alias db='git branch -D'
# git prune local branches. (all branches that have been merged into master or develop)
alias gpl='git branch --merged | egrep -v "(^\*|master|develop)" | xargs git branch -d'
# git delete all local branches except master
alias gdlb='git branch | grep -v "master" | xargs git branch -D'
alias gitclean='git clean -xdf'
## get file info. <gitinfo path/to/file.txt>
alias gitinfo='git log --diff-filter=A --'
## recover deleted file or directory. add path to file at end.
## example: rdf -- ./postcss.config.js
alias rdf='git checkout HEAD^ --'
gc() {
git commit -m "'$*'";
}
##################################################################
########### Node ##################################
###################################################
alias n='npm'
alias ni='npm install'
alias nu='npm-check-updates -u'
alias nr='npm run'
alias nrs='npm run start'
alias nrb='npm run build'
alias nrd='npm run deploy'
alias nrsma='npm run startMockedApp'
alias nrt='npm run test'
alias nret='npm run e2eTests'
alias nretd='npm run e2eTestsDebug'
alias nretw='npm run e2eTestsWatch'
alias nrutd='npm run unitTestsDebug'
alias nrut='npm run unitTests'
alias yad="yarn add --dev"
alias ya="yarn add"
alias y="yarn"
alias ys="yarn start"
# npm veiw versions
nvv() {
npm v $1 versions --json
}
# npm view latest
# nvla some_npm_package
nvla() {
echo $(npm v $1 dist-tags.latest)
}
# npm view local
# nvlo some_npm_package
nvlo() {
local latest_version local_version
latest_version=$(nvla $1)
local_version=$(npm ls $1 --depth 0 | grep "$1"@ | awk '{print $NF}')
wait
echo "Local version: ${local_version:-"nooop"} | Latest version: $latest_version"
}
alias cts="tsc --noEmit"
# show global installed npm packages
alias npmg='npm list -g --depth=0'
## node_modules/.bin shortcuts
alias eslint='node_modules/.bin/eslint'
# check and use .nvmrc on every directory change
enter_directory() {
if [[ $PWD == $PREV_PWD ]]; then
return
fi
PREV_PWD=$PWD
[[ -f ".nvmrc" ]] && nvm use && echo "nvm using $(cat .nvmrc)"
}
function chpwd {
enter_directory
}
# old bash syntax to exicute a thing when entering a new dir. no work in zsh
# export PROMPT_COMMAND=enter_directory
####################################################
############### Android #####################
#---- open android-sdk
# android
alias devices="adb devices"
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
#############################################
############## Shortcuts ########################################################
#################################################################################
alias finder='open -a Finder'
alias prev='open -a Preview'
alias catb='cat ~/.bash_profile'
alias ebp='code ~/.bash_profile'
## fix conflicts - open all files with merge conflicts
alias fc='git diff --name-only | uniq | xargs code'
alias sb='source ~/.bash_profile'
alias pserver='python -m SimpleHTTPServer'
# grep bash profile with 1 line of context above and bellow any results
gbp() {
catb | grep -C 1 "$1"
}
######################### Utils ###############################
###############################################################
alias brewu='brew update && brew cleanup && brew prune && brew doctor'
# grep package json
gpj() {
cat package.json | grep $1
}
hist() {
history ${1:-15}
}
# cd back x times or defualts to one
# ex: .. 4
..() {
cd $(seq -f '..' -s '/' ${1:-1});
}
# take you to root dir of git repo
root() {
local local_git_repo
local_git_repo=$(git rev-parse --show-toplevel)
local_git_repo=${local_git_repo:-.}
cd "$local_git_repo"
}
# generate password
gp() {
openssl rand -base64 ${1:-10}
}
# defaults to killing whatever process in running on port 3000 (rails)
search_and_destroy() {
kill -9 $(lsof -i :"${1:-3000}" -t)
}
###############################################################
#################################################################################
############################# Erlang 17 #########################################
# erlang@17-17.5.6.9.sierra.bottle.tar.gz
# This formula is keg-only, which means it was not symlinked into /usr/local,
# because this is an alternate version of another formula.
# If you need to have this software first in your PATH run:
# echo 'export PATH="/usr/local/opt/erlang@17/bin:$PATH"' >> ~/.bash_profile
# For compilers to find this software you may need to set:
# LDFLAGS: -L/usr/local/opt/erlang@17/lib
# test -e "${HOME}/.iterm2_shell_integration.bash" && source "${HOME}/.iterm2_shell_integration.bash"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment