Skip to content

Commit

Permalink
✨feat: vim-ghの設定を移動
Browse files Browse the repository at this point in the history
  • Loading branch information
utubo committed Nov 19, 2024
1 parent b32f7a2 commit 3445596
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 23 deletions.
36 changes: 36 additions & 0 deletions .vim/autoload/vimrc/gh.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
vim9script noclear
def A(a: any)
var p = str2nr($'{b:repo_list.param.page}')
if a ==# '+'
p += 1
elseif p < 2
return
else
p -= 1
endif
b:repo_list.param.page = $'{p}'
const c = printf(
'e gh://%s/repos?%s',
b:repo_list.owner,
gh#http#encode_param(b:repo_list.param)
)
gh#gh#delete_buffer(b:, 'gh_repo_list_bufid')
execute(c)
enddef
if !exists('*GhRepoListChangePage')
g:GhRepoListChangePage = (op: any) => {
A(op)
}
endif
export def ReposKeymap()
nn <buffer> i <ScriptCmd>execute 'edit!' ['gh:/', getline('.')->matchstr('\S\+'), 'issues']->join('/')<CR>
gh#map#add('gh-buffer-repo-list', 'nnoremap', '<C-h>', '<ScriptCmd>call g:GhRepoListChangePage("-")<CR>')
gh#map#add('gh-buffer-repo-list', 'nnoremap', '<C-l>', '<ScriptCmd>call g:GhRepoListChangePage("+")<CR>')
enddef
export def IssuesKeymap()
nn <buffer> <CR> <ScriptCmd>execute 'new' [expand('%'), getline('.')->matchstr('[0-9]\+'), 'comments']->join('/')<CR>
nn <buffer> r <ScriptCmd>execute 'edit!' expand('%:h:h') .. '/repos'<CR>
enddef
export def IssueCommentsKeymap()
nn <buffer> <CR> <ScriptCmd>execute 'bo vsplit' [expand('%'), getline('.')->matchstr('[0-9]\+')]->join('/')<CR><Cmd>setlocal wrap<CR>
enddef
15 changes: 4 additions & 11 deletions .vim/autoload/vimrc/lazyload.vim
Original file line number Diff line number Diff line change
Expand Up @@ -75,17 +75,10 @@ nn <Space>gd <Cmd>Gdiffsplit<CR>
nn <Space>gl <Cmd>Git pull<CR>
nn <Space>gt :<C-u>GitTagPush<Space>
nn <Space>gC :<C-u>Git checkout %
au vimrc FileType gh-repos {
nn <buffer> i <ScriptCmd>execute 'edit!' ['gh:/', getline('.')->matchstr('\S\+'), 'issues']->join('/')<CR>
}
au vimrc FileType gh-issues {
nn <buffer> <CR> <ScriptCmd>execute 'new' [expand('%'), getline('.')->matchstr('[0-9]\+'), 'comments']->join('/')<CR>
nn <buffer> r <ScriptCmd>execute 'edit!' expand('%:h:h') .. '/repos'<CR>
}
au vimrc FileType gh-issue-comments {
nn <buffer> <CR> <ScriptCmd>execute 'bo vsplit' [expand('%'), getline('.')->matchstr('[0-9]\+')]->join('/')<CR><Cmd>setlocal wrap<CR>
}
nn <Space>gh <Cmd>tabe gh://utubo/repos<CR>
nn <Space>gh <Cmd>e gh://utubo/repos<CR>
au vimrc FileType gh-repos vimrc#gh#ReposKeymap()
au vimrc FileType gh-issues vimrc#gh#IssuesKeymap()
au vimrc FileType gh-issue-comments vimrc#gh#IssueCommentsKeymap()
nn <F2> <Cmd>MRUToggle<CR>
g:MRU_Exclude_Files = has('win32') ? $'{$TEMP}\\.*' : '^/tmp/.*\|^/var/tmp/.*'
nn <Leader>a <Cmd>PortalAim<CR>
Expand Down
48 changes: 48 additions & 0 deletions src/.vim/autoload/vimrc/gh.src.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
vim9script noclear

# repos {{{
def GhRepoListChangePage(op: any)
var p = str2nr($'{b:repo_list.param.page}')
if op ==# '+'
p += 1
elseif p < 2
return
else
p -= 1
endif
b:repo_list.param.page = $'{p}'

const cmd = printf(
'e gh://%s/repos?%s',
b:repo_list.owner,
gh#http#encode_param(b:repo_list.param)
)
gh#gh#delete_buffer(b:, 'gh_repo_list_bufid')
execute(cmd)
enddef
if !exists('*GhRepoListChangePage')
g:GhRepoListChangePage = (op: any) => {
GhRepoListChangePage(op)
}
endif

export def ReposKeymap()
nnoremap <buffer> i <ScriptCmd>execute 'edit!' ['gh:/', getline('.')->matchstr('\S\+'), 'issues']->join('/')<CR>
gh#map#add('gh-buffer-repo-list', 'nnoremap', '<C-h>', '<ScriptCmd>call g:GhRepoListChangePage("-")<CR>')
gh#map#add('gh-buffer-repo-list', 'nnoremap', '<C-l>', '<ScriptCmd>call g:GhRepoListChangePage("+")<CR>')
enddef
# }}}

# issues {{{
export def IssuesKeymap()
nnoremap <buffer> <CR> <ScriptCmd>execute 'new' [expand('%'), getline('.')->matchstr('[0-9]\+'), 'comments']->join('/')<CR>
nnoremap <buffer> r <ScriptCmd>execute 'edit!' expand('%:h:h') .. '/repos'<CR>
enddef
# }}}

# issue-comments {{{
export def IssueCommentsKeymap()
nnoremap <buffer> <CR> <ScriptCmd>execute 'bo vsplit' [expand('%'), getline('.')->matchstr('[0-9]\+')]->join('/')<CR><Cmd>setlocal wrap<CR>
enddef
# }}}
#
16 changes: 4 additions & 12 deletions src/.vim/autoload/vimrc/lazyload.src.vim
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,10 @@ nnoremap <Space>gC :<C-u>Git checkout %
#}}}

# gh {{{
# ftpluginにすると定義がバラバラになって見通し悪くなるかな
au vimrc FileType gh-repos {
nnoremap <buffer> i <ScriptCmd>execute 'edit!' ['gh:/', getline('.')->matchstr('\S\+'), 'issues']->join('/')<CR>
}
au vimrc FileType gh-issues {
nnoremap <buffer> <CR> <ScriptCmd>execute 'new' [expand('%'), getline('.')->matchstr('[0-9]\+'), 'comments']->join('/')<CR>
nnoremap <buffer> r <ScriptCmd>execute 'edit!' expand('%:h:h') .. '/repos'<CR>
}
au vimrc FileType gh-issue-comments {
nnoremap <buffer> <CR> <ScriptCmd>execute 'bo vsplit' [expand('%'), getline('.')->matchstr('[0-9]\+')]->join('/')<CR><Cmd>setlocal wrap<CR>
}
nnoremap <Space>gh <Cmd>tabe gh://utubo/repos<CR>
nnoremap <Space>gh <Cmd>e gh://utubo/repos<CR>
au vimrc FileType gh-repos vimrc#gh#ReposKeymap()
au vimrc FileType gh-issues vimrc#gh#IssuesKeymap()
au vimrc FileType gh-issue-comments vimrc#gh#IssueCommentsKeymap()
# }}}

# MRU {{{
Expand Down

0 comments on commit 3445596

Please sign in to comment.