Skip to content

Instantly share code, notes, and snippets.

@hraban
Last active June 12, 2018 22:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hraban/c33e8ea3babb8e371c95 to your computer and use it in GitHub Desktop.
Save hraban/c33e8ea3babb8e371c95 to your computer and use it in GitHub Desktop.
bash aliases
#!/bin/bash
#### GIT STUFF
# gitlog only the specified revision(s), e.g. $ gitlog1 master some-feature-branch
alias gitlog1='git log --color --graph --format="format:%C(normal bold)%h%Creset %s%C(red)%d%Creset (%C(yellow)%aN%Creset, %C(green)%ar%Creset)"'
# Entire git commit history with tree and colors and branch names
alias gitlog='gitlog1 --all --branches=\* --remotes=\*'
# Pull from remote and update all branches (assumes every branch tracks origin/<same-branch-name>)
alias gitup='git fetch -p && git branch | tr -d \* | while read b ; do if git merge-base --is-ancestor "$b" "origin/$b"; then git branch -qf "$b" "origin/$b" ; else echo "$b" cannot be fast-forwarded to "origin/$b" ; fi ; done && git checkout master'
# Github-like list of all changed files (not actual diff) in your branch vs. master.
# This is what you will change in master if you'd checkout master and merge in
# your branch.
alias git-pr-changes='git log --format=format: --name-status --no-merges HEAD ^master | grep . | sort -u -k 2'
# List of all (local) branches, most recently changed at the bottom. Useful for
# huuuuge repositories with many branches.
alias branches="git for-each-ref --sort=authordate --format='%(color:normal bold)%(objectname:short)%(color:reset)%09%(color:red)%(refname:short)%(color:reset)%09%(contents:subject) (%(color:yellow)%(authorname)%(color:reset), %(color:green)%(authordate:relative)%(color:reset))' refs/heads/ refs/remotes/origin/ | column -t -s $'\t'"
### STANDARD STUFF
alias ls="ls -G"
alias l=ls
alias cp='cp -i'
alias mv='mv -i'
alias rm='rm -i'
alias s="cd .."
alias sbt="sbt -java-home /var/lib/jdk1.8.0_40/"
# YAML to JSON
alias y2j="ruby -ryaml -rjson -e 'puts JSON.pretty_generate(YAML.load(ARGF))' "
alias bru=brew
# Run gae flex env apps locally with the right envvars.
#
# $ docker run $(gaeenv) my-flex-env-image
# or
# $ eval "$(GAEENV)" ; # now run your apps
alias gaeenv='y2j app.yaml | jq -r '\''.env_variables | to_entries | map("-e \(.key)=\(.value)") | join(" ")'\'
alias GAEENV='y2j app.yaml | jq -r '\''.env_variables | to_entries | map("export \(.key)=\"\(.value)\"") | join("; ")'\'
# Set AWS credentials as environment variables from credentials file
alias awsenv='[[ -f ~/.aws/credentials ]] && eval $(perl -ne '\''print if s/(aws_.*): (.*)/export \U\1\E="\2"/'\'' < ~/.aws/credentials) || echo "No ~/.aws/credentials found"'
# Extract the n-th field (common use of awk). If a second argument is
# provided, it is interpreted as the split character.
#
# Example:
#
# $ echo foom fi fo | fawk 2
# fi
# $ echo foo,bar,baz | fawk 2 ,
# bar
#
function fawk {
awk ${2:+-F $2} "{print \$$1}"
}
@dougpagani
Copy link

Wow! Such code.

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