Skip to content
NightMachinary edited this page Mar 31, 2020 · 2 revisions

Interop between vcsh and other git tools

asciicast

Put these in your .zshrc:

gq () {
    # Use this to control quoting centrally.
    print -r -- "${(q+@)@}"
}
reval () {
    eval "$(gq "$@")"
}
fnrep() {
    # 'Replaces a function temporarily during <cmd>: <fn> <new body> <cmd>'
    local fn="$1"
    local body="$2"
    local cmd=( "${@[3,-1]}" )
    local origbody
    origbody=$functions[$fn] || $origbody=''
    trap false INT TERM
    functions[$fn]=$body
    reval "${cmd[@]}"
    local e=$?
    test -n "$origbody" && functions[$fn]="$origbody" || unfunction $fn
    trap - INT TERM
    return $e
}
fnrepvc() {
    fnrep git "vcsh $1"' "$@"' "${@[2,-1]}"
}

Now you can use any command that expects git with vcsh. For example, this is a command that lists the blobs in the repo's history:

git-listblobs () {
    git rev-list --objects --all | git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' | sed -n 's/^blob //p' | sort --numeric-sort --key=2 | cut -c 1-12,41- | $(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest
}

We can now use this with vcsh:

fnrepvc VCSH_REPO_NAME_HERE git-listblobs

And it doesn't pollute the original git in our environment!

Clone this wiki locally