dlvhdr / gh-dash

A beautiful CLI dashboard for GitHub šŸš€
https://dlvhdr.github.io/gh-dash
MIT License
7.25k stars 217 forks source link

A script directory collections for the repo ? #296

Open Sanix-Darker opened 1 year ago

Sanix-Darker commented 1 year ago

Hey there, this is an amazing project and am a big fan of it already !

Concerning this issue, it's not really a feature request, i was just wondering if it could not be a good idea to add to the repo, a scripts directory where everyone can share some nice custom script in it ! i have some "fun" scripts on my dotfiles for git stuffs, such as browsing for commits from a branch. Usualy, this help me see what have been done on a branch from a repo !

And I mixed it with a custom branch of this repo. In my ~/.config/gh-dash/config.yml :

keybindings:
  issues: []
  prs:
    - key: d
      command: >
        cd {{.RepoPath}} &&
        git checkout {{.HeadRefName}} &&
        git changes # which is a git alias

git changes calls these bash scripts functions :

#!/bin/bash

# for all git + fzf commands
GIT_FZF_DEFAULT_OPTS="
    $FZF_DEFAULT_OPTS
    --ansi
    --reverse
    --height=100%
    --bind shift-down:preview-down
    --bind shift-up:preview-up
    --bind pgdn:preview-page-down
    --bind pgup:preview-page-up
    --bind q:abort
    $GIT_FZF_DEFAULT_OPTS
"

git-fuzzy-log ()
{
    PREVIEW_COMMAND='f() {
        set -- $(echo -- "$@" | grep -o "[a-f0-9]\{7\}")
        [ $# -eq 0 ] || (
            git show --no-patch --color=always $1
            echo
            git show --stat --format="" --color=always $1 |
            while read line; do
                tput dim
                echo " $line" | sed "s/\x1B\[m/\x1B\[2m/g"
                tput sgr0
            done |
            tac | sed "1 a \ " | tac
        )
    }; f {}'

    ENTER_COMMAND='(grep -o "[a-f0-9]\{7\}" | head -1 |
        xargs -I % bash -ic "git-fuzzy-diff %^1 %") <<- "FZF-EOF"
        {}
        FZF-EOF'

    git log --graph --color=always --format="%C(auto)%h %s%d " | \
        fzf ${GIT_FZF_DEFAULT_OPTS} --no-sort --tiebreak=index \
        --preview "${PREVIEW_COMMAND}" --preview-window=top:15 \
        --bind "enter:execute:${ENTER_COMMAND}"
}

git-changes ()
{
    PREVIEW_COMMAND='f() {
        set -- $(echo -- "$@" | grep -o "[a-f0-9]\{7\}")
        [ $# -eq 0 ] || (
            git show --no-patch --color=always $1
            echo
            git show --stat --format="" --color=always $1 |
            while read line; do
                tput dim
                echo " $line" | sed "s/\x1B\[ m/\x1B\[2m/g"
                tput sgr0
            done |
            tac | sed "1 a \ " | tac
        )
    }; f {}'

    ENTER_COMMAND='(grep -o "[a-f0-9]\{7\}" | head -1 |
        xargs -I % bash -ic "git-fuzzy-diff %^1 %") <<- "FZF-EOF"
        {}
        FZF-EOF'

    git log origin..HEAD --no-merges  --graph --color=always --format="%C(auto)%h %s%d " | \
        fzf ${GIT_FZF_DEFAULT_OPTS} --no-sort --tiebreak=index \
        --preview "${PREVIEW_COMMAND}" --preview-window=top:15 \
        --bind "enter:execute:${ENTER_COMMAND}"
}

And with that I can :

DEMO

demo3

dlvhdr commented 1 year ago

These are awesome scripts :) Thanks for sharing. Are you aware of any projects that include something similar like this scripts folder you're suggesting? I'm wondering what's the best way to include those. If it's a really popular behavior, it can be integrated straight into gh-dash, in Go rather than in bash. I could link to a list of popular scripts, like the ones in your dotfiles etc.

Sanix-Darker commented 1 year ago

Are you aware of any projects that include something similar like this scripts folder you're suggesting?

Mhh, actually no šŸ˜„ , I was just proposing it as a "thing" for the community to share some nice script that can do multiple kind of things.

in Go rather than in bash

Totally agree too, for this specific behaviour of listing commits from a branch on a repo, and see what's inside, I can take the issue I try something.

I could link to a list of popular scripts, like the ones in your dotfile

yeah, on this repo or another specific repo like gh-dash-scripts for the community to share some interesting key-bindings scripts for PRs and issues, I think it could be great.