From 12cbac42e8283cc97bf28941abb51e930e2ee0ac Mon Sep 17 00:00:00 2001 From: David O'Trakoun Date: Thu, 5 Mar 2015 14:51:02 -0500 Subject: [PATCH] initial commit --- README.md | 30 ++++++++++++++++++++++++++ git-my | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 README.md create mode 100755 git-my diff --git a/README.md b/README.md new file mode 100644 index 0000000..f577a57 --- /dev/null +++ b/README.md @@ -0,0 +1,30 @@ +# git-my v0.1 + +> Lists (stale) (branches|tags) in the remote named (origin) (where you were +> the last committer) + +[Homepage](https://github.com/davidosomething/git-my) + +## Installation + +- Add the `git-my` file somewhere in your path, e.g. `/usr/local/bin/` + +## Usage + +From command line execute: +``` +git my +``` + +## TODO +- Add options: + ``` + -U|--username="gitconfig user.name" + -R|--remote=origin + -T|--tags + -B|--branches + -F|--filter=mine,stale + ``` + +Copyright (c) 2015 David O'Trakoun + diff --git a/git-my b/git-my new file mode 100755 index 0000000..77eab2d --- /dev/null +++ b/git-my @@ -0,0 +1,64 @@ +#!/usr/bin/env bash + +# git-my v0.1 +# +# Lists (stale) (branches|tags) in the remote named (origin) (where you were +# the last committer) +# +# Copyright (c) 2015 David O'Trakoun +# +# Usage: +# git my +# +# Options: +# @todo NOT IMPLEMENTED +# -U|--username="gitconfig user.name" +# -R|--remote=origin +# -T|--tags +# -B|--branches +# -F|--filter=mine,stale +# + +_check_in_repository() { + git rev-parse --git-dir > /dev/null 2>&1 +} + +_filter_mine() { + local git_user=$(git config --get user.name) + + # use eval to not parse the fmt string + local my_remotes=$(echo "$1" | grep -i "^$git_user") + echo "$my_remotes" | awk -F'\t' '{ print $2 }' +} + +# @TODO +_filter_stales() { + local raw_stales=$(git remote prune --dry-run origin) + echo "$raw_stales" +} + +_main() { + if ! _check_in_repository ; then + echo "This is not a git repository." + exit 1 + fi + + # user.namebranch.name + # the TAB is used as a delimiter to awk with + local fmt=' + a=%(authorname) + r=%(refname) + b=${r#refs/remotes/origin/} + printf "%s\t%s\n" "$a" "$b" + ' + + local cmd_everyones_remotes=$( + git for-each-ref --shell --format="$fmt" refs/remotes/origin + ) + local everyones_remotes=$(eval "$cmd_everyones_remotes") + + _filter_mine "$everyones_remotes" +} + +_main +