Last active
August 29, 2015 14:05
-
-
Save dan-bennett/63709627b26c9877748a to your computer and use it in GitHub Desktop.
my shell aliases
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 | |
# backup "<path>" | |
# create a new folder in the backups directory and dump the current directory's contents into it | |
backup(){ | |
mkdir "/path/to/backups/$1"; | |
cp -r . "/path/to/backups/$1"; | |
} | |
# bs | |
# go to the Bootstrap source directory of the current git tree | |
alias bs="cd '$(git rev-parse --show-toplevel)\assets\bootstrap'" | |
# build "thing" | |
# "thing" can be blank, 'less' or 'js' to run the appropriate grunt command | |
# requires aliases: bs, gd, ld, jd, root | |
build(){ | |
bs; | |
if [ $# -eq 0 ]; then | |
gd; | |
elif [ "$1" == "less" ]; then | |
ld; | |
elif [ "$1" == "js" ]; then | |
jd; | |
fi; | |
root; | |
} | |
# colour_my_prompt | |
# should auto-invoke, not for calling yourself | |
# styles your bash prompt with current user, working directory and branch (if in a git dir) | |
color_my_prompt() { | |
local __user_and_host="\[\033[32m\]\u@\h" | |
local __cur_location="\[\033[31m\]\w" | |
local Yellow="\e[0;33m" | |
local __git_branch_color="\[\033[40m\]" | |
local __git_branch='`git branch 2> /dev/null | grep -e ^* | sed -E s/^\\\\\*\ \(.+\)$/\(\\\\\1\)\ /`' | |
local __prompt_tail="\[\033[01;32m\]o_O?" | |
local NC="\e[m" | |
export PS1="\n$__user_and_host: $__cur_location $Yellow$__git_branch\n$__prompt_tail$NC " | |
} | |
color_my_prompt | |
# d | |
# open SQLyog SQL GUI | |
alias d="/c/Program\ Files/SQLyog/SQLyog.exe &" | |
# extract "/path/to/file.tar.gz" | |
# extract a given archive file | |
# from https://github.com/bt3gl/Dotfiles-and-Bash-Examples/blob/master/configs/bashrc | |
extract() | |
{ | |
if [ -f $1 ] ; then | |
case $1 in | |
*.tar.bz2) tar xvjf $1 ;; | |
*.tar.gz) tar xvzf $1 ;; | |
*.bz2) bunzip2 $1 ;; | |
*.rar) unrar x $1 ;; | |
*.gz) gunzip $1 ;; | |
*.tar) tar xvf $1 ;; | |
*.tbz2) tar xvjf $1 ;; | |
*.tgz) tar xvzf $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 | |
} | |
# f | |
# open WinSCP for FTP access | |
alias f="/c/Program\ Files\ \(x86\)/WinSCP/WinSCP.exe &" | |
# fs "<file>" | |
# get total filesize of file/folder in a human readable format | |
alias fs="du -hs" | |
# gd | |
# build all Bootstrap components | |
alias gd="grunt dist" | |
# jd | |
# build Bootstrap JavaScript only | |
alias jd="grunt dist-js" | |
# ld | |
# build Bootstrap LESS only | |
alias ld="grunt dist-css" | |
# l | |
# prettify ls a bit | |
alias l="ls -lA --si --color=auto" | |
# makezip "dir" | |
# ZIP the specified directory | |
makezip(){ | |
zip -r "${1%%/}.zip" "$1" ; | |
} | |
# p | |
# launch putty with password to auto-connect | |
alias p="putty.exe -ssh <user>@<server> -pw <password> &" | |
# r | |
# reload bash profile to allow use of new aliases without closing shell | |
alias r=". ~/.bash_profile" | |
# rd "<path>" | |
# remove a directory's contents recursively and then remove the directory | |
rd(){ | |
rm -rf $1/..?* $1/.[!.]* $1/*; | |
rmdir $1; | |
} | |
# root | |
# go to the root directory of the current git tree | |
alias root="cd '$(git rev-parse --show-toplevel)'" | |
# vm | |
# ssh into the running Vagrant box | |
alias vm='ssh [email protected] -p 2222' | |
# vg <Vagrantfile_dir> <command> | |
# e.g. vg homestead up | |
# control multiple Vagrant boxes without having to manually navigate all over the place | |
vg(){ | |
cwd=$(pwd); | |
cd ~/Vagrant-Playground/$1; # cd path/to/below/Vagrantfile/$1 ($1 == dir containing Vagrantfile) | |
vagrant $2; | |
cd "${cwd}"; | |
} | |
# wtc | |
# commit all local changes with a message form What The Commit | |
wtc() { | |
git add -A .; | |
git commit -m "`curl -s http://whatthecommit.com/index.txt`" | |
} | |
# wtca | |
# ammend the previous WTC commit message if you didn't like it before pushing | |
wtca() { | |
git commit --amend -m "`curl -s http://whatthecommit.com/index.txt`" | |
} |
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 | |
# git b | |
# get your current working directory and the current branch name | |
# (opposed to git branch returning all tracked branches) | |
git config --global alias.b '!echo "directory:" && pwd; echo "branch:" && git rev-parse --abbrev-ref HEAD' | |
# git bd "<branch>" | |
# switch back to master and delete the local copy of the specified branch | |
git config --global alias.bd = '!f() { git ch master; git branch -D "$1"; }; f' -- | |
# git bp "<branch>" | |
# switch back to master and delete the specified branch both locally and on origin | |
git config --global alias.bp = '!f() { git ch master; git branch -D "$1"; git push origin ":$1"; }; f' -- | |
# git ch "<branch>" | |
# shorthand for checkout, does a fetch first so you immediately know if your copy of <branch> is behind | |
git config --global alias.ch = '!f() { git fetch; git checkout "$1"; }; f' -- | |
# git cn "<branch>" | |
# checkout -b followed by push -u to create a new branch and automatically push it to origin | |
git config --global alias.cn = '!f() { git checkout -b "$1"; git push -u origin "$1"; }; f' -- | |
# git cp "<branch>" | |
# checkout to a branch and immediately pull | |
git config --global alias.cp = '!f() { git checkout "$1"; git pull; }; f' -- | |
# git l | |
# pretty commit/merge map for current branch | |
# source: http://fredkschott.com/post/2014/02/git-log-is-so-2005/ | |
git config --global alias.l "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%C(bold blue)<%an>%Creset' --abbrev-commit" | |
# git p "<message>" | |
# push all local changes to origin with (hopefully) an automerge of any downstream commits | |
# stage all changes (modified, deleted, new) and create a commit with <message>, git pull then git push | |
git config --global alias.p '!f() { git add .; git commit -am "$1"; git pull; git push; }; f' -- | |
# git r | |
# quickly rollback all local changes and pull outstanding commits | |
git config --global alias.r '!git remote prune origin; git clean -f -d; git checkout -- .; git pull' | |
# git s | |
# git status is cool and all, but only shows your local status | |
# this does a fetch first to show your status compared to origin | |
git config --global alias.s '!git fetch; git status' | |
# git t <version> <message> | |
# create a tag on your current local branch state and push to origin | |
git config --global alias.t '!f() { git tag -a v$1 -m "$2 $1"; git push origin v$1; }; f' -- | |
# git update <branch> | |
# merge master into a given branch (defaults to current branch if you don't name one) | |
# relies on my 'git r' alias, but that could be swapped out for a standard pull if you want | |
git config --global alias.update "!f() { if [ $# -eq 0 ]; then bra=`git rev-parse --abbrev-ref HEAD`; else bra=$1; fi; st=`git stash -u | grep -o -e 'No local changes to save'`; git checkout master &> /dev/null; echo 'Switched to master.'; git r; git checkout ${bra} &> /dev/null; echo \"Back on ${bra}, beginning merge...\"; git merge origin/master &> /dev/null; git status; if [ \"\" == \"${st}\" ]; then echo 'Some files were stashed, use \"git stash apply\" to retrieve them.'; fi; }; f" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment