From bfebc68743da0749f35681ee1520065555e6c447 Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Sun, 20 Apr 2014 13:36:23 -0700 Subject: [PATCH] Add git replace author, tmux conf resizing short cuts bump .emacs.d to fix mo-git-blame/flymake issue. --- dotfiles/emacs.d | 2 +- dotfiles/lib/python/git_replace_author.py | 107 ++++++++++++++++++++++ dotfiles/tmux.conf | 8 +- 3 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 dotfiles/lib/python/git_replace_author.py diff --git a/dotfiles/emacs.d b/dotfiles/emacs.d index 247fecd4..19826eb2 160000 --- a/dotfiles/emacs.d +++ b/dotfiles/emacs.d @@ -1 +1 @@ -Subproject commit 247fecd40e840e5fe5b803eccf073df2832e251a +Subproject commit 19826eb2019773b1947494f2cccee819afaec74e diff --git a/dotfiles/lib/python/git_replace_author.py b/dotfiles/lib/python/git_replace_author.py new file mode 100644 index 00000000..05f4e84e --- /dev/null +++ b/dotfiles/lib/python/git_replace_author.py @@ -0,0 +1,107 @@ +#!/usr/bin/env python +from collections import namedtuple +import argparse +import re + +from iterpipes import * + + +CommitInfo = namedtuple('CommitInfo', ['hash', 'author', 'email']) + + +class AlwaysMatches(object): + + @classmethod + def matches(*args): + return True + + +class GitAuthorReplacer(object): + + def __init__(self, author_string, email_string, + source_branch='HEAD', commit_matcher=AlwaysMatches): + self.author_string = author_string + self.email_string = email_string + self.source_branch = source_branch + self.commit_matcher = commit_matcher + + @property + def log_triples(self): + return map(self.build_hash_author_email, + run(linecmd('git log --pretty=format:"%h|%an|%ae"'))) + + @staticmethod + def build_hash_author_email(line): + line = line.strip() + print line + print line.split('|') + return CommitInfo(*line.split('|')) + + def recredit_commits(self): + reversed_triples = self.log_triples[::-1] + self.reset(reversed_triples[0]) + self.conditionally_recredit_commit(reversed_triples[0]) + for commit_info in reversed_triples[1:]: + self.cherry_pick(commit_info) + self.conditionally_recredit_commit(commit_info) + + @staticmethod + def reset(commit_info): + return list(run(cmd('git reset --hard {}', commit_info.hash))) + + @staticmethod + def cherry_pick(commit_info): + return list(run(cmd('git cherry-pick {}', commit_info.hash))) + + def conditionally_recredit_commit(self, commit_info): + if self.commit_matcher.matches(commit_info): + return list( + run(cmd('git commit --amend --author "{} {}" -C HEAD', self.author_string, '<{0}>'.format(self.email_string))) + ) + + +class NameMatcher(object): + + def __init__(self, name_regexp): + self.matcher = re.compile(name_regexp) + + def matches(self, commit_info): + return bool(self.matcher.search(commit_info.author)) + + +class AndMatcher(object): + + def __init__(self, *matchers): + self.matchers = matchers + + def matches(self, commit_info): + return all(matcher.matches(commit_info) for matcher in self.matchers) + + +if __name__ == '__main__': + parser = argparse.ArgumentParser() + parser.add_argument( + '--name', + action='store', + type=str, + dest='name', + default='', + help='Name to set for matching commits.', + ) + parser.add_argument( + '--email', + action='store', + type=str, + dest='email', + default='', + help='Email to set for matching commits.' + ) + parser.add_argument( + '--name-re', + action='append', + dest='name_regexps', + help='A regular expression to use when inspecting filepaths' + ) + namespace = parser.parse_args() + name_matchers = map(NameMatcher, namespace.name_regexps) + GitAuthorReplacer(namespace.name, namespace.email, commit_matcher=AndMatcher(*name_matchers)).recredit_commits() \ No newline at end of file diff --git a/dotfiles/tmux.conf b/dotfiles/tmux.conf index 3d04d7cd..0cf6b2ee 100644 --- a/dotfiles/tmux.conf +++ b/dotfiles/tmux.conf @@ -12,4 +12,10 @@ set-option -g status-justify "centre" set-option -g status-left-length 60 set-option -g status-right-length 90 set-option -g status-bg colour235 -set-option -g status-fg colour255 \ No newline at end of file +set-option -g status-fg colour255 + +# Set up resize-pane keys +bind-key + resize-pane -D 3 +bind-key / resize-pane -L 3 +bind-key - resize-pane -U 3 +bind-key * resize-pane -R 3 \ No newline at end of file