diff --git a/tree/.local/nu/git.nu b/tree/.local/nu/git.nu index 07deb7d..5ae55d3 100644 --- a/tree/.local/nu/git.nu +++ b/tree/.local/nu/git.nu @@ -18,3 +18,26 @@ def gitfixremote [ print $"Unknown host: ($parsed.host)" } } + +def "git sha" [ + --no-copy(-c), # don't copy to clipboard + --full(-f), # output the complete sha +]: nothing -> record { + mut sha = (git show -q | lines | parse "commit {sha}" | first); + + if ($sha | is-empty) { + return; + } + + $sha = $sha.sha + + if not $full { + $sha = ($sha | str substring 0..7) + } + + if not $no_copy { + $sha | pbc + } + + $sha +}