Add branchname and jira scripts, update nvimrc

This commit is contained in:
Rob Watson 2021-07-20 09:52:24 +02:00
parent c76f2ca656
commit 1aad7008c7
5 changed files with 71 additions and 13 deletions

View File

@ -25,7 +25,7 @@
drb = !git diff $(git rb) drb = !git diff $(git rb)
ds = diff --staged ds = diff --staged
f = fetch f = fetch
fixom = rebase -i --autosquash origin/master fixom = !sh -c 'git fetch && git rebase -i --autosquash origin/master'
fixup = rebase -i --autosquash fixup = rebase -i --autosquash
l = log l = log
ll = log --oneline -n 5 ll = log --oneline -n 5
@ -47,7 +47,7 @@
rc = rebase --continue rc = rebase --continue
re = rebase re = rebase
rh = reset --hard rh = reset --hard
rom = rebase origin/master rom = !sh -c 'git fetch && git rebase origin/master'
rr = !git reset --hard $(git rb) rr = !git reset --hard $(git rb)
s = status s = status
shp = show -p shp = show -p

22
nvimrc
View File

@ -140,6 +140,7 @@ nnoremap <leader>m :marks<cr>
nnoremap <leader>v :vsplit<cr> nnoremap <leader>v :vsplit<cr>
nnoremap <leader>s :split<cr> nnoremap <leader>s :split<cr>
nnoremap <leader>rp "_dd<bar>P nnoremap <leader>rp "_dd<bar>P
nnoremap <leader>dq ggVG"_d:wq<cr>
lua <<EOF lua <<EOF
function _G.dump(...) function _G.dump(...)
@ -150,6 +151,12 @@ end
function _G.insert_uuid() function _G.insert_uuid()
local uuid = vim.call("system", "uuidprint") local uuid = vim.call("system", "uuidprint")
local errcode = vim.v.shell_error
if errcode ~= 0 then
vim.api.nvim_err_writeln("uuidprint returned error code: " .. errcode)
return
end
vim.call("setreg", "u", uuid) vim.call("setreg", "u", uuid)
vim.api.nvim_command([[normal! "up]]) vim.api.nvim_command([[normal! "up]])
end end
@ -157,6 +164,21 @@ end
vim.api.nvim_set_keymap("n", "<leader>uu", [[:lua _G.insert_uuid()<cr>]], {noremap = true, silent = true}) vim.api.nvim_set_keymap("n", "<leader>uu", [[:lua _G.insert_uuid()<cr>]], {noremap = true, silent = true})
vim.api.nvim_set_keymap("i", "<c-d><c-u>", [[<esc>:lua _G.insert_uuid()<cr>a]], {noremap = true, silent = true}) vim.api.nvim_set_keymap("i", "<c-d><c-u>", [[<esc>:lua _G.insert_uuid()<cr>a]], {noremap = true, silent = true})
function _G.insert_jira_url()
local url = vim.call("system", "jira")
local errcode = vim.v.shell_error
if errcode ~= 0 then
vim.api.nvim_err_writeln("jira returned error code: " .. errcode)
return
end
vim.call("setreg", "u", url)
vim.api.nvim_command([[normal! "up]])
end
vim.api.nvim_set_keymap("n", "<leader>ji", [[:lua _G.insert_jira_url()<cr>]], {noremap = true, silent = true})
vim.api.nvim_set_keymap("i", "<c-d><c-j>", [[<esc>:lua _G.insert_jira_url()<cr>a]], {noremap = true, silent = true})
_G._test_cmd_to_wins = {} _G._test_cmd_to_wins = {}
_G._build_test_cmd = function() _G._build_test_cmd = function()

24
script/branchname Executable file
View File

@ -0,0 +1,24 @@
#!/usr/bin/env bash
#
# branchname - print current branchname, including during rebase
#
# https://stackoverflow.com/questions/34213120/find-branch-name-during-git-rebase
set -e
branchname=$(git bn)
if [ "$branchname" = "HEAD" ]; then
branchoutput=$(git branch --list | grep rebasing)
if [ ! $? -eq 0 ]; then
exit 1
fi
regex="rebasing ([^)]+)\)"
if [[ $branchoutput =~ $regex ]]; then
branchname="${BASH_REMATCH[1]}"
else
exit 2
fi
fi
printf $branchname

View File

@ -4,7 +4,7 @@
set -e set -e
if [ "$1" == "-s" ]; then if [ "$1" = "-s" ]; then
args="--short" args="--short"
fi fi

View File

@ -9,7 +9,12 @@ if [ -z "$JIRADOMAIN" ]; then
exit 1 exit 1
fi fi
branchname="$(git bn)" branchname="$(branchname)"
if [ ! $? -eq 0 ]; then
echo "branchname returned exit code: $?"
exit 1
fi
if ! echo "$branchname" | grep -q "/"; then if ! echo "$branchname" | grep -q "/"; then
echo "no ticket number found in branch name: $branchname" echo "no ticket number found in branch name: $branchname"
exit 1 exit 1
@ -17,10 +22,17 @@ fi
ticket=$(echo "$branchname" | cut -d "/" -f1 | tr '[:lower:]' '[:upper:]') ticket=$(echo "$branchname" | cut -d "/" -f1 | tr '[:lower:]' '[:upper:]')
url="$JIRADOMAIN/browse/$ticket"
if [ "$1" == "-b" ]; then
if [ $(uname -s) = "Linux" ]; then if [ $(uname -s) = "Linux" ]; then
progname="xdg-open" progname="xdg-open"
else else
progname="open" # macOS progname="open" # macOS
fi fi
eval "$progname $JIRADOMAIN/browse/$ticket" eval "$progname $url"
exit $?
fi
printf $url