dotfiles

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

commit 544d540befb1aae1a7a0aa35e330475b1185a939
parent 6993865d994ed7aea876aa0a18c9f640da2b5246
Author: Dash Eclipse <dash@ezup.dev>
Date:   Wed, 14 Oct 2020 23:35:09 +0000

Add stagit-viewer.sh

Diffstat:
A.local/bin/stagit-viewer.sh | 49+++++++++++++++++++++++++++++++++++++++++++++++++
M.zshrc.local | 2+-
2 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/.local/bin/stagit-viewer.sh b/.local/bin/stagit-viewer.sh @@ -0,0 +1,49 @@ +#!/bin/sh + +which fzf bat curl >/dev/null || exit 0 + +view_raw_file() { + echo "Fetching $(basename ${1})..." + local HTML_RAW=$(curl --progress-bar "$1") + echo "$HTML_RAW" \ + | sed -n 's|^<a href="#.*" class="line" id=".*">.*</a>||p' \ + | recode HTML_4.0..UTF-8 \ + | bat -n --paging=always +} + +view_file() { + local HTML_FILE=$(curl --progress-bar "$1") + 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') + local HOMEPAGE=$(echo "$1" | sed 's/files.html$//') + while true; do + local FILE_PATH=$(echo "$LIST_FILE" | GREP_COLORS="sl=0;34;49:ms=0;90;49" grep --color=always '^\|[^/]*$' | fzf --ansi +s) + [ -z "$FILE_PATH" ] && return 0 + view_raw_file ${HOMEPAGE}file/${FILE_PATH}.html + done +} + +view_raw_commit() { + echo "Fetching $(basename ${1})..." + local TEXT=$(links -dump "$1" | sed 's/^ //' | sed -n '/^commit .*$/,$p') + echo "$TEXT" | bat -nl diff --paging=always +} + +view_log() { + local HOMEPAGE=$(echo "$1" | sed 's/log.html$//') + local HTML_FILE=$(curl --progress-bar "$1") + 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') + while true; do + local COMMIT=$(echo "$LIST_LOG" | fzf +s | awk '{print $1}') + [ -z "$COMMIT" ] && return 0 + view_raw_commit "${HOMEPAGE}commit/${COMMIT}.html" + done +} + +[ -z "$1" ] && { printf "URL: "; read -r URL; } || URL=$1 + +if $(echo "$URL" | grep '^http.*/log.html$' >/dev/null); then view_log "$URL" +elif $(echo "$URL" | grep '^http.*/files.html$' >/dev/null); then view_file "$URL" +elif $(echo "$URL" | grep 'http.*/commit/.*.html$' >/dev/null); then view_raw_commit "$URL" +elif $(echo "$URL" | grep 'http.*/file/.*.html$' >/dev/null); then view_raw_file "$URL" +else echo "Invald URL"; return 0 +fi diff --git a/.zshrc.local b/.zshrc.local @@ -93,7 +93,7 @@ sgview() { && local URL=$(read -e "?URL: ") \ || local URL=$1 curl --progress-bar "$URL" \ - | sed -n 's|<a href="#.*" class="line" id=".*">.*</a>||p' \ + | sed -n 's|^<a href="#.*" class="line" id=".*">.*</a>||p' \ | recode html..ascii \ | bat -n }