Skip to content

Commit

Permalink
Merge pull request #11 from gennaro-tedesco/tags_fun
Browse files Browse the repository at this point in the history
tags fun
  • Loading branch information
Gennaro Tedesco authored Feb 16, 2022
2 parents c649e2f + c10683d commit f41079e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ takes one of the following arguments or flags
| -p,prs | view, diff and checkout PR | enter: checkout selected PR<br>ctrl-d: diff selected PR<br>ctrl-v: view selected PR
| -b,branches | checkout and diff branches | enter: checkout selected branch<br>ctrl-d: diff selected branch<br>ctrl-x: delete selected branch
| -l,logs | select commits and show diff | enter: show selected commit diff
| -t,tags | checkout and diff version tags | enter: checkout tag in detached HEAD<br>ctrl-d diff against current branch
| -s,search | search issues in any repository | interactive prompt: follow instructions
| -m,myissue | search issues you opened somewhere | interactive prompt: follow instructions
| -k,pick | cherrypick files between branches | enter: checkout cherrypicked files from branch
Expand All @@ -64,7 +65,8 @@ Most commands follow the semantics of `git` standard instructions (so that you c
## Customisation
If you want to skip typing `gh f` before each command you may alias it directly, for instance
```
gh set alias prs --shell `gh f -p`
gh set alias prs `f -p` # show PRs
gh set alias l `f -l` # show git logs
```
and likewise for the rest.

Expand Down
34 changes: 34 additions & 0 deletions gh-f
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ COMMANDS
-p|prs: view, diff and checkout PR
-b|branches: checkout and diff branches
-l|logs: select commits and show diff
-t|tags: checkout and diff version tags
-s|search: search issues in any repository
-m|myissue: search issues you opened somewhere
-k|pick: cherrypick files from one branch to the other
Expand Down Expand Up @@ -55,6 +56,11 @@ USAGE
file paths can be passed as positional arguments
enter: show selected commit diff
gh f -t | gh f tags
enter: checkout the tag in detached HEAD state
ctrl-d: diff the tag against current branch
gh f -s | gh f search
prompt for repository name and issue title
Expand Down Expand Up @@ -203,6 +209,30 @@ logs() {
[[ -n ${commit} ]] && cut -f1 -d' ' <<<"$commit" | xargs -n1 git show
}

tags() {
if ! is_git_repo; then {
echo "not a git repo"
exit
}; fi
lines="$(
git tag -l -n | awk -F' {2,}' -v ID_COLOUR="$ID_COLOUR" -v TEXT_COLOUR="$TEXT_COLOUR" -v SHELL_COLOUR="$SHELL_COLOUR" '{print ID_COLOUR $1 SHELL_COLOUR" - " TEXT_COLOUR $2}' |
fzf \
--exit-0 \
--ansi --delimiter=- \
--prompt="tags:" \
--preview="GH_FORCE_TTY=$FZF_PREVIEW_COLUMNS git diff --stat --color=always {1} 2>/dev/null" \
--expect="enter,ctrl-d"
)"

key="$(head -1 <<<"$lines")"
tag="$(sed 1d <<<"$lines" | cut -d '-' -f1 | tr -d ' ')"

case "$key" in
enter) git checkout tags/"$tag" ;;
ctrl-d) git diff "$tag" ;;
esac
}

search() {
read -rp "repository name: " repo
[[ -z $repo ]] && exit
Expand Down Expand Up @@ -290,6 +320,10 @@ while [[ "$#" -gt 0 ]]; do
logs "$@"
shift
;;
-t | tags)
tags
shift
;;
-s | search)
search
shift
Expand Down

0 comments on commit f41079e

Please sign in to comment.