Skip to content

Instantly share code, notes, and snippets.

@sudogem
Last active February 27, 2024 16:07
Show Gist options
  • Save sudogem/ac3667637ebc3b7c907d76b5f46f5209 to your computer and use it in GitHub Desktop.
Save sudogem/ac3667637ebc3b7c907d76b5f46f5209 to your computer and use it in GitHub Desktop.
Create a .bashrc file(if not exist) using the command: $ vi ~/.bashrc then update it. Once updated we run this command: $ source ~/.bashrc
## Add git branch name in Terminal
force_color_prompt=yes
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
## export PS1="\u@\h \[\033[32m\]\w\[\033[33m\]\$(parse_git_branch)\[\033[00m\] >\n$ "
export PS1="${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\[\033[33m\]\$(parse_git_branch)\[\033[00m\] >\n$ "
## Git shortcuts
alias gitlogtree="git log -n 10 --graph --decorate -30 --all --date-order --date=format:'%Y-%m-%d %H:%M:%S' --pretty=format:'%C(cyan)%h%Creset %C(black bold)%ad%Creset%C(auto)%d %s'"
alias gitlog="git log -n 10 --pretty=format:'%Cgreen%h%Creset%x09%C(cyan)%an%Creset%x09%C(black bold)%ad%Creset%x09%s'"
alias gl='gitlog'
## Git commands
alias c='git cola'
alias gs='git status'
alias gf='git fetch && git pull --rebase'
alias o='git remote show origin'
## gitlog n - can accept arguments
function gitlog() {
arg1=${1:-10}
git log -n $arg1 --pretty=format:'%Cgreen%h%Creset%x09%C(cyan)%an%Creset%x09%C(black bold)%ad%Creset%x09%s'
}
## Clear the screen
alias cls='clear;clear'
export DOCKER_RAILS_MYSQL_HOST=172.17.0.2
export DOCKER_RAILS_MYSQL_PORT=3306
export DOCKER_RAILS_MYSQL_USER=root
export DOCKER_RAILS_MYSQL_PASW=webdevel
export DOCKER_RAILS_MYSQL_DB=railsBookDB
## Automatic run: On cd command it will check .ruby-version file and then run uru auto
cd() {
if builtin cd ${1:+"$@"} && [ -e .ruby-version ]; then
uru auto
fi
}
## Remove log files inside the log/ folder. We should run this in the root of your application.
## Example usage: rmlog && npm start
function rmlog() {
# <app-root> / log
# check if log folder is exist.
if [ -d "log" ]
then
echo "[rmlog()] log folder found!"
rm -rf *.*
else
echo "[rmlog()] log folder does not exist."
fi
}
## Export the node .env environment variables. We should run this in the roo app where .env resides.
## Example usage: myenv && npm start
function myenv() {
echo "========================================="
echo " "
echo ".env variables successfully loaded!! "
echo " "
echo "========================================="
set -o allexport; source .env; set +o allexport
}
function rand() {
cat /dev/urandom | base64 | head -n 1 |tr -dc '[:alpha:]' |cut -c -8
}
## Github multiple accounts
## $ cat ~/.ssh/config
## Host *github.com
## User git
## IdentityFile ~/.ssh/company_id_rsa
##
## Host *github-sudogem
## Hostname github.com
## User git
## IdentityFile ~/.ssh/sudogem_id_rsa.pub
## Github login
# For Windows
function github_autologin() {
eval $(ssh-agent)
ssh-add "/c/Users/My Company/.ssh/sudogem_id_rsa"
}
github_autologin
# For Ubuntu
function github_autologin_sudogem() {
eval $(ssh-agent)
ssh-add ~/.ssh/id_rsa_sudogem
}
github_autologin_sudogem
@sudogem
Copy link
Author

sudogem commented Feb 26, 2019

Then run this command to execute the bashrc file in the current terminal: $ source ~/.bashrc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment