Skip to content

Instantly share code, notes, and snippets.

@MyklClason
Last active July 23, 2024 18:49
Show Gist options
  • Save MyklClason/d71a39ace28b9ec9f0ad to your computer and use it in GitHub Desktop.
Save MyklClason/d71a39ace28b9ec9f0ad to your computer and use it in GitHub Desktop.
List of useful terminal bash aliases for Ruby On Rails, Cloud9, Git and more. What are bash aliases: http://www.tldp.org/LDP/abs/html/aliases.html What does && and ; do? http://unix.stackexchange.com/a/304258
alias ls='ls --color=auto -F'
alias grep='grep --color=auto'
alias fgrep='fgrep --color=auto'
alias egrep='egrep --color=auto'
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'
alias less="less -R "
alias mysqldump="mysqldump --user=$C9_USER --host=$IP"
alias php="php -c ~/workspace/php.ini"
alias ..="cd .."
alias ctw='killall tmux' # Close Terminal Windows. Closes all terminal windows. Acts more as a hard reset for terminal windows in Cloud9.
# ----------------------
# Ubuntu
# ----------------------
alias ucru="free -m" # Ubuntu Check RAM Usage. Checks ram usage
alias ucdu="df -h" # Ubuntu Check Disk Usage. Checks disk usage
# ----------------------
# Cloud9 Aliases
# ----------------------
alias c9ct="sudo rm -rf /tmp/*" # Clear the temp files folder
alias c9mr="sudo /etc/init.d/mysql start && sudo service redis-server start" # Start mysql2 and redis servers
# ----------------------
# Django
# ----------------------
alias pmrs='python manage.py runserver $IP:$PORT'
alias c9ds='python manage.py runserver $IP:$PORT' # C9, Django Server
alias pmcs='python manage.py collectstatic'
alias pmm='python manage.py migrate'
# ----------------------
# Python
# ----------------------
alias pelr='pipenv lock --requirements'
alias pir='pip install -r requirements.txt'
# ----------------------
# Rails Aliases
# Many from: https://github.com/ndbroadbent/rails_shell
# ----------------------
alias c9s="rails s -b $IP -p $PORT" # Cloud 9 server, Run rails server
alias c9sp="pgr && rails s -b $IP -p $PORT" # Cloud 9 Server Postgres, restarts Postgres server then runs rails server
alias c9p="rails s -b $IP -p $PORT puma" # Cloud 9 server (Puma), Run rails server via Puma
alias c9pr='pgr && sudo service redis-server start && c9s'
alias rg='rails generate'
alias rgc='rails generate controller'
alias rgm='rails generate migration'
alias rgbt='rails g bootstrap:themed'
alias rgvc='rails generate component'
alias rdvc='rails destroy component'
alias rdbm='rake db:migrate'
alias rdbm0='rake db:migrate VERSION=0'
alias rdbmu='rake db:migrate:up'
alias rdbmd='rake db:migrate:down'
alias rdbr='rake db:rollback'
alias rdbc='rake db:create'
alias rdbp='rake db:drop'
alias rdbs='rake db:seed'
alias rdbhr='pgr && rake db:drop db:create db:migrate db:schema:dump db:setup' # db hard reset
alias rr='rails routes'
alias rrg='rails routes | grep'
alias b='bundle'
alias ber='bundle exec rspec'
alias bi='bundle install'
alias biwp='bundle install --without production'
alias bu='bundle update'
alias bui='bundle update && bundle install' # Bundle update and install, update doesn't touch Gemfile.lock
#-----------------------
# Rubocop
#-----------------------
alias rc='rubocop' # Run rubocop
alias rca='rubocop -a' # Run rubocop autocorrect
alias rcagc='rubocop --auto-gen-config' # Run rubocop autogen config
#-----------------------
# Standard Ruby
#-----------------------
alias stdrb='standardrb --fix' # Standard ruby, always autofix
alias stdrbtd='standardrb --fix; standardrb --generate-todo' # Fix safely, then gen todo for anything unsafe or unfixable
alias stdrbfus='standardrb --fix-unsafely' # Standard ruby fix unsafely
#-----------------------
# ERB Lint
#-----------------------
alias erbl='erblint --lint-all --config .erb-lint.yml' # ERB Lint autocorrect
alias erblac='erblint --lint-all --config .erb-lint.yml --autocorrect' # ERB Lint autocorrect
#-----------------------
# Slim Lint
#-----------------------
alias sl='slim-lint app/**/*.slim --config .slim-lint.yml' # Run Slim lint
#-----------------------
# Webpacker
#-----------------------
alias wps='./bin/webpack-dev-server'
#-----------------------
# Rails Setup Helpers (make into generators?)
#-----------------------
# Devise Setup (Add a name for the user model at the end)
alias sud='rails generate devise:install && rails generate devise'
# Devise with Bootstrap Setup (Still need to add to application.css)
alias sudbs='rails generate bootstrap:install static && rails g devise:views:locale en && rails g devise:views:bootstrap_templates'
# ----------------------
# RVM
# ----------------------
# This is often needed after switching ruby versions.
alias rvmlid='rvm use ruby --latest --install --default' # RVM latest stable ruby install as default
alias rvmdu='rvm use --default' # RVM Default Use, sets the default ruby version (IE: rvmdu 2.4.0)
alias rvmudi='rvm use --default --install' # RVM Default Use, sets the default ruby version (IE: rvmdu 2.4.0)
alias bs='gem install bundle && bundle install' # Bundle Setup, adds the bundle gem and updates
alias bsu='gem install bundle && bundle update && bundle install' # Bundle Setup, adds the bundle gem and updates
# ----------------------
# Postgres
# ----------------------
alias pgr="sudo service postgresql stop && sudo service postgresql start"
# Postgres Setup: https://github.com/Aerogami/guides/wiki/Cloud9-workspace-setup-with-Rails-and-Postgresql
alias c9pgr="pg_restore --verbose --clean --no-acl --no-owner -h $IP -U ubuntu -d"
# Cloud9 pg_restore, just add database name and dump file name
# ----------------------
# MySQL
# ----------------------
alias msr="sudo /etc/init.d/mysql stop && sudo /etc/init.d/mysql start" # Restart MySQL server
# ----------------------
# Brunch.io (NodeJS)
# ----------------------
alias bb="brunch build"
alias bbp="brunch build --production"
# ----------------------
# Git Aliases (V1.X)
# ----------------------
alias gic='git init && git add -A && git commit -m "Initial commit"' # Git initial commit
alias ga='git add'
alias gaa='git add -A' # Stage All (New/Modified/Deleted)
alias gaad='git add -A && git diff --staged' # Stage All and check diffs
alias gad='git add .' # ... Exclude Deleted
alias gan='git add -u' # ... Exclude New
alias gac='git add -A && git commit -m' # Add all and commit
alias gb='git branch'
# https://coderwall.com/p/x3jmig/remove-all-your-local-git-branches-but-keep-master
# - Extended to incldue staging and develop branches
alias gbd='git branch -d' # Safer Delete
alias gbda='git branch | grep -v "master\|staging\|develop" | xargs git branch -d' # Safer Delete
alias gbD='git branch -D' # Risky Delete
alias gbDa='git branch | grep -v "master\|staging\|develop" | xargs git branch -D' # Risky Delete
alias gbr='git branch -m' # Git Branch Rename
alias gcm='git commit -m'
alias gco='git checkout'
alias gcob='git checkout -b'
alias gcom='git checkout master'
alias gcos='git checkout staging'
alias gcod='git checkout develop' # Checkout development branch
alias gcodev='git checkout development' # Checkout development branch
alias gcp="git cherry-pick"
alias gd='git diff'
alias gda='git diff HEAD'
alias gds='git diff --staged'
alias gf='git fetch'
alias gi='git init'
alias gl='git log'
alias glg='git log --graph --oneline --decorate --all'
alias gld='git log --pretty=format:"%h %ad %s" --date=short --all'
alias gm='git merge --no-ff'
alias gmff='git merge'
alias gp='git pull'
alias gpm='git push' # Push to Github
alias gpo='git push origin' # Push to Github (V2)
alias gphm='git push heroku master' # Push to Heroku
alias gphp='git push heroku-production master' # Push to Heroku (production)
alias gphs='git push heroku-staging staging:master' # Push to Heroku (staging)
alias grbc="git rebase --continue"
alias grbac="git add -A && git rebase --continue"
alias grbrc="git reset && git rebase --continue"
alias grHa="git add -A && git reset --hard HEAD" # Git Reset Hard All, Add all and reset hard to HEAD
alias grhH="git reset --hard HEAD" # Git Reset Hard All, Add all and reset hard to HEAD
alias grs="git reset HEAD" # Git Remove From Staging
alias grs="git reset HEAD" # Git Remove From Staging
alias guc='git reset HEAD^ && gss' # Git Undo Commit; unstage, undo commit, and show status
alias gss='git status -s'
alias gsss='git status'
alias gst='git stash'
alias gstl='git stash list'
alias gstp='git stash pop'
alias gstd='git stash drop'
alias gtd='git update-index --assume-unchanged' # Git Track Disable; disable tracking of changes
alias gte='git update-index --no-assume-unchanged' # Git Track Enabled; enable tracking of changes
alias grlt="git reflog --date=iso"
#-----------------------
# Heroku
#-----------------------
alias hf="heroku update || heroku help" # Heroku Fix; Fixes most heroku issues
alias huf="wget -qO- https://cli-assets.heroku.com/install-ubuntu.sh | sh" # Heroku Update Force, updates forcefully
alias hai="heroku apps:info" # Get info on current Heroku App
alias hgra="heroku git:remote -a" # Heroku Add Git Remote, adds git remote for app
alias hrm='heroku run --remote heroku-production'
alias hrs='heroku run --remote heroku-staging'
alias hrdm="heroku run rake db:migrate"
alias hrdhr="heroku run 'rake db:drop db:create db:migrate db:schema:dump db:setup'"
alias hrdbm0='rake db:migrate VERSION=0'
alias hl="heroku logs" # Logs
alias hlg="heroku logs -n 10000 | grep" # Logs w/ grep
alias hlt="heroku logs -t"
alias hltg="heroku logs -t -n 10000 | grep" # Logs Tail w/ grep
alias hld="heroku logs -n 10000 > tmp/heroku-logs.log" # Heroku logs dump, dumps heroku logs to tmp file
alias rap="RAILS_ENV=production rake assets:precompile" # Rails assets precompile
alias hpa="rap && gac 'Precompile assets for Heroku' " # Heroku Precompile Assets and Commit
# ----------------------
# Expo.io
# ----------------------
alias est='expo start --tunnel'
# ----------------------
# Git Flow
# ----------------------
# Safely clean up merged branches before fetching and checkout of develop
alias gffcod='gbda; git fetch && git checkout develop'
alias gffs='gffcod && gcos && git flow feature start'
alias gfrb='gffcod && git pull origin develop && git rebase -i develop'
alias gfrspec='xvfb-run -a bundle exec rspec'
# ----------------------
# Misc
# ----------------------
alias gfrspec='xvfb-run -a bundle exec rspec'
# ----------------------
# Alias Functions
# ----------------------
bstcs () {
# Bootstrap themed controller scaffold
rails g scaffold_controller $1 && rails g bootstrap:themed $2
}
@MyklClason
Copy link
Author

MyklClason commented Feb 19, 2016

Cloud9:
This should be entered in the hidden file, .bash_aliases which can be easily edited via selecting the option "Show Home in Favorites". Recommend favoriting this file (in Cloud9) for future reference (via right click). Note: Any changes to this file will only take effect when the terminal is reset. Recommend closing all terminal windows and opening up new ones to allow for the terminal to load the changes.

@MyklClason
Copy link
Author

MyklClason commented Dec 4, 2017

AWS Cloud9:
You'll need to create the .bash_aliases folder by right clicking on the ~ folder and clicking "New file. The .at the start of the filename is very important. Then add the following to the end of the.bashrc` file.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

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