dotfiles

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

commit 872ab7eb62b8335bb49ebbfd4cb515d0b581dbd0
parent e0cb5605c9fffd6f1fe1911b063555dd3138da69
Author: Dash Eclipse <dash@ezup.dev>
Date:   Wed, 14 Oct 2020 17:35:41 +0000

Add fv

Remove fzgit

Diffstat:
A.local/bin/fv | 71+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
D.local/bin/fzgit | 39---------------------------------------
2 files changed, 71 insertions(+), 39 deletions(-)

diff --git a/.local/bin/fv b/.local/bin/fv @@ -0,0 +1,71 @@ +#!/bin/env sh +# +# fuzzy finder based File Viewer +# +: "${progname:="${0##*/}"}" +: "${WRKDIR:=./}" + +which sk bat fd >/dev/null || exit 1 + +fuzzy_git() { + local HEADER="[ENTER] Print [TAB] Toggle [ALT-F] View [ALT-H] Log [ALT-L] Log 1L" + local REPO=$(git -C "$WRKDIR" rev-parse --show-toplevel 2>/dev/null) #|| { echo "${WRKDIR} is not a git repo"; exit 1; } + git -C "$REPO" ls-tree --full-tree -r --name-only HEAD \ + | GREP_COLORS="sl=0;34;49:ms=0;37;49" grep --color=always '^\|[^/]*$' \ + | sk --ansi \ + --header="${HEADER} | $REPO" \ + --prompt "[git] > " \ + --layout=reverse-list \ + --preview="git -C \"${WRKDIR}\" show master:{1} | bat --color=always -p" \ + --preview-window=up:40% \ + -m \ + --bind "alt-f:execute[ git -C \"${REPO}\" show master:{} | bat -p --color=always --paging=always ]" \ + --bind "alt-l:execute[ git -C \"${REPO}\" log --oneline -- {} ]" \ + --bind "alt-h:execute[ git -C \"${REPO}\" log -p -- {} ]" \ + ${1:+--query "$@"} +} + +fuzzy_find() { + [ -d "$WRKDIR" ] || exit 0 + fd --type file --color=always . "$WRKDIR" \ + | sk \ + --ansi \ + --layout=reverse-list \ + --preview="bat --color=always --paging=always {}" \ + --preview-window=up \ + --prompt "$WRKDIR > " \ + --bind "alt-f:execute[ bat --color=always --paging=always {} ]" \ + ${1:+--query "$@"} +} + +usage() { + cat <<_EOF +Usage: $progname [options] + +Options: + -d <repo-dir> Set git repository to this directory + -f Force to use find instead of git + -h Show this page +_EOF + exit 0 +} + +while getopts "d:fh" opt; do + case $opt in + d) WRKDIR="$OPTARG";; + f) readonly FORCE_DIR=1;; + h) usage;; + *) usage;; + esac +done +shift $((OPTIND - 1)) + + +[ -d "$WRKDIR" ] || { echo "$WRKDIR: no such directory"; return 0; } +if [ "$FORCE_DIR" = 1 ]; then + fuzzy_find +elif git -C "$WRKDIR" rev-parse 2>/dev/null; then + fuzzy_git "$@" +else + fuzzy_find +fi diff --git a/.local/bin/fzgit b/.local/bin/fzgit @@ -1,39 +0,0 @@ -#!/bin/env sh -HEADER="[ENTER] Print selected [TAB] Toggle selection [ALT-F] View file [ALT-H] Commit log [ALT-L] Commit log (oneline)" -: "${progname:="${0##*/}"}" -: "${REPO:=./}" - -usage() { - cat <<_EOF -Usage: $progname [options] - -Options: - -r <repo-dir> Set git repository to this directory - -h Show this page -_EOF - exit 0 -} - -while getopts "r:h" opt; do - case $opt in - r) REPO="$OPTARG";; - h) usage;; - *) usage;; - esac -done -shift $((OPTIND - 1)) - -REPO_TL=$(git -C "$REPO" rev-parse --show-toplevel) || { echo "${REPO} is not a git repo"; exit 1; } -git -C "$REPO_TL" ls-tree --full-tree -r --name-only HEAD \ - | sk --inline-info \ - --header="${HEADER}" \ - --prompt "File name > " \ - --layout=reverse-list \ - --preview="git -C \"${REPO_TL}\" show master:{1}" \ - --preview-window=up:40% \ - -m \ - --bind "alt-f:execute[ git -C \"${REPO_TL}\" show master:{} ]" \ - --bind "alt-l:execute[ git -C \"${REPO_TL}\" log --oneline -- {} ]" \ - --bind "alt-h:execute[ git -C \"${REPO_TL}\" log -p -- {} ]" \ - ${1:+--query "$@"} -