Last active
April 18, 2021 05:02
-
-
Save anmolgarg/9eccfe9ff975e22149fe to your computer and use it in GitHub Desktop.
This file contains 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 configurations and aliases | |
# | |
# Sections: | |
# 1. Environment Configuration | |
# 2. Make Terminal Better | |
# 3. File and Folder Management | |
# 4. Searching | |
# 5. Networking and System Information | |
# 6. Data Analytics | |
# 1. ENVIRONMENT CONFIGURATION | |
# Configure custom prompt | |
configure_my_prompt () | |
{ | |
local __cur_locn_c="\[\033[01;34m\]"; | |
local __cur_locn="\w"; | |
local __git_branch_c="\[\033[35m\]"; | |
local __git_branch='`git branch 2> /dev/null | grep -e ^* | sed -E s/^\\\\\*\ \(.+\)$/\(\\\\\1\)\ /`'; | |
local __prompt_tail_c="\[\033[36m\]"; | |
local __prompt_tail="⚙"; # or any other cool unicode symbol i.e. ><(((º> | |
local __input_c="\[\033[00m\]"; | |
export PS1="$__cur_locn_c$__cur_locn $__git_branch_c$__git_branch$__prompt_tail_c$__prompt_tail$__input_c " | |
} | |
configure_my_prompt | |
# Show wd in tab | |
export PROMPT_COMMAND='echo -ne "\033]0;${PWD##*/}\007"' | |
# Source bashrc for paths, pointers, hidden info | |
if [ -f ~/.bashrc ]; | |
then source ~/.bashrc | |
fi | |
# -------------------------------------------------------------------- | |
# -------------------------------------------------------------------- | |
# 2. MAKE TERMINAL BETTER | |
# Remap defaults, add new ones | |
alias cd..='cd ../' # Go back 1 directory level (because typo) | |
alias ..='cd ../' # Go back 1 directory level | |
alias ...='cd ../../' # Go back 2 directory levels | |
alias .3='cd ../../../' # Go back 3 directory levels | |
alias c='clear' # c: Clear terminal display | |
alias cp='cp -iv' # Preferred 'cp' implementation | |
alias df='df -Ph' # Preferred 'df' implementation | |
function edit () { # edit: Open dir or file in Sublime Text. If no file given, open wd | |
if [ $# -eq 0 ]; then sublime .; | |
else sublime "$@"; | |
fi; | |
} | |
function f () { # f: Open file in MacOS Finder. If no file given, open wd | |
if [ $# -eq 0 ]; then open -a Finder .; | |
else open -a Finder "$@"; | |
fi; | |
} | |
function g () { # g: Open file in Google Chrome. If no file given, open wd | |
if [ $# -eq 0 ]; then open -a Google\ Chrome .; | |
else open -a Google\ Chrome "$@"; | |
fi; | |
} | |
jcurl () { command curl "$@" | python -m json.tool; } # jcurl: Curls and pipes to json | |
alias less='less -FSRXc' # Preferred 'less' implementation | |
alias ls='ls -G' # Preferred 'ls' implementation | |
alias ll='ls -FGlAhp' # Advanced 'ls' implementation | |
alias lsd='ll | grep "^d"' # Advanced 'ls' implementation, only dirs | |
alias mkdir='mkdir -pv' # Preferred 'mkdir' implementation | |
alias mv='mv -iv' # Preferred 'mv' implementation | |
alias gc='git commit' # do git things quicker | |
alias gco='git checkout' | |
alias gd='git diff' | |
alias gpull='git pull' | |
alias gpush='git push' | |
alias gs='git status' | |
trash () { command mv "$@" ~/.Trash; } # trash: Move a file to the MacOS trash | |
ql () { qlmanage -p "$*" >& /dev/null; } # ql: Open any file in MacOS Quicklook Preview | |
alias cic='set completion-ignore-case On' # cic: Make tab-completion case-insensitive | |
alias cleanupDS='find . -type f -name '\''*.DS_Store'\'' -ls -delete' # cleanupDS: Delete all .DS_store files | |
alias fixstty='stty sane' # fixstty: Restore terminal settings when screwed up | |
alias killdock='killall Dock' # killdock: Restart MacOS dock | |
alias path='echo -e ${PATH//:/\\n}' # path: Echo all executable Paths | |
alias showoptions='shopt' # showoptions: Display bash options settings | |
# -------------------------------------------------------------------- | |
# -------------------------------------------------------------------- | |
# 3. FILE AND FOLDER MANAGEMENT | |
# zipf: Create a ZIP archive of a folder | |
zipf () { zip -r "$1".zip "$1" ; } | |
# extract: Extract most known archives | |
extract () { | |
if [ -f $1 ] ; then | |
case $1 in | |
*.tar.bz2) tar xjf $1 ;; | |
*.tar.gz) tar xzf $1 ;; | |
*.bz2) bunzip2 $1 ;; | |
*.rar) unrar e $1 ;; | |
*.gz) gunzip $1 ;; | |
*.tar) tar xf $1 ;; | |
*.tbz2) tar xjf $1 ;; | |
*.tgz) tar xzf $1 ;; | |
*.zip) unzip $1 ;; | |
*.Z) uncompress $1 ;; | |
*.7z) 7z x $1 ;; | |
*) echo "'$1' cannot be extracted via extract()" ;; | |
esac | |
else | |
echo "'$1' is not a valid file" | |
fi | |
} | |
# hide/showfiles: Show and Hide hidden files in Finder, restart Finder | |
alias hidefiles='defaults write com.apple.finder AppleShowAllFiles NO; killall Finder /System/Library/CoreServices/Finder.app' | |
alias showfiles='defaults write com.apple.finder AppleShowAllFiles YES; killall Finder /System/Library/CoreServices/Finder.app' | |
# -------------------------------------------------------------------- | |
# -------------------------------------------------------------------- | |
# 4. SEARCHING | |
# Create expanded search functions using find | |
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" | head -10; } | |
# -------------------------------------------------------------------- | |
# -------------------------------------------------------------------- | |
# 5. NETWORKING AND SYSTEM INFORMATION | |
alias myip='curl -s --max-time 1 ipecho.net/plain' | |
alias macstats='top -l 1 -s 0 | grep "PhysMem"; top -l 1 -s 0 | grep "CPU usage"' | |
# ii: Display useful host related informaton | |
ii() { | |
echo -ne "You are logged on$NC "; scutil --get ComputerName | |
echo -ne "The current datetime is$NC " ; date | |
echo -e "\nMachine stats:$NC " ; uptime; macstats | |
echo -e "\nDisk usage:$NC "; df -l | |
echo -ne "\nPublic facing IP address:$NC "; myip | |
echo | |
} | |
# weather: Curls weather forecast for San Francisco, CA | |
alias weather='curl -s http://wttr.in/sf | head -n 37' | |
# editbash: Open bash_profile in editor | |
alias editbash='edit ~/.bash_profile' | |
# backupbash: Back up bash_profile and bashrc | |
backupbash() { | |
cp -f ~/.bash_profile ~/.bash_profile_backup | |
cp -f ~/.bashrc ~/.bashrc_backup | |
} | |
# updatebash: Update bash_profile with latest version from anmolgarg gist | |
updatebash() { | |
backupbash | |
curl -k https://gist.githubusercontent.com/anmolgarg/9eccfe9ff975e22149fe/raw/.bash_profile -o ~/.bash_profile | |
source ~/.bash_profile | |
} | |
# cpu/memhogs: Display top CPU and memory users | |
alias cpuhogs='ps wwaxr -o pid,stat,%cpu,time,command | head -10' | |
alias memhogs='ps wwaxm -o pid,stat,vsize,rss,time,command | head -10' | |
# z: Initialize z (see https://github.com/rupa/z) | |
. ~/z.sh | |
# -------------------------------------------------------------------- | |
# -------------------------------------------------------------------- | |
# 6. DATA ANALYTICS | |
# Jupyter/IPython useful commands | |
alias jp='jupyter lab ./' # jp: Open current directory in Jupyter Notebook | |
alias jptoh='ipython nbconvert --to html' # jptoh: Convert given .ipynb to html | |
alias jptos='ipython nbconvert --to script' # jptos: Convert given .ipynb to executable python script | |
# makeproj: Run make_project_dir.py script from anmolgarg gist | |
# alias makeproj='python -c "$(curl -fsSL https://gist.githubusercontent.com/anmolgarg/ef483a22babb353367a9/raw/make_project_dir.py)"' | |
# getjpstartfile: Pull ipython startup file from anmolgarg gist | |
# alias getjpstartfile='curl -L https://gist.githubusercontent.com/anmolgarg/b92ae9985efc6543f0cc/raw/00-startup.ipy > ~/.ipython/profile_default/startup/00-pd_plt_magic.ipy' | |
# -------------------------------------------------------------------- | |
# -------------------------------------------------------------------- | |
# Run ii on source | |
ii |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment