• 0 Posts
  • 3 Comments
Joined 3 years ago
cake
Cake day: June 15th, 2023

help-circle
  • You’re absolutely right. Here’s a slopcoded rewrite that does run a ton faster and doesn’t use git last-modified (which is labelled experimental but was kind of the original inspiration). I even got it to do relative filenames instead of the full path to the root of the repo which I had been wanting.

    cat .local/bin/git-slopblame

    #!/usr/bin/env bash
    # Show when <paths> were last committed, with date, author and commit title
    
    paths=("$@")
    if ((${#paths[@]} == 0)); then
        paths=(".")
    fi
    
    git log --format='@@@%h%x09%as%x09%an%x09%s' --relative --name-only -- "${paths[@]}" |
    awk '/^@@@/ {
            commit = substr($0, 4)
            next
        } length($0) && !seen[$0]++ {
            print commit "\t" $0
        }' |
    while IFS=$'\t' read -r hash date author subject file; do
        printf '%s:\033[34m%s\033[0m \033[32m%s\033[0m \033[34m%s:\033[0m%s\n' \
            "$hash" "$date" "$author" "$file" "$subject"
    done
    

  • cat .local/bin/git-lastblame

    #!/usr/bin/env bash
    #Show when <paths> were last committed, with date, author and commit title
    
    paths=("$@")
    if ((${#paths[@]} == 0)); then
        paths=(".")
    fi
    
    while IFS=$'\t' read -r hash file; do
      git log -n1 --pretty=format:"%h:%Cblue%as%Creset %Cgreen%an%Creset %Cblue$file:%Creset%s" --no-patch $hash
    done < <(git last-modified ${paths[@]})
    

    By default it will show all the files in your current directory. I like it to get an idea of of the lifecycle of one area of a project. Files will be listed ordered by most recent commit. Note that it’s not very fast so it’ll probably choke on big repos. Alias as g lb - press few key.