dot

packages and services management
Log | Files | Refs | README

commit a866536bb592a831d66fcacd74ed93e52369ff8c
parent 4393a800228b4eb5e9b9602c7c1e6b56c285fd08
Author: Josuah Demangeon <mail@josuah.net>
Date:   Sun,  9 Apr 2017 16:55:44 +0200

Better, simpler www-git script

Diffstat:
M.profile | 4++--
Mbin/build | 3+--
Mbin/ii-client | 25+++++++++++--------------
Mbin/www-git | 167++++++++++++++++++++++++++++++++++++-------------------------------------------
Mbuild/dvtm | 4++--
Mdvtm/config.h | 2+-
Mman/www-git.1 | 22++++++++++++++--------
7 files changed, 107 insertions(+), 120 deletions(-)

diff --git a/.profile b/.profile @@ -18,7 +18,7 @@ export MAIL="$HOME/mail/INBOX" export NAME='Josuah Demangeon' EMAIL='mail@josuah.net' TZ='Europe/Paris' # default commands -export EDITOR='vis' VISUAL='vis' +export EDITOR='mg' VISUAL='mg' export PAGER='less' MANPAGER='less -R' DVTM_PAGER='less -R' export BROWSER='firefox' @@ -45,7 +45,7 @@ alias ..='cd ..' alias j='jobs' # iomenu -alias e='io-edit' +alias v='io-edit' alias a='io-abduco' alias r='io-run' alias f='find ! -path "*/.git/*" -type f | iomenu -l 255' diff --git a/bin/build b/bin/build @@ -45,9 +45,8 @@ info() } -# # Default build function, to be overriden in the build recipes scripts -# + build() { find "$CONFIG/$1" -name '*.diff' -exec patch -N -p 1 -i {} \; diff --git a/bin/ii-client b/bin/ii-client @@ -1,7 +1,6 @@ # wrapper script for ii irc client http://tools.suckless.org/ii -II_DIR="$HOME/.cache/irc" E="$(printf '\033')" @@ -22,7 +21,7 @@ key() case "$1" in ( [[:print:]] ) - printf %s "$key" >> input + printf %s "$key" >> "$INPUT" ;; ( "$(printf '\020')" | "$(printf '\016')" ) # Ctrl-P Ctrl-N @@ -33,20 +32,20 @@ key() ;; ( "$(printf '\015')" ) # Ctrl-M Enter - sed 's/$/\n/' input > in - printf '' > input + sed 's/$/\n/' "$INPUT" > in + printf '' > "$INPUT" ;; ( "$(printf '\025')" ) # Ctrl-U - printf '' > input + printf '' > "$INPUT" ;; ( "$(printf '\027')" ) # Ctrl-W - [ -f input ] && sed -i 's/[^ \t]* *$//' input + [ -f "$INPUT" ] && sed -i 's/[^ \t]* *$//' "$INPUT" ;; ( "$(printf '\010')" | "$(printf '\177')" ) # Ctrl-H Backspace - [ -f input ] && sed -i 's/.$//' input + [ -f "$INPUT" ] && sed -i 's/.$//' "$INPUT" ;; ( "$(printf '\014')" ) # Ctrl-L @@ -65,7 +64,7 @@ key() prompt() { - [ -f input ] && IFS='' read -r input < input + [ -f "$INPUT" ] && IFS='' read -r input < "$INPUT" size="$(stty -F /dev/tty size)" width="$((${#input} + 4 - ${size#* }))" @@ -97,10 +96,10 @@ print_screen() main() { - printf '' > input + INPUT="$(mktemp)" + print_screen - (tail -n 0 -f out & printf '%s\n' $! > pid) | ii-filter | while IFS='' read -r line do printf '\r\033[K%s\n' "$line" @@ -112,11 +111,9 @@ main() key "$key" || break done - read pid < pid - rm -f pid input - - kill -9 "$pid" stty sane + + rm "$INPUT" } diff --git a/bin/www-git b/bin/www-git @@ -1,41 +1,33 @@ # Static Git index generator inspired from git.2f30.org/stagit -# 1: path to the parent 1 -# 2: title of the page +#1 path to the root header() { printf '<!doctype html> -<html> -<head> -<meta charset="UTF-8" /> -<title>%s</title> +<html><head><meta charset="UTF-8" /><title>%s</title> <link rel="icon" type="image/png" href="%s/favicon.png" /> -<link rel="stylesheet" type="text/css" href="%s/git.css" /> +<link rel="stylesheet" type="text/css" href="%s/style.css" /> </head> -<body> -<h1>%s<span id="description">%s</span></h1> -' "$2" "$1" "$1" "$repo" "$desc" +<body><h1>%s <span id="description">%s</span></h1> +' "$NAME" "$1" "$1" "$NAME" "$DESC" } footer() { - printf '</body> -</html> -' + printf '</body>\n</html>\n' } -# 1: long hash of the commit +#1 long hash of the commit -commit() +git_commit() { - git show --format='<pre> + git -C "$REPO" show --format='<pre> <b>commit</b> <a href="%H.html">%H</a> -<b>parent</b> <a href="%P.html">%P</a> <b>author</b> %an &lt;<a href="mailto:%ae">%ae</a>&gt; <b>date</b> %aD @@ -61,120 +53,113 @@ commit() } -commits() +git_commits() { - mkdir -p "$pwd/$repo/commit" - - printf '<table>\n<thead>\n<tr>' - printf '<th>%s</th>' 'Date' 'Commit message' 'Author' - printf '</tr>\n</thead>\n<tbody>\n' - - f='<tr><td>%ad</td><td><a href="commit/%H.html">%s</a></td><td>%an</td></tr>' - git log --format="$f" --date='short' - - for hash in $(git log --format='%H') + printf ' +<table> +<thead><tr><th>Date</th><th>Commit message</th><th>Author</th></tr></thead> +<tbody> +' + git -C "$REPO" log --date='short' --format=' +<tr> + <td>%ad</td> + <td><a href="commit/%H.html">%s</a></td> + <td>%an</td> +</tr> +' + for hash in $(git -C "$REPO" log --format='%H') do { - header '../../..' "Commits - ${PWD##*/}" - commit "$hash" + header ../.. + + git_commit "$hash" + footer - } > "$pwd/$repo/commit/$hash.html" + } > "$NAME/commit/$hash.html" done - printf '\n</tbody>\n</table>\n' + printf '</tbody></table>\n' } -#1 file to display +#1 path of the file -file() +git_file() { - printf '<table id="file">\n<tr>\n<td>\n<pre id="num">\n' + printf '<table id="file"><tr><td><pre id="num">\n' - if grep -qI . "$1" 1>/dev/null + if grep -qI . "$REPO/$1" 1>/dev/null then - seq "$(wc -l < "$1")" | sed 's|.*|<a id="&" href="#&">&</a>|' - printf '</pre></td>\n<td><pre>\n' - sed 's|&|\&amp;|g; s|<|\&lt;|g' "$1" + seq "$(wc -l < "$REPO/$1")" | + sed 's|.*|<a id="&" href="#&">&</a>|' + + printf '</pre></td><td><pre>\n' + + sed 's|&|\&amp;|g; s|<|\&lt;|g' "$REPO/$1" else printf 'binary file' fi - printf '</pre></td></tr></table>' + printf '</pre></td></tr></table>\n' } -files() +git_files() { - mkdir -p "$pwd/$repo/file" - - printf '<table>\n<thead>\n<tr>' - printf '<th>%s</th>' 'Mode' 'Name' 'Size' - printf '</tr>\n</thead>\n<tbody>\n' + printf ' +<table> +<thead><tr><th>Mode</th><th>Name</th><th>Size</th></tr></thead> +<tbody> +' - git ls-files | while IFS='' read -r file + git -C "$REPO" ls-files | while IFS='' read -r file do - [ -z "${file##*/*}" ] && mkdir -p "$pwd/$repo/file/${file%/*}" + [ -z "${file##*/*}" ] && mkdir -p "$NAME/file/${file%/*}" { - header "../../$( + header "$( printf %s "$file" | sed 's|[^/]*||g; s|/|../|g' - ).." "$file - $repo" - file "$file" - footer - } > "$pwd/$repo/file/$file.html" - - printf '<tr>' - printf '<td>%s</td>' \ - "$(stat -c %A "$file")" \ - "<a href=\"file/$file.html\">$file</a>" \ - "$(wc -l < "$file")L" - printf '</tr>\n' - done - - printf '\n</tbody>\n</table>\n' + )../.." - [ -f 'README' ] && printf '<h2>README</h2>\n' && file 'README' -} + git_file "$file" + footer + } > "$NAME/file/$file.html" -repo() -{ - mkdir -p "$pwd/$repo/commit" + f='<tr><td>%s</td><td><a href="file/%s.html">%s</a></td></tr>' + printf "$f" "$(stat -c %A "$REPO/$file")" "$file" "$file" + done - { - header '../..' "$repo" - printf '<h2>Files</h2>\n' - files - printf '<h2>Commits</h2>\n' - commits - footer - } > "$pwd/$repo/index.html" + printf '</tbody>\n</table>\n' - printf '<tr>' - printf '<td><a href="git/%s">%s</a></td>' "$repo" "$repo" - printf '<td>%s</td>' "$desc" - printf '</tr>\n' + [ -f 'README' ] && printf '<h2>README</h2>\n' && file "$REPO" 'README' } -repos() +#1 path to repository +#2 description + +main() { - mkdir -p git && cd git || exit 1 + REPO="$1" NAME="${1##*/}" DESC="$2" - printf '<table>\n' + printf ' %s' "$NAME" 1>&2 - while read -r repo desc - do - printf ' %s' "$repo" 1>&2 + [ -d "$NAME" ] && rm -r "$NAME" + mkdir -p "$NAME/commit" "$NAME/file" - mkdir -p "$repo" + { + header .. - (pwd="$PWD"; cd "../$2/$repo" && repo) - done < "../$1" + printf '<h2>Files</h2>\n' + git_files - printf '</table>\n' + printf '<h2>Commits</h2>\n' + git_commits + + footer + } > "$NAME/index.html" } -repos "$@" +main "$@" diff --git a/build/dvtm b/build/dvtm @@ -5,7 +5,7 @@ tar=http://github.com/martanne/dvtm/archive/master.tar.gz build() { patch -Ni ~/.config/dvtm/dvtm-statusline.diff - cp ~/.config/dvtm/config.h config.h - cp ~/.config/dvtm/dvtm-status dvtm-status + cp "$CONFIG/dvtm/config.h" config.h + cp "$CONFIG/dvtm/dvtm-status" dvtm-status make PREFIX="$PREFIX" install } diff --git a/dvtm/config.h b/dvtm/config.h @@ -175,7 +175,7 @@ static KeyBinding bindings[] = { { { MOD, CTRL('L'), }, { redraw, { NULL } } }, { { MOD, 'r', }, { redraw, { NULL } } }, - { { MOD, MOD, }, { send, { (const char []){MOD, 0} } } }, + { { MOD, ' ', }, { send, { (const char []){MOD, 0} } } }, { { MOD, 'e', }, { copymode, { "dvtm-editor" } } }, { { MOD, 'E', }, { copymode, { "dvtm-pager" } } }, diff --git a/man/www-git.1 b/man/www-git.1 @@ -1,21 +1,27 @@ .Dd mar 23, 2017 .Dt WWW-GIT .Os -.. +. +. .Sh NAME -.. +. .Nm www-git .Nd generate static website with the git command -.. +. +. .Sh SYNOPSIS -.. +. .Nm -.. +.Ar descriptions +. .Sh DESCRIPTION -.. +. .Nm will create a .Pa git -subdirectory in current directory with one subdirectory per git repository. +subdirectory in current directory with one subdirectory per git +repository. Repositories are specified from the -.Pa description file . +.Ar description +file, with one line per repository, and the first word the name and the +rest the description.