Last active
September 15, 2022 21:50
-
-
Save LuisEnMarroquin/84da950fb32d5a3c248975af450e1be0 to your computer and use it in GitHub Desktop.
My bash aliases and functions
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
#!/bin/bash | |
CL_NULL='\e[0m' | |
CL_FAIL='\e[0;31m' | |
CL_NICE='\e[0;32m' | |
CL_WARN='\e[0;33m' | |
CL_BLUE='\e[0;34m' | |
CL_PURP='\e[0;35m' | |
CL_CYAN='\e[0;36m' | |
# Determine OS | |
isMAC=false | |
isLINUX=false | |
isWINDOWS=false | |
if [[ "$(uname)" == "Darwin" ]]; then isMAC=true; | |
elif [[ "$(expr substr $(uname -s) 1 5)" == "Linux" ]]; then isLINUX=true; | |
else isWINDOWS=true; fi | |
function getOS { echo "---" MAC $isMAC "---" LINUX $isLINUX "---" WINDOWS $isWINDOWS "---" ; } | |
# PS1 - https://phoenixnap.com/kb/change-bash-prompt-linux | |
if [[ $isMAC ]]; then PROMPT='%F{green}%1~%f ☭ '; else | |
nowBr=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo '' 2>/dev/null) | |
setPS1 () { local shBr=''; if [ ! -z $nowBr ]; then shBr="${CL_CYAN}(${nowBr})${CL_NULL}"; fi; PS1="\[\033]0;☭ ${PWD}\007\]"; export PS1="${PS1}\n${CL_NICE}☭${CL_NULL} ${CL_WARN}\w${CL_NULL} ${CL_PURP}\t${CL_NULL} ${shBr}\n$ "; } | |
PROMPT_COMMAND=setPS1 | |
fi | |
# Git | |
alias gbr='git branch' | |
alias ggo='git remote get-url origin' # Git get origin | |
alias gl1='git log --pretty=format:"%h - %an, %ar : %s"' # Git log with formatting | |
alias gl2='git log --oneline --decorate' # Git log with formatting | |
alias gpl='git fetch --all && git pull --all' | |
alias gps='git push' | |
alias gst='git status' | |
alias gut='git rm -r --cached . -f' # Untrack all files | |
alias gpsa='git push --all' | |
alias count='ls | wc -l' # Counts files in current directory | |
function ga { git add ${*:-.}; } # By default adds all | |
function gc { if [[ $# -eq 0 ]]; then git commit; else git commit -m "$*"; fi; } | |
function gac { if [[ $# -eq 0 ]]; then git add . && git commit; else git add . && git commit -m "$*"; fi; } # Git add commit | |
function gao { git remote add origin $1; } # Git add origin | |
function gck { git checkout $1; } # Change branch | |
function gdb { git branch -d $1 && git push --delete origin $1; } # Delete local and remote branch | |
function gso { git remote set-url origin $1; } # Git set origin | |
function gacp { if [[ $# -eq 0 ]]; then git add . && git commit && git push; else git add . && git commit -m "$*" && git push; fi; } # Git add commit push | |
function gckb { git checkout -b $1; } # Create new branch | |
function gcko { git checkout --orphan $1; } # Create new orphan branch | |
function gcon { git config --global user.name "$1" && git config --global user.email "$2"; } # Sets git basic configuration | |
function gpso { git push --set-upstream origin $1; } | |
function gsta { for dir in */.git/ ; do printf "\n${CL_CYAN}* $dir${CL_NULL}\n"; (cd $dir && cd .. && git status); done; } | |
function gpla { for dir in */.git/ ; do printf "\n${CL_CYAN}* $dir${CL_NULL}\n"; (cd $dir && cd .. && git pull); done; } | |
# More | |
alias c='clear' # Clean console | |
alias e='exit 0' # Exit with status 0 (no error) | |
alias p='pwd' # Show path | |
alias ch='cd ~' # Go to home folder | |
alias la='ls -a' # Show all files | |
alias ng='npm list -g --depth 0' # List global npm deps | |
alias nu='npm update -g' # Update global npm deps | |
alias rs='if test -f ~/.bash_profile; then source ~/.bash_profile; fi; if test -f ~/.bashrc; then source ~/.bashrc; fi; if test -f ~/.zshrc; then source ~/.zshrc; fi;' # Reload this file | |
alias ydl='youtube-dl' | |
alias sup='if [[ $isMAC ]]; then brew update && brew upgrade && brew autoremove; elif [[ $isLINUX ]]; then sudo apt update && sudo apt upgrade -y && sudo apt autoremove -y; else start powershell.exe -noexit -command "scoop update; scoop update *; exit" && exit; fi;' | |
function cu { for (( c=1; c<=${1-1}; c++ )); do cd ..; done; } | |
function dc { cd /d/$(whoami); } | |
function nr { npm run ${*}; } | |
function random { LC_CTYPE=C && tr -dc A-Za-z0-9 </dev/urandom | head -c ${1-8} ; echo ''; } | |
function mongoDocker { docker stop mongo && docker rm mongo; docker volume create mongo; docker volume create mongoc; docker run -d --name mongo -p 27017:27017 -v mongo:/data/db -v mongoc:/data/configdb mongo:4.4; } | |
# function random { tr -dc A-Za-z0-9 </dev/urandom | head -c ${1-8} ; echo ''; } # This is windows version that doesnt work on mac | |
export NVM_DIR="$HOME/.nvm" | |
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm | |
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion | |
#THIS MUST BE AT THE END OF THE FILE FOR SDKMAN TO WORK!!! | |
export SDKMAN_DIR="$HOME/.sdkman" | |
[[ -s "$HOME/.sdkman/bin/sdkman-init.sh" ]] && source "$HOME/.sdkman/bin/sdkman-init.sh" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment