Skip to content

Instantly share code, notes, and snippets.

@bvanderlaan
Last active April 5, 2020 13:34
Show Gist options
  • Save bvanderlaan/8f9b5d4bee10b364a22345f40ffc15d0 to your computer and use it in GitHub Desktop.
Save bvanderlaan/8f9b5d4bee10b364a22345f40ffc15d0 to your computer and use it in GitHub Desktop.
My dot Files

Just thought I'd drop this somewhere I can get at it if I need to redo my machine. For my terminal's PS1 I tend to do this:

parse_git_branch() {
  git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}

rightprompt() {
 printf "\[\033[91m\]||< max-length\[\033[00m\]"
}

export PS1="\u@\h in \[\033[93m\]\W\[\033[32m\]\$(parse_git_branch)\[\033[00m\] $ \[$(tput sc; tput cuf 72; rightprompt; tput rc)\]"
export PS2="> \[$(tput sc; tput cuf 80; rightprompt; tput rc)\]"
  • The max length is so I know when I've hit the limit of a git commit summary

I also add these functions to help up with development.

Clean up Local Branches

Working with git means you get the power of switching tasks quickly with multiple branches; the down side is that you end up with branches to the left of you, branches to the right of you, branches all around you. Best practice is to clean up your local branches once they are merged but to simplify that task I have this function: cleanlocal It will purge any branchs which have been merged (and deleted) on the origin.

function cleanlocal() {
  DELETE_COMMAND="branch -d"

  if [ "$1" = "-f" ]; then
    DELETE_COMMAND="branch -D"
  fi

  echo 'purging local git branchs'
  git remote prune origin
  git branch -r | awk '{print $1}' | egrep -v -f /dev/fd/0 <(git branch -vv | grep origin) | awk '{print $1}' | xargs ${DELETE_COMMAND}
}

View a users open PRs

When working on a team across multiple repositories within an orginziation I often loose track of who has open PRs for which repo. To help me find open PRs I use GitHub's advanced search feature which can do a cross repo query for open PRs

To quickly perform a cross repo query for a given user I added the below function where I pass in the users GitHub user name and get an open browser showing me the cross repo search results.

$ pr jsmith
function pr() {
  URL="https://github.com/search?utf8=%E2%9C%93&q=is%3Aopen+is%3Apr+user%3$org+author%3A$1&type="
  echo "Opening PRs for $1"
  $(open $URL)
}

If I'm using cygwin then I need to set an alias for open: alias open='cygstart'

$org is set to the orginization

Jump to JIRA

At work I use JIRA for my ALM system but the number of clicks I have to do to get to an issue is painful so the next time someone says to me can you look at issue PROJ-1234 I use this function to jump to it.

jira PROJ-1234

This will open a browser directly to this issue.

function jira() {
  open https://jira.opentext.com/browse/$1
}
@bvanderlaan
Copy link
Author

Also here are some git alias I use:

co = checkout
	s = status
	a = add
	c = commit
	p = push
  sync = !git checkout master && git pull upstream master && git submodule update
  l = log --graph --oneline --decorate --pretty=format:'%C(bold blue)%h%C(reset) - %C(magenta)(%ar)%C(reset)%C(auto)%d %C(reset)%C(white)%s%C(reset) %C(dim white)- %C(bold white)%an%C(reset)' --all

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