Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a Makefile and rename git-playback to git-playback.sh
- Loading branch information
Showing
4 changed files
with
183 additions
and
144 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
prefix ?= /usr/local | ||
gitdir ?= $(shell git --exec-path) | ||
|
||
gitver ?= $(word 3,$(shell git --version)) | ||
|
||
INSTALL ?= install | ||
INSTALL_DATA = $(INSTALL) -c -m 0644 | ||
INSTALL_EXE = $(INSTALL) -c -m 0755 | ||
INSTALL_DIR = $(INSTALL) -c -d -m 0755 | ||
|
||
default: | ||
@echo "git-playback doesn't need to be built." | ||
@echo "Just copy it (including playback.css and playback.js) somewhere on your PATH, like /usr/local/bin." | ||
@false | ||
|
||
install: install-exe install-js install-css | ||
|
||
install-exe: git-playback.sh | ||
$(INSTALL_DIR) $(DESTDIR)/$(gitdir) | ||
$(INSTALL_EXE) $< $(DESTDIR)/$(gitdir)/git-playback | ||
|
||
install-js: playback.js | ||
$(INSTALL_DIR) $(DESTDIR)/$(gitdir) | ||
$(INSTALL_DATA) $< $(DESTDIR)/$(gitdir) | ||
|
||
install-css: playback.css | ||
$(INSTALL_DIR) $(DESTDIR)/$(gitdir) | ||
$(INSTALL_DATA) $< $(DESTDIR)/$(gitdir) |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,142 +1 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
if [ $# -eq 0 ]; then | ||
set -- -h | ||
fi | ||
|
||
OPTS_SPEC="\ | ||
git playback file1 file2 ... | ||
-- | ||
h,help show the help | ||
s,start= specify start revision | ||
e,end= specify end revision | ||
t,style= specify style to be used in output | ||
l,stylelist list all available styles | ||
" | ||
eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)" | ||
|
||
get_git_branch() { | ||
git branch 2>/dev/null | grep -e ^* | tr -d \* | ||
} | ||
|
||
get_root_commit() { | ||
git rev-list --max-parents=0 HEAD 2>/dev/null | tr -d \* | ||
} | ||
|
||
files=() | ||
output_file='playback.html' | ||
start_revision=`get_root_commit` | ||
end_revision=`get_git_branch` | ||
style='default' | ||
available_styles=(default dark far idea sunburst zenburn vs ascetic magula github googlecode brown_paper school_book ir_black solarized_dark solarized_light arta monokai) | ||
|
||
while [ $# -gt 0 ]; do | ||
opt="$1" | ||
shift | ||
case "$opt" in | ||
-s) start_revision="$1"; shift;; | ||
-e) end_revision="$1"; shift;; | ||
-t) style="$1"; shift;; | ||
-l) echo ${available_styles[@]}; exit;; | ||
*) files+=("$1") ;; | ||
esac | ||
done | ||
|
||
is_style_available() { | ||
for i in ${available_styles[@]}; do | ||
if [ $i == $1 ]; then | ||
return 1 | ||
fi | ||
done | ||
return 0 | ||
} | ||
|
||
if is_style_available $style; then | ||
echo "Style is not available: ${style}. You can list available styles with --stylelist." | ||
exit 1 | ||
fi | ||
|
||
source_file="${BASH_SOURCE[0]}" | ||
while [ -h "$source_file" ]; do | ||
source_file="$(readlink "$source_file")"; | ||
done | ||
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd -P "$(dirname "$source_file")" && pwd)" | ||
unset source_file | ||
|
||
js=`cat ${script_dir}/playback.js` | ||
css=`cat ${script_dir}/playback.css` | ||
htmlStart="<!DOCTYPE html> | ||
<html lang='en'> | ||
<head> | ||
<meta charset='utf-8'> | ||
<title>Git Playback</title> | ||
<style type='text/css'>${css}</style> | ||
<link rel='stylesheet' href='http://yandex.st/highlightjs/6.2/styles/${style}.min.css' type='text/css'> | ||
</head> | ||
<body> | ||
<div id='playback'> | ||
<div class='container'>" | ||
|
||
htmlEnd="</div> | ||
</div> | ||
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script> | ||
<script src='http://yandex.st/highlightjs/6.2/highlight.min.js'></script> | ||
<script type='text/javascript'>${js}</script> | ||
<script> | ||
jQuery(document).ready(function(){ | ||
jQuery('#playback').playback(); | ||
hljs.initHighlightingOnLoad(); | ||
var background = jQuery('pre code').css('background-color'); | ||
jQuery('body').css('background-color', background); | ||
}); | ||
</script> | ||
</body> | ||
</html>" | ||
|
||
|
||
foreach_git_revision() { | ||
command=$1 | ||
|
||
revisions=`git rev-list --reverse ${end_revision} ^${start_revision}` | ||
|
||
for revision in $revisions; do | ||
git checkout --quiet $revision | ||
eval $command | ||
git reset --hard | ||
done | ||
|
||
git checkout --quiet $end_revision | ||
} | ||
|
||
output_to_file() { | ||
no_files=true | ||
for file in ${files[@]} | ||
do | ||
if [ -f $file ] && [ -s $file ]; then | ||
no_files=false | ||
fi | ||
done | ||
|
||
if ! $no_files; then | ||
echo '<div><ul>' >> $output_file | ||
for file in ${files[@]} | ||
do | ||
echo '<li><pre><code>' >> $output_file | ||
if [ -f $file ]; then | ||
cat $file >> $output_file | ||
fi | ||
echo '</code></pre></li>' >> $output_file | ||
done | ||
echo '</ul></div>' >> $output_file | ||
fi | ||
} | ||
|
||
rm -f $output_file | ||
echo $htmlStart >> $output_file | ||
foreach_git_revision output_to_file | ||
echo $htmlEnd >> $output_file | ||
git-playback.sh |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
if [ $# -eq 0 ]; then | ||
set -- -h | ||
fi | ||
|
||
OPTS_SPEC="\ | ||
git playback file1 file2 ... | ||
-- | ||
h,help show the help | ||
s,start= specify start revision. Default: root commit | ||
e,end= specify end revision. Default: current branch | ||
t,style= specify style to be used in output | ||
l,stylelist list all available styles | ||
" | ||
eval "$(echo "$OPTS_SPEC" | git rev-parse --parseopt -- "$@" || echo exit $?)" | ||
|
||
get_git_branch() { | ||
git branch 2>/dev/null | grep -e ^* | tr -d \* | ||
} | ||
|
||
get_root_commit() { | ||
git rev-list --max-parents=0 HEAD 2>/dev/null | tr -d \* | ||
} | ||
|
||
files=() | ||
output_file='playback.html' | ||
start_revision=`get_root_commit` | ||
end_revision=`get_git_branch` | ||
style='default' | ||
available_styles=(default dark far idea sunburst zenburn vs ascetic magula github googlecode brown_paper school_book ir_black solarized_dark solarized_light arta monokai) | ||
|
||
while [ $# -gt 0 ]; do | ||
opt="$1" | ||
shift | ||
case "$opt" in | ||
-s) start_revision="$1"; shift;; | ||
-e) end_revision="$1"; shift;; | ||
-t) style="$1"; shift;; | ||
-l) echo ${available_styles[@]}; exit;; | ||
*) files+=("$1") ;; | ||
esac | ||
done | ||
|
||
is_style_available() { | ||
for i in ${available_styles[@]}; do | ||
if [ $i == $1 ]; then | ||
return 1 | ||
fi | ||
done | ||
return 0 | ||
} | ||
|
||
if is_style_available $style; then | ||
echo "Style is not available: ${style}. You can list available styles with --stylelist." | ||
exit 1 | ||
fi | ||
|
||
source_file="${BASH_SOURCE[0]}" | ||
while [ -h "$source_file" ]; do | ||
source_file="$(readlink "$source_file")"; | ||
done | ||
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd -P "$(dirname "$source_file")" && pwd)" | ||
unset source_file | ||
|
||
js=`cat ${script_dir}/playback.js` | ||
css=`cat ${script_dir}/playback.css` | ||
htmlStart="<!DOCTYPE html> | ||
<html lang='en'> | ||
<head> | ||
<meta charset='utf-8'> | ||
<title>Git Playback</title> | ||
<style type='text/css'>${css}</style> | ||
<link rel='stylesheet' href='http://yandex.st/highlightjs/6.2/styles/${style}.min.css' type='text/css'> | ||
</head> | ||
<body> | ||
<div id='playback'> | ||
<div class='container'>" | ||
|
||
htmlEnd="</div> | ||
</div> | ||
<script src='https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js'></script> | ||
<script src='http://yandex.st/highlightjs/6.2/highlight.min.js'></script> | ||
<script type='text/javascript'>${js}</script> | ||
<script> | ||
jQuery(document).ready(function(){ | ||
jQuery('#playback').playback(); | ||
hljs.initHighlightingOnLoad(); | ||
var background = jQuery('pre code').css('background-color'); | ||
jQuery('body').css('background-color', background); | ||
}); | ||
</script> | ||
</body> | ||
</html>" | ||
|
||
|
||
foreach_git_revision() { | ||
command=$1 | ||
|
||
revisions=`git rev-list --reverse ${end_revision} ^${start_revision}` | ||
|
||
for revision in $revisions; do | ||
git checkout --quiet $revision | ||
eval $command | ||
git reset --hard | ||
done | ||
|
||
git checkout --quiet $end_revision | ||
} | ||
|
||
output_to_file() { | ||
no_files=true | ||
for file in ${files[@]} | ||
do | ||
if [ -f $file ] && [ -s $file ]; then | ||
no_files=false | ||
fi | ||
done | ||
|
||
if ! $no_files; then | ||
echo '<div><ul>' >> $output_file | ||
for file in ${files[@]} | ||
do | ||
echo '<li><pre><code>' >> $output_file | ||
if [ -f $file ]; then | ||
cat $file >> $output_file | ||
fi | ||
echo '</code></pre></li>' >> $output_file | ||
done | ||
echo '</ul></div>' >> $output_file | ||
fi | ||
} | ||
|
||
rm -f $output_file | ||
echo $htmlStart >> $output_file | ||
foreach_git_revision output_to_file | ||
echo $htmlEnd >> $output_file |