Skip to content

Instantly share code, notes, and snippets.

@benwiz
Last active October 2, 2019 02:00
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 benwiz/69270080eeeec2214e74369c32aaed7a to your computer and use it in GitHub Desktop.
Save benwiz/69270080eeeec2214e74369c32aaed7a to your computer and use it in GitHub Desktop.
# ~/.bash_alias is a convention of my own design. All aliases (and functions?) should be placed in here.
# Then this file is sourced in ~/.bashrc.
# my local ip address
alias myip="ipconfig getifaddr en0"
# python & pip
alias pip=pip3
alias python=python3
# docker
alias drmui='docker rmi $(docker images | grep "^<none>" | awk "{print $3}")' # remove untagged images
alias dpg="cd $HOME/github/personal/util/docker/postgres && docker-compose up" # start postgres container
alias pycon='docker run --rm -v $(pwd .):/opt -w /opt --name python-shell -it python:3.7 bash' # start python container in bash shell
# virtualenv
alias venv="source venv/bin/activate && if [ -f .local.env ]; then source .local.env; fi"
alias mkvenv="virtualenv venv && venv && if [ -f requirements.txt ]; then pip install -r requirements.txt; fi"
# generate uuid and copy to clipboard
alias uuid="uuidgen | tr -d '\n' | tr '[:upper:]' '[:lower:]' | pbcopy && pbpaste && echo"
# Generate the `eb setenv` command using a local .env file
ebsetenv() {
if [ -z "$1" ]
then
echo "Please give the filename as the only input."
echo "Exiting script..."
return 1
fi
FILENAME="$1"
echo $FILENAME
# Craft command
CMD="eb setenv"
for line in $(cat $FILENAME)
do
CMD="$CMD $line"
done
# Remove `export ` from everywhere
CMD=${CMD//export /}
if [ "$2" ]
then
CMD="$CMD -e $2"
fi
# Confirm command
echo $CMD
echo
echo -n "Does the above command look good (y/n)? "
read answer
if echo "$answer" | grep -iq "^y"
then
echo "Executing..."
# Evaluate command
eval $CMD
else
echo "Canceling..."
fi
}
# Create editorconfig file
editorconfig() {
echo """\
root = true
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 4
[{*.{json,yml,md,js,html,clj,cljs,css,scss,ts,glsl,vert,frag},Gemfile}]
indent_size = 2
[*.go]
indent_style = tab
""" > .editorconfig
}
# Create .eslintrc.json file
eslintrc() {
echo '''{
"extends": "airbnb-base",
"env": {
"browser": true,
"node": false
},
"rules": {
"max-len": [1, 100, 2, { "ignoreComments": true }],
"no-console": 0,
"no-unused-vars": ["error", { "argsIgnorePattern": "^_" }],
"no-param-reassign": ["error", { "props": false }],
"radix": ["error", "as-needed"],
"no-new": "off",
"no-mixed-operators": "off",
"no-return-assign": "off",
"no-magic-numbers": "off",
"import/prefer-default-export": false,
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }],
"no-continue": "off",
"object-shorthand": ["error", "consistent-as-needed"]
}
}
''' > .eslintrc.json
}
eslintrc-react() {
echo '''{
"extends": "react-app",
"env": {
"browser": true,
"node": false
},
"rules": {
"quotes": ["error", "single"],
"comma-dangle": ["error", "always-multiline"],
"object-shorthand": ["error", "always"]
}
}
''' > .eslintrc.json
}
# Override tree command to exclude `venv`
alias tree="tree -I 'venv|__pycache__'"
# Weather
alias weather="curl -4 http://wttr.in"
# Emscripten
alias emsdk_env="source $HOME/code/vendor/emsdk/emsdk_env.sh"
# ~/.bash_profile is supposed to be loaded on login shells, not a normal shell session.
# However, Terminal.app calls it when it loads. For simplicity, place everything inside
# the ~/.bashrc file and source it here.
if [ -f $HOME/.bashrc ]; then source $HOME/.bashrc; fi
##
# Your previous /Users/benwiz/.bash_profile file was backed up as /Users/benwiz/.bash_profile.macports-saved_2019-03-17_at_15:23:38
##
# MacPorts Installer addition on 2019-03-17_at_15:23:38: adding an appropriate PATH variable for use with MacPorts.
export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
# Finished adapting your PATH environment variable for use with MacPorts.
export PATH="$HOME/.cargo/bin:$PATH"
# ~/.bashrc is loaded on a new session.
# Shell colors
export CLICOLOR=1
export LSCOLORS=ExGxBxDxCxEgEdxbxgxcxd
# PS1='\[\e[0;33m\]\u\[\e[0;32m\]:\[\e[0;33m\]\W\[\e[0;32m\]:\[\e[0;33m\]$\[\e[m\]$ '
PS1='\[\e[0;33m\]\u\[\e[0;32m\]:\[\e[0;33m\]\W\n\[\e[0;33m\]$\[\e[m\] '
# Set tab name in iTerm2
if [ "$TERM_PROGRAM" == "iTerm.app" ]
then
export PROMPT_COMMAND='echo -ne "\033];${PWD##*/}\007"; ':"$PROMPT_COMMAND";
fi
# source aliases
if [ -f "$HOME/.bash_alias" ]; then source $HOME/.bash_alias; fi
# TOOD: Once asdf if working for node, remove this commented out nvm block
# Initialize NVM
#export NVM_DIR=~/.nvm
#source /usr/local/opt/nvm/nvm.sh # $(brew --prefix nvm) runs too slowly
# ASDF
source $HOME/.asdf/asdf.sh
source $HOME/.asdf/completions/asdf.bash
# Initialize RBENV
eval "$(rbenv init -)"
# Select Java 8
# I needed to use Java 8 for `wwoz_to_spotify` because of lein and Clojure.
# I'm not sure if this is a lein/Clojure thing or specific to that project.
# Hopefully I can leave this commented out and just run it in the shell when
# working on that project specifically. I'll keep it here for reference.
# export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
# Path config
export PATH=$PATH:. # Should this be added to the front of path? Can't decide.
export PATH=$PATH:$GOPATH/bin
###-begin-npm-completion-###
#
# npm command completion script
#
# Installation: npm completion >> ~/.bashrc (or ~/.zshrc)
# Or, maybe: npm completion > /usr/local/etc/bash_completion.d/npm
#
if type complete &>/dev/null; then
_npm_completion () {
local words cword
if type _get_comp_words_by_ref &>/dev/null; then
_get_comp_words_by_ref -n = -n @ -n : -w words -i cword
else
cword="$COMP_CWORD"
words=("${COMP_WORDS[@]}")
fi
local si="$IFS"
IFS=$'\n' COMPREPLY=($(COMP_CWORD="$cword" \
COMP_LINE="$COMP_LINE" \
COMP_POINT="$COMP_POINT" \
npm completion -- "${words[@]}" \
2>/dev/null)) || return $?
IFS="$si"
if type __ltrim_colon_completions &>/dev/null; then
__ltrim_colon_completions "${words[cword]}"
fi
}
complete -o default -F _npm_completion npm
elif type compdef &>/dev/null; then
_npm_completion() {
local si=$IFS
compadd -- $(COMP_CWORD=$((CURRENT-1)) \
COMP_LINE=$BUFFER \
COMP_POINT=0 \
npm completion -- "${words[@]}" \
2>/dev/null)
IFS=$si
}
compdef _npm_completion npm
elif type compctl &>/dev/null; then
_npm_completion () {
local cword line point words si
read -Ac words
read -cn cword
let cword-=1
read -l line
read -ln point
si="$IFS"
IFS=$'\n' reply=($(COMP_CWORD="$cword" \
COMP_LINE="$line" \
COMP_POINT="$point" \
npm completion -- "${words[@]}" \
2>/dev/null)) || return $?
IFS="$si"
}
compctl -K _npm_completion npm
fi
###-end-npm-completion-###
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment