Last active
September 20, 2017 23:54
-
-
Save ishahid/0149b444f76d3503af34 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# --------------------------------------------------------------------------- | |
# | |
# Description: This file holds all my BASH configuration and aliases | |
# | |
# Sections: | |
# 1. Environment Configuration | |
# 2. Make Terminal Better (remapping defaults and adding functionality) | |
# 3. File and Folder Management | |
# 4. Searching | |
# 5. Process Management | |
# 6. Networking | |
# 7. Custom | |
# | |
# --------------------------------------------------------------------------- | |
# ------------------------------- | |
# 1. ENVIRONMENT CONFIGURATION | |
# ------------------------------- | |
# Change Prompt | |
# ------------------------------------------------------------ | |
# export PS1="________________________________________________________________________________\n| \w @ \h (\u) \n| => " | |
# export PS2="| => " | |
export PS1="\D{%T} \W \$ " | |
# Set Paths | |
# ------------------------------------------------------------ | |
export PATH="/usr/local/bin:$PATH:/usr/local/Cellar/node/4.2.1/libexec/npm/bin" | |
# export PYTHONPATH="${PYTHONPATH}:/usr/local/lib/python2.7/site-packages" | |
# export GOPATH=$HOME/go | |
# export PATH=$PATH:$GOPATH/bin | |
# Set Default Editor (change 'Nano' to the editor of your choice) | |
# ------------------------------------------------------------ | |
export EDITOR=/usr/bin/vim | |
# Set VirtualEnvWrapper Settings | |
# ------------------------------------------------------------ | |
export WORKON_HOME=~/.virtualenvs | |
source /usr/local/bin/virtualenvwrapper.sh | |
# source $(brew --repository)/Library/Contributions/brew_bash_completion.sh | |
# Set default blocksize for ls, df, du | |
# ------------------------------------------------------------ | |
export BLOCKSIZE=4k | |
# Add color to terminal | |
# ------------------------------------------------------------ | |
export CLICOLOR=1 | |
# export LSCOLORS=ExFxBxDxCxegedabagacad | |
# ----------------------------- | |
# 2. MAKE TERMINAL BETTER | |
# ----------------------------- | |
alias cp='cp -iv' # Preferred 'cp' implementation | |
alias mv='mv -iv' # Preferred 'mv' implementation | |
alias rm='rm -v' # Preferred 'rm' implementation | |
alias mkdir='mkdir -pv' # Preferred 'mkdir' implementation | |
alias ll='ls -FGlAhp' # Preferred 'ls' implementation | |
alias less='less -FSRXc' # Preferred 'less' implementation | |
cd() { builtin cd "$@"; ll; } # Always list directory contents upon 'cd' | |
alias finder='open -a Finder ./' # finder: Opens current directory in MacOS Finder | |
alias path='echo -e ${PATH//:/\\n}' # path: Echo all executable Paths | |
mcd () { mkdir -p "$1" && cd "$1"; } # mcd: Makes new Dir and jumps inside | |
trash () { command mv "$@" ~/.Trash ; } # trash: Moves a file to the MacOS trash | |
ql () { qlmanage -p "$*" >& /dev/null; } # ql: Opens any file in MacOS Quicklook Preview | |
alias DT='tee ~/Desktop/terminalOut.txt' # DT: Pipe content to file on MacOS Desktop | |
alias genpass='pwgen --secure -c -y -n 12' # genpass: Generates a list of secure passwords | |
# lr: Full Recursive Directory Listing | |
# ------------------------------------------ | |
alias lr='ls -R | grep ":$" | sed -e '\''s/:$//'\'' -e '\''s/[^-][^\/]*\//--/g'\'' -e '\''s/^/ /'\'' -e '\''s/-/|/'\'' | less' | |
# mans: Search manpage given in agument '1' for term given in argument '2' (case insensitive) | |
# displays paginated result with colored search terms and two lines surrounding each hit. | |
# Example: mans mplayer codec | |
# -------------------------------------------------------------------- | |
mans () { | |
man $1 | grep -iC2 --color=always $2 | less | |
} | |
# showa: to remind yourself of an alias (given some part of it) | |
# ------------------------------------------------------------ | |
showa () { /usr/bin/grep --color=always -i -a1 $@ ~/Library/init/bash/aliases.bash | grep -v '^\s*$' | less -FSRXc ; } | |
# ------------------------------- | |
# 3. FILE AND FOLDER MANAGEMENT | |
# ------------------------------- | |
zipf () { zip -r "$1".zip "$1" ; } # zipf: To create a ZIP archive of a folder | |
alias numfiles='echo $(ls -1 | wc -l)' # numfiles: Count of non-hidden files in current dir | |
# --------------------------- | |
# 4. SEARCHING | |
# --------------------------- | |
alias qfind="find . -name " # qfind: Quickly search for file | |
ff () { /usr/bin/find . -name "$@" ; } # ff: Find file under the current directory | |
ffs () { /usr/bin/find . -name "$@"'*' ; } # ffs: Find file whose name starts with a given string | |
ffe () { /usr/bin/find . -name '*'"$@" ; } # ffe: Find file whose name ends with a given string | |
# spotlight: Search for a file using MacOS Spotlight's metadata | |
# ----------------------------------------------------------- | |
spotlight () { mdfind "kMDItemDisplayName == '$@'wc"; } | |
# --------------------------- | |
# 5. PROCESS MANAGEMENT | |
# --------------------------- | |
# findpid: find out the pid of a specified process | |
# ----------------------------------------------------- | |
# Note that the command name can be specified via a regex | |
# E.g. findPid '/d$/' finds pids of all processes with names ending in 'd' | |
# Without the 'sudo' it will only find processes of the current user | |
# ----------------------------------------------------- | |
findpid () { lsof -t -c "$@" ; } | |
# memhogstop, memhogsps: Find memory hogs | |
# ----------------------------------------------------- | |
alias memhogstop='top -l 1 -o rsize | head -20' | |
alias memhogsps='ps wwaxm -o pid,stat,vsize,rss,time,comm | head -10' | |
# cpuhogs: Find CPU hogs | |
# ----------------------------------------------------- | |
alias cpuhogs='ps wwaxr -o pid,stat,%cpu,time,comm | head -10' | |
# ttop: Recommended 'top' invocation to minimize resources | |
# ------------------------------------------------------------ | |
alias ttop="top -R -F -s 10 -o rsize" | |
# myps: List processes owned by my user: | |
# ------------------------------------------------------------ | |
myps() { ps $@ -u $USER -o pid,%cpu,%mem,start,time,bsdtime,command ; } | |
# --------------------------- | |
# 6. NETWORKING | |
# --------------------------- | |
alias myip='curl canhazip.com && echo ""' # myip: Public facing IP Address | |
alias netcons='lsof -i' # netcons: Show all open TCP/IP sockets | |
alias flushdns='sudo killall -HUP mDNSResponder' # flushdns: Flush out the DNS Cache | |
alias lsock='sudo /usr/sbin/lsof -i -P' # lsock: Display open sockets | |
alias lsocku='sudo /usr/sbin/lsof -nP | grep UDP' # lsocku: Display only open UDP sockets | |
alias lsockt='sudo /usr/sbin/lsof -nP | grep TCP' # lsockt: Display only open TCP sockets | |
alias ipinfo0='ipconfig getpacket en0' # ipinfo0: Get info on connections for en0 | |
alias ipinfo1='ipconfig getpacket en1' # ipinfo1: Get info on connections for en1 | |
alias openports='sudo lsof -i | grep LISTEN' # openports: All listening connections | |
alias showblocked='sudo ipfw list' # showblocked: All ipfw rules inc/ blocked IPs | |
# ii: display useful host related informaton | |
# ------------------------------------------------------------------- | |
ii() { | |
echo -e "\nYou are logged on ${RED}$HOST" | |
echo -e "\nAdditionnal information:$NC " ; uname -a | |
echo -e "\n${RED}Users logged on:$NC " ; w -h | |
echo -e "\n${RED}Current date :$NC " ; date | |
echo -e "\n${RED}Machine stats :$NC " ; uptime | |
echo -e "\n${RED}Current network location :$NC " ; scselect | |
echo -e "\n${RED}Public facing IP Address :$NC " ;myip | |
# echo -e "\n${RED}DNS Configuration:$NC " ; scutil --dns | |
echo | |
} | |
# ----------------------------- | |
# 7. CUSTOM | |
# ----------------------------- | |
# zappa exports and aliases setup | |
# -------------------------------- | |
export AWS_PROFILE="default" | |
export TRAVIS_DECRYPT_KEY="TRAVIS_DECRYPT_KEY" | |
export TRAVIS_DECRYPT_KEY_PROD="TRAVIS_DECRYPT_KEY" | |
export AWS_ACCESS_KEY_ID="AWS_ACCESS_KEY_ID" | |
export AWS_SECRET_ACCESS_KEY="AWS_SECRET_ACCESS_KEY" | |
alias zappa_shell='docker run -ti -e AWS_PROFILE=$AWS_PROFILE -v $(pwd):/var/task -v ~/.aws/:/root/.aws --rm zappa:0.40' | |
zappa_encrypt () { openssl aes-256-cbc -k $TRAVIS_DECRYPT_KEY -in zappa_settings.json -out zappa_settings.json.enc; } | |
zappa_encrypt_prod () { openssl aes-256-cbc -k $TRAVIS_DECRYPT_KEY_PROD -in zappa_settings_prod.json -out zappa_settings_prod.json.enc; } | |
zappa_decrypt () { openssl aes-256-cbc -k $TRAVIS_DECRYPT_KEY -in zappa_settings.json.enc -out zappa_settings.json -d; } | |
zappa_decrypt_prod () { openssl aes-256-cbc -k $TRAVIS_DECRYPT_KEY_PROD -in zappa_settings_prod.json.enc -out zappa_settings_prod.json -d; } | |
zappa_deploy () { | |
docker build --build-arg environment="$1" --build-arg AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID --build-arg AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY --build-arg AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION -f Dockerfile.deploy -t deploy . | |
} | |
# awless bash autocomplete setup | |
# -------------------------------- | |
[ -f /usr/local/etc/bash_completion ] && . /usr/local/etc/bash_completion | |
# thefuck setup | |
eval "$(thefuck --alias)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment