Created
February 15, 2018 00:13
-
-
Save boertel/a32f67a27039f628b3bb838ba5376e92 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/bash | |
# usage: ./git-clean PATH TRASH_FOLDER | |
SAVEIFS=$IFS | |
IFS=$(echo -en "\n\b") | |
function github_url { | |
echo "https://`git config --get remote.origin.url | sed -e "s/git@//" -e "s/:/\//" -e s"/\.git//"`" | |
} | |
function open_commit_on_github { | |
open "$(github_url)/commit/$1" | |
} | |
function move_or_remove { | |
if [ "$2" = "" ]; then | |
rm ./$1 | |
else | |
mkdir -p $2$(dirname "$1"); cp -R $1 $2$(dirname "$1"); rm $1; | |
fi | |
} | |
TRASH=$2 | |
for FILE in $(git ls-files $1); do | |
echo ">" $FILE | |
git grep $(basename "$FILE") | |
while true; do | |
read -p "[m]ove/[o]pen/[g]ithub/[c]ommit ? " yn | |
case $yn in | |
[Mm]* ) move_or_remove $FILE $TRASH; break;; | |
[Oo]* ) open $FILE; continue;; | |
[Gg]* ) open_commit_on_github `git log -1 --pretty=oneline --abbrev-commit -- $FILE | cut -f 1 -d " "`; continue;; | |
[Cc]* ) git log -1 --pretty=format:%h%x09%an%x09%ad%x09%s --date=relative -- $FILE; continue;; | |
* ) break;; | |
esac | |
done | |
echo "" | |
done | |
IFS=$SAVEIFS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment