Skip to content

Instantly share code, notes, and snippets.

@benwiz benwiz/bash_alias
Last active Mar 24, 2019

Embed
What would you like to do?
# ~/.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"
# pip
alias pip=pip3
# 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},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": ["error", { "ignoreArrayIndexes": true, "ignore": [0, 0.25, 0.5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 24, 45, 90, 100, 255, 256, 360, 1000] }],
"import/prefer-default-export": false,
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }],
"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.
# ~/.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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.