feat: git prs|actions aliases + lazygit integration

This commit is contained in:
2024-05-20 13:04:21 +03:00
parent f19b88b49d
commit 9f96f5519d
3 changed files with 166 additions and 14 deletions

View File

@@ -241,7 +241,22 @@ keybinding:
os:
openLink: open "$(echo "{{link}}" | sed 's/\[/\%5B/g; s/\]/\%5D/g')"
disableStartupPopups: false
customCommands: []
customCommands:
- key: 'B'
context: 'localBranches'
prompts:
- type: 'menu'
title: 'Choose an action'
key: 'action'
options:
- name: 'Pull Requests'
description: 'Open pull requests'
value: 'pull_requests'
- name: 'Pipelines'
description: 'Open pipelines'
value: 'pipelines'
command: 'git {{.Form.action}} {{.SelectedLocalBranch.Name}}'
loadingText: 'Opening...'
services: {}
notARepository: prompt
promptToReturnFromSubprocess: false

View File

@@ -45,8 +45,18 @@ if ! gpg --list-keys | grep -q "$GITHUB_GPG_KEY_ID"; then
curl https://github.com/web-flow.gpg | gpg --import
fi
git config --global user.name "Chen Asraf"
git config --global user.email "casraf@pm.me"
if [[ -z $(git config --global user.name) ]]; then
echo_cyan "Enter your name:"
read name
git config --global user.name "$name"
fi
if [[ -z $(git config --global user.email) ]]; then
echo_cyan "Enter your email:"
read email
git config --global user.email "$email"
fi
git config --global user.signingkey "~/.ssh/id_casraf.pub"
git config --global filter.lfs.clean "git-lfs clean -- %f"
git config --global filter.lfs.smudge "git-lfs smudge -- %f"
@@ -61,6 +71,9 @@ git config --global core.excludesfile "~/.config/.gitignore"
git config --global alias.unchanged "update-index --assume-unchanged"
git config --global alias.changed "update-index --no-assume-unchanged"
git config --global alias.show-unchanged "!git ls-files -v | sed -e 's/^[a-z] //p; d'"
git config --global alias.prs "!source $DOTFILES/plugins/git_custom_commands.plugin.zsh prs"
git config --global alias.pipelines "!source $DOTFILES/plugins/git_custom_commands.plugin.zsh pipelines"
git config --global alias.actions "!source $DOTFILES/plugins/git_custom_commands.plugin.zsh pipelines"
git config --global rerere.enabled true
git config --global gpg.format "ssh"
git config --global gpg.ssh.allowedSignersFile "~/.ssh/allowed_signers"
@@ -91,17 +104,6 @@ if [[ -z $existing_pager ]]; then
git config --global diff.colorMoved default
fi
if [[ -z $(git config --global user.name) ]]; then
echo_cyan "Enter your name:"
read name
git config --global user.name "$name"
fi
if [[ -z $(git config --global user.email) ]]; then
echo_cyan "Enter your email:"
read email
git config --global user.email "$email"
fi
echo_yellow "Installing binaries..."

View File

@@ -0,0 +1,135 @@
git_get_remote() {
remote=$(git remote -v | grep "(push)" | awk '{print $2}')
echo $remote
}
git_get_repo_path() {
repo_path=''
if [[ $remote =~ ^git@ ]]; then
repo_path=$(echo "$remote" | sed -E 's/^git@[^:]+:([^\.]+)\.git$/\1/')
elif [[ $remote =~ ^https?:// ]]; then
repo_path=$(echo "$remote" | sed -E 's|^https?://[^/]+/([^\.]+)\.git$|\1|')
fi
echo $repo_path
}
git_get_remote_type() {
remote=$(git_get_remote)
url_pathname=$(echo $remote | sed 's/.*:\/\/[^\/]*\//\//')
remote_type='github'
case $remote in
*github.com*)
remote_type='github'
;;
*gitlab.com*)
remote_type='gitlab'
;;
*bitbucket.org*)
remote_type='bitbucket'
;;
*)
return 1
;;
esac
echo $remote_type
return 0
}
git_open_pr_list() {
# branch=$1
# if [[ -z $branch ]]; then
# branch=$(git branch --show-current)
# fi
remote=$(git_get_remote)
if [[ -z $remote ]]; then
echo "No remote found"
return 1
fi
remote_type=$(git_get_remote_type)
if [[ -z $remote_type ]]; then
echo "Unknown remote type"
return 1
fi
repo_path=$(git_get_repo_path)
case $remote_type in
github)
# open "https://github.com/$repo_path/pulls?q=is%3Apr+is%3Aopen+head%3A$branch"
open "https://github.com/$repo_path/pulls?q=is%3Apr+is%3Aopen"
;;
gitlab)
# open "https://gitlab.com/$repo_path/merge_requests?scope=all&state=opened&search=$branch"
open "https://gitlab.com/$repo_path/merge_requests?scope=all&state=opened"
;;
bitbucket)
# open "https://bitbucket.org/$repo_path/pull-requests?state=OPEN&source=$branch"
open "https://bitbucket.org/$repo_path/pull-requests?state=OPEN"
;;
*)
echo "Unknown remote type: $remote_type"
return 2
;;
esac
return 0
}
git_open_pipelines() {
branch=$1
if [[ -z $branch ]]; then
branch=$(git branch --show-current)
fi
remote=$(git_get_remote)
if [[ -z $remote ]]; then
echo "No remote found"
return 1
fi
remote_type=$(git_get_remote_type)
if [[ -z $remote_type ]]; then
echo "Unknown remote type"
return 1
fi
repo_path=$(git_get_repo_path)
case $remote_type in
github)
# open "https://github.com/$repo_path/actions?query=branch%3A$branch"
open "https://github.com/$repo_path/actions"
;;
gitlab)
# open "https://gitlab.com/$repo_path/pipelines?scope=all&ref=$branch"
open "https://gitlab.com/$repo_path/pipelines?scope=all"
;;
bitbucket)
# open "https://bitbucket.org/$repo_path/addon/pipelines/home#!/results/$branch"
open "https://bitbucket.org/$repo_path/addon/pipelines/home"
;;
esac
return 0
}
if [[ ! -z $1 ]]; then
case $1 in
pr|prs)
shift
git_open_pr_list $@
;;
actions|pipelines)
shift
git_open_pipelines $@
;;
*)
echo "Unknown command: $1"
return 1
;;
esac
fi