Skip to content

Commit

Permalink
feat(scripts): Allow override of dependencies at runtime as well as b…
Browse files Browse the repository at this point in the history
…uild time
  • Loading branch information
alerque committed Aug 21, 2024
1 parent 78faebe commit 3279586
Show file tree
Hide file tree
Showing 14 changed files with 104 additions and 67 deletions.
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ AM_COND_IF([DEPENDENCY_CHECKS], [
QUE_PROGVAR([bc])
QUE_PROGVAR([curl])
QUE_PROGVAR([cut])
QUE_PROGVAR([date])
QUE_PROGVAR([decasify])
QUE_PROGVAR([deepl])
QUE_PROGVAR([diff])
Expand Down
1 change: 1 addition & 0 deletions rules/casile.mk.in
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ BC ?= @BC@
CMP ?= @CMP@
CURL ?= @CURL@
CUT ?= @CUT@
DATE ?= @DATE@
DECASIFY ?= @DECASIFY@
DEEPL ?= @DEEPL@
DIFF ?= @DIFF@
Expand Down
4 changes: 2 additions & 2 deletions rules/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -1176,7 +1176,7 @@ $(BUILDDIR)/repository-worklog.sqlite: $(BUILDDIR)/repository-lastcommit.ts
WORKLOGFIELDS := sha AS 'Commit', date AS 'Date', file AS 'Filename', added AS 'Added', removed AS 'Removed'

$(BUILDDIR)/repository-worklog.md: $(BUILDDIR)/repository-worklog.sqlite force
now="$$(LANG=en_US date +%c)"
now="$$(LANG=en_US $(DATE) +%c)"
ver="$(call versioninfo,$(PROJECT))"
export IFS='|'
$(SQLITE3) $< "SELECT DISTINCT(author) FROM commits" |
Expand All @@ -1186,7 +1186,7 @@ $(BUILDDIR)/repository-worklog.md: $(BUILDDIR)/repository-worklog.sqlite force
$(SQLITE3) $< "SELECT SUM(added+ -removed) FROM commits WHERE author='$${author}' and strftime('%Y-%m', date)='$${month}'" | read netadded
[[ $${netadded} -ge 1 ]] || continue
echo "# Worklog for $${author}"
echo "## $$(LANG=en_US date +'%B %Y' -d $${month}-01)"
echo "## $$(LANG=en_US $(DATE) +'%B %Y' -d $${month}-01)"
echo
echo "Report Generated on $${now} from repository $${ver}."
echo
Expand Down
25 changes: 15 additions & 10 deletions scripts/branch2criticmark.zsh.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,31 @@

CASILEDIR=$(cd "$(dirname $0)/../" && pwd)

alias git="${GIT:-@GIT@}"
alias m4="${M4:-@M4@}"
alias perl="${PERL:-@PERL@}"
alias sed="${SED:-@SED@}"

BRANCH=${1}
FILE=${2}
WT=$(mktemp -d -u worktree-diff.XXXXXX)

trap 'rm -rf ${WT}' EXIT SIGHUP SIGTERM

@GIT@ worktree prune > /dev/null
@GIT@ worktree add --detach ${WT} ${BRANCH} > /dev/null
git worktree prune > /dev/null
git worktree add --detach ${WT} ${BRANCH} > /dev/null

@M4@ ${FILTERS} ${WT}/${FILE} | @GIT@ hash-object --stdin -w | read A
@M4@ ${FILTERS} ${FILE} | @GIT@ hash-object --stdin -w | read B
m4 ${FILTERS} ${WT}/${FILE} | git hash-object --stdin -w | read A
m4 ${FILTERS} ${FILE} | git hash-object --stdin -w | read B

if @GIT@ diff ${A}..${B} --quiet; then
@GIT@ show ${B}
if git diff ${A}..${B} --quiet; then
git show ${B}
else
@GIT@ diff --no-color --word-diff -U99999 ${A}..${B} |
@SED@ -e '1,5d' |
@PERL@ -pn \
git diff --no-color --word-diff -U99999 ${A}..${B} |
sed -e '1,5d' |
perl -pn \
-e 's/\[-[^\]]*?-\]\{\+([^\}]*?==.*?)\+\}/\1/g' |
@SED@ \
sed \
-e 's/\[-/{--/g' -e 's/-\]/--}/g' \
-e 's/{+/{++/g' -e 's/+}/++}/g'
fi
9 changes: 6 additions & 3 deletions scripts/diff2marked.zsh.in
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#!@ZSH@

alias git="${GIT:-@GIT@}"
alias sed="${SED:-@SED@}"

cd $MARKED_ORIGIN
if @GIT@ diff --quiet -- $MARKED_PATH; then
if git diff --quiet -- $MARKED_PATH; then
cat -
exit
else
cat - > /dev/null
@GIT@ diff --no-color --word-diff -U99999 -- $MARKED_PATH |
@SED@ -e '1,5d' \
git diff --no-color --word-diff -U99999 -- $MARKED_PATH |
sed -e '1,5d' \
-e 's/\\[A-Za-z0-9]*{\(.*\)}/\1/g' \
-e 's/\\[A-Za-z0-9]* //g' \
-e 's/ *{[-\.].*}$//g' \
Expand Down
3 changes: 1 addition & 2 deletions scripts/flatten_chapters.zsh.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ set -e

source "$CASILEDIR/scripts/functions.zsh"

: ${CASILE-:casile}
alias casile="$CASILE"
alias casile="${CASILE-:casile}"

bookid=$1
test -n $bookid
Expand Down
12 changes: 6 additions & 6 deletions scripts/functions.zsh.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function flunk () {
}

function require_pristine_project () {
alias git="@GIT@"
alias git="${GIT:-@GIT@}"
# disallow anything already staged
git diff-index --quiet --cached HEAD ||
flunk 'Staging not clean'
Expand All @@ -14,17 +14,17 @@ function require_pristine_project () {
}

function track () {
alias git="@GIT@"
alias git="${GIT:-@GIT@}"
git add $=@
}

function untrack () {
alias git="@GIT@"
alias git="${GIT:-@GIT@}"
git rm -rf --ignore-unmatch .untracked $=@
}

function commit () {
alias git="@GIT@"
alias git="${GIT:-@GIT@}"
git diff-index --quiet --cached HEAD ||
git commit -m "[auto] $@"
}
Expand All @@ -39,7 +39,7 @@ function remove_extant_bookid () {
}

function normalize_scrivener_mmd () {
alias sed="@SED@"
alias sed="${SED:-@SED@}"
sed -E 's/^\\#\\#\\#$/----/' |
sed -E 's/^\*:::/::: */' |
sed -E 's/^::: (\*)? ?.verse/::: verse\n\1/' |
Expand All @@ -49,7 +49,7 @@ function normalize_scrivener_mmd () {
}

function normalize_pandoc () {
alias pandoc="@PANDOC@"
alias pandoc="${PANDOC:-@PANDOC@}"
pandoc_args=(
--wrap=preserve
--markdown-headings=atx
Expand Down
6 changes: 3 additions & 3 deletions scripts/import.zsh.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!@ZSH@
set -e

alias git="@GIT@"
alias git="${GIT:-@GIT@}"

setopt -o nullglob

Expand All @@ -22,8 +22,8 @@ function import_scrivener-mmd () {
--lua-filter="$CASILEDIR/pandoc-filters/mark-parts.lua"
--lua-filter="$CASILEDIR/pandoc-filters/mark-epigraphs.lua"
)
alias sed="@SED@"
alias pandoc="@PANDOC@"
alias sed="${SED:-@SED@}"
alias pandoc="${PANDOC:-@PANDOC@}"
: ${bookid:=$1}
: ${input:=$2}
cat $input |
Expand Down
8 changes: 4 additions & 4 deletions scripts/list_related_files.zsh.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ case $cmd in
value $bookid.yml
;;
mds)
alias git="@GIT@"
alias sed="@SED@"
alias sort="@SORT@"
alias git="${GIT:-@GIT@}"
alias sed="${SED:-@SED@}"
alias sort="${SORT:-@SORT@}"
# wrangle our own sorting so NNN.md comes before NNN-foo/bar.md
git ls-files "$PROJECT.md" "$PROJECT-*.md" "$bookid.md" "$bookid-**.md" |
sed -E 's/\.md$/,md/' |
Expand All @@ -25,7 +25,7 @@ case $cmd in
exit 0
;;
srcid)
alias yq="@YQ@"
alias yq="${YQ:-@YQ@}"
$0 meta $2 | read meta
if [[ -f $meta ]] && yq -e 'has("source")' $meta >/dev/null; then
yq -r '[.source[] | select(.type == "bookid")][0].text' $meta | read bookid
Expand Down
6 changes: 3 additions & 3 deletions scripts/normalize_files.zsh.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ set -e

source "$CASILEDIR/scripts/functions.zsh"

alias git="@GIT@"
alias pandoc="@PANDOC@"
alias rg="@RG@"
alias git="${GIT:-@GIT@}"
alias pandoc="${PANDOC:-@PANDOC@}"
alias rg="${RG:-@RG@}"

: ${bookid:=$1}
test -n bookid
Expand Down
10 changes: 5 additions & 5 deletions scripts/split_chapters.zsh.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ set -e

source "$CASILEDIR/scripts/functions.zsh"

alias pandoc="@PANDOC@"
alias sed="@SED@"
alias mkdir="@MKDIR_P@"
alias parallel="@PARALLEL@"
alias pandoc="${PANDOC:-@PANDOC@}"
alias sed="${SED:-@SED@}"
alias mkdir="${MKDIR_P:-@MKDIR_P@}"
alias parallel="${PARALLEL:-@PARALLEL@}"

splitlevels=$1
test -n $splitlevels
Expand Down Expand Up @@ -67,7 +67,7 @@ sed -i -n -e '/^\[\^1\]: /,$p' $src

# Put footnotes in all files, renumber, and generally cleanup
function cleanup_split () {
alias sponge="@SPONGE@"
alias sponge="${SPONGE:-@SPONGE@}"
normalize_pandoc < $1 < $src | sponge $1
}
F=$(functions cleanup_split normalize_pandoc)
Expand Down
11 changes: 7 additions & 4 deletions scripts/split_mdbook_src.zsh.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ set -e
src=$1
dir=$2

alias pandoc="${PANDOC:-@PANDOC@}"
alias perl="${PERL:-@PERL@}"

echo -e "# Summary\n\n"

i=0
Expand All @@ -19,7 +22,7 @@ while read line; do
unset title slug
# Check for chapter header
if [[ $line =~ "^##? " ]]; then
@PANDOC@ --to=plain-smart <<< "$line" |
pandoc --to=plain-smart <<< "$line" |
read title
if [[ $line =~ "^# " ]]; then
[[ $line =~ "\.unnumbered\b" ]] || let i=$i+1
Expand All @@ -30,16 +33,16 @@ while read line; do
echo -n " "
fi
# https://github.com/jgm/pandoc/issues/8003
@PANDOC@ -f markdown+ascii_identifiers -t markdown-auto_identifiers <<< "# ${title//ı/i}" |
@PERL@ -pne 's/^.*{.*#([-\w]+).*}/\1/' |
pandoc -f markdown+ascii_identifiers -t markdown-auto_identifiers <<< "# ${title//ı/i}" |
perl -pne 's/^.*{.*#([-\w]+).*}/\1/' |
read slug
test -n "$slug"
of="$(printf %02d $i)${j:+$(printf .%03d $j)}-$slug.md"
trunc $dir/$of
[[ $line =~ "\.unnumbered\b" ]] || echo -n "- "
echo "[$title](./$of)"
# Strip attrs we *used* via commonmark_x for our own use from markup going to mdbook
@PANDOC@ --to=commonmark-smart <<< "$line" |
pandoc --to=commonmark-smart <<< "$line" |
read line
fi
>> $dir/$of <<< $line
Expand Down
43 changes: 29 additions & 14 deletions scripts/stats.zsh.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,69 @@

CASILEDIR=$(cd "$(dirname $0)/../" && pwd)

alias date="${DATE:-@DATE@}"
alias perl="${PERL:-@PERL@}"

basename="$1"
: ${2:=2}
let months=$2-1

. ${CASILEDIR}/functions.zsh

function list_sources () {
@GIT@ ls-files |
@PCREGREP@ "$basename.*(md|yml)"
alias git="${GIT:-@GIT@}"
alias pcregrep="${PCREGREP:-@PCREGREP@}"
git ls-files |
pcregrep "$basename.*(md|yml)"
}

function list_authors () {
alias git="${GIT:-@GIT@}"
alias sort="${SORT:-@SORT@}"
alias xargs="${XARGS:-@XARGS@}"
list_sources $1 |
@XARGS@ -n1 @GIT@ log --format=%aN --follow -- |
@SORT@ -u
xargs -n1 git log --format=%aN --follow -- |
sort -u
}

function list_commits () {
alias cut="${CUT:-@CUT@}"
alias git="${GIT:-@GIT@}"
alias sort="${SORT:-@SORT@}"
alias xargs="${XARGS:-@XARGS@}"
basename=$1
month=$2
author=$3
list_sources $basename |
@XARGS@ -n1 @GIT@ log --format='%at|%h|%s|%an' --follow --find-renames -- |
xargs -n1 git log --format='%at|%h|%s|%an' --follow --find-renames -- |
while IFS='|' read at sha1 msg aut; do
inrange $month $at || continue
[[ $aut == $author ]] || continue
echo $at $sha1
done |
@SORT@ -u |
@CUT@ -d\ -f2
sort -u |
cut -d\ -f2
}

function calculate_affected () {
alias git="${GIT:-@GIT@}"
alias pcregrep="${PCREGREP:-@PCREGREP@}"
sha1=$1
basename=$2
before=0 beforew=0
after=0 afterw=0
@GIT@ diff-tree --no-commit-id --name-only -r $sha1 |
@PCREGREP@ "$basename.*(md|yml)" |
git diff-tree --no-commit-id --name-only -r $sha1 |
pcregrep "$basename.*(md|yml)" |
while read file; do
let after="$after + $(@GIT@ show "$sha1:$file" 2>&- | countchars)"
let before="$before + $(@GIT@ show "$sha1^:$file" 2>&- | countchars)"
let after="$after + $(git show "$sha1:$file" 2>&- | countchars)"
let before="$before + $(git show "$sha1^:$file" 2>&- | countchars)"
done
change=$(($after-$before))
echo $after $change
}

function inrange () {
alias date="${DATE:-@DATE@}"
month=$1
at=$2
since=$(date --date "$cyclestart - $month months" "+%F")
Expand All @@ -71,7 +86,7 @@ echo "ÇEVİRİ VE EDİTÖRLÜK RAPÖRÜ: $basename"
echo "(Son hali $(itemwords $basename) kelime)"

cyclestart=$(date "+%Y-%m-1")
rootstart=$(@GIT@ log --format=%at | @SORT@ -n | head -n1)
rootstart=$(git log --format=%at | sort -n | head -n1)
list_authors $basename |
while read author; do
let usertotal=0
Expand All @@ -91,8 +106,8 @@ list_authors $basename |
[[ $change -ge 0 ]] || continue
let monthtotal=$monthtotal+$change
# git log -1 --date="format:%m-%d %H:%M" --format="%ad (%h) %s" $sha1
echo "Karakter: $(printf %8d $after) [$(printf %+8d $change)]" “$(@GIT@ log -1 --format="%s" $sha1 |
@PERL@ -pe 's/(?<=.{39}).{1,}$/…/')”
echo "Karakter: $(printf %8d $after) [$(printf %+8d $change)]" “$(git log -1 --format="%s" $sha1 |
perl -pe 's/(?<=.{39}).{1,}$/…/')”
done
let usertotal=$usertotal+$monthtotal
done
Expand Down
Loading

0 comments on commit 3279586

Please sign in to comment.