Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A script directory collections for the repo ? #296

Open
Sanix-Darker opened this issue Jul 22, 2023 · 2 comments
Open

A script directory collections for the repo ? #296

Sanix-Darker opened this issue Jul 22, 2023 · 2 comments

Comments

@Sanix-Darker
Copy link
Contributor

Sanix-Darker commented Jul 22, 2023

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 :

  • browse/search commits title from a branch .
  • browse/search files changed from that branch.
  • browse changes for those files.

DEMO

demo3

@Sanix-Darker Sanix-Darker changed the title A script collections ? + an update on executeCustomScript. A script directory collections for the repo ? Jul 23, 2023
@dlvhdr
Copy link
Owner

dlvhdr commented Jul 23, 2023

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
Copy link
Contributor Author

Sanix-Darker commented Jul 23, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants