Created
June 30, 2015 20:41
-
-
Save philss/4db11bba7092b76d4f3e to your computer and use it in GitHub Desktop.
Zsh git functions
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
# Put those functions on your ~/.zshrc or something similar. | |
# Cleans all merged branches (relative to the branch you are). Recommended to run from master. | |
function git_clean_branches() | |
{ | |
# Fetch all merged branches that are not the master branch, and not the current branch | |
echo 'Deleting all merged branches...' | |
for branch in `git branch --merged | awk -F ' * ' '{print $2}' | grep -v -e 'master' | grep -v -e '*'` | |
do | |
echo "Removing .. $branch" | |
git branch -d $branch | |
done | |
echo 'Done!' | |
} | |
# List files that contains a given term | |
function git_grep_files() | |
{ | |
git grep $1 | awk -F ':' '{print $1}' | sort | uniq | |
} | |
# Replace terms inside files under the same repository. | |
# Usage git_replace "old_term" "new_term" | |
function git_replace() | |
{ | |
original=$1; | |
new_version=$2; | |
echo "$original -> $new_version" | |
echo | |
for file in `git_grep_files $original`; do | |
echo "Replacing in $file" | |
sed -i '' "s/$1/$2/g" $file; | |
done; | |
echo; | |
echo "Done"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment