dotfiles

Dash Eclipse's dotfiles
git clone git://ezup.dev/dotfiles.git
Log | Files | Refs | README | LICENSE

stagit-viewer.sh (1863B)


      1#!/bin/sh
      2
      3which fzf bat curl >/dev/null || exit 0
      4
      5view_raw_file() {
      6	echo "Fetching $(basename ${1})..."
      7	local HTML_RAW=$(curl --progress-bar "$1")
      8	echo "$HTML_RAW" \
      9		| sed -n 's|^<a href="#.*" class="line" id=".*">.*</a>||p' \
     10		| recode HTML_4.0..UTF-8 \
     11		| bat -n --paging=always
     12}
     13
     14view_file() {
     15	local HTML_FILE=$(curl --progress-bar "$1")
     16	local LIST_FILE=$(echo "$HTML_FILE" | sed -n 's|^<tr><td>.*</td><td><a href=".*">\(.*\)</a></td><td class="num" align="right">.*</td></tr>$|\1|p')
     17	local HOMEPAGE=$(echo "$1" | sed 's/files.html$//')
     18	while true; do
     19		local FILE_PATH=$(echo "$LIST_FILE" | GREP_COLORS="sl=0;34;49:ms=0;37;49" grep --color=always '^\|[^/]*$' | fzf --ansi +s)
     20		[ -z "$FILE_PATH" ] && return 0
     21		view_raw_file ${HOMEPAGE}file/${FILE_PATH}.html
     22	done
     23}
     24
     25view_raw_commit() {
     26	echo "Fetching $(basename ${1})..."
     27	local TEXT=$(links -dump "$1" | sed 's/^ //' | sed -n '/^commit .*$/,$p')
     28	echo "$TEXT" | bat -nl diff --paging=always
     29}
     30
     31view_log() {
     32	local HOMEPAGE=$(echo "$1" | sed 's/log.html$//')
     33	local HTML_FILE=$(curl --progress-bar "$1")
     34	local LIST_LOG=$(echo "$HTML_FILE" | sed -n 's|^<tr><td>\(.*\)</td><td><a href="commit/\(.*\).html">\(.*\)</a></td><td>.*.*</td><td class="num" align="right">.*|\2  \1  \3|p')
     35	while true; do
     36		local COMMIT=$(echo "$LIST_LOG" | fzf +s | awk '{print $1}')
     37		[ -z "$COMMIT" ] && return 0
     38		view_raw_commit "${HOMEPAGE}commit/${COMMIT}.html"
     39	done
     40}
     41
     42[ -z "$1" ] && { printf "URL: "; read -r URL; } || URL=$1
     43
     44if	$(echo "$URL" | grep '^http.*/log.html$' >/dev/null);		then view_log "$URL"
     45elif	$(echo "$URL" | grep '^http.*/files.html$' >/dev/null);		then view_file "$URL"
     46elif	$(echo "$URL" | grep 'http.*/commit/.*.html$' >/dev/null);	then view_raw_commit "$URL"
     47elif	$(echo "$URL" | grep 'http.*/file/.*.html$' >/dev/null);	then view_raw_file "$URL"
     48else	echo "Invald URL"; return 0
     49fi