Skip to content

Instantly share code, notes, and snippets.

View maguroguma's full-sized avatar
🏠
Working from home

Masahiro Yokoyama maguroguma

🏠
Working from home
View GitHub Profile
# unique MRC(most recently checkouted, like MRU) checkouted branchs or commit hashs -> branch name or commit hash
_gm() {
is_in_git_repo || return
git --no-pager reflog | awk '$3 == "checkout:" && /moving from/ {print $8}' | uniq | \
awk '
BEGIN { memo[0]=""; results[0]=""; } { if(!($0 in memo))
{ memo[$0] = 1; results[length(results)] = $0; } }
END { for(i=1; i<length(results); i++) print results[i] }
' | \
fzf-down -m --preview 'git show --color=always {1}' --prompt="refs> "
@maguroguma
maguroguma / fzf-git-show.vim
Created October 16, 2022 12:38
print the selected revision of current buffer file (require fzf.vim and fugitive.vim)
" source
function! s:list_commits() abort
let l:res = system('git log --date=short --format="%C(green)%C(bold)%cd %C(auto)%h%d %s (%an)" --color=always')
return split(l:res, "\n")
endfunction
" sink
function! s:select_commits(commit_hash) abort
let l:list = split(a:commit_hash, ' ')
let l:execute_command = 'Git show ' . l:list[1] . ':%'
execute l:execute_command
" deletes buffers by fzf
" ref: https://github.com/junegunn/fzf.vim/pull/733#issuecomment-559720813
function! s:list_buffers_customized()
redir => list
silent ls
redir END
let l:res = []
let l:raw_lines = split(list, "\n")
for l:raw_line in raw_lines
@maguroguma
maguroguma / zsh-history.vim
Created October 16, 2022 12:27
filter command history from `.zhistory` to a buffer
" show zsh command history
if getftype(expand('$HOME') . '/.zhistory') != ""
function! s:showShellHistory(...)
execute 'botright' 10 'new'
setlocal nobuflisted bufhidden=unload buftype=nofile
silent read !cat $HOME/.zhistory | cut -b 16- | head -n 5000
if a:0 == 1
let l:exe_com = 'v/' . a:1 . '/d'
execute l:exe_com
endif
@maguroguma
maguroguma / trans.vim
Last active October 16, 2022 07:04
https://github.com/soimort/translate-shell を用いて単語レベルでサクッと意味を調べたい時用の和英・英和のvim wrapper
if executable('trans')
function! s:printToTempBuffer(exe_command)
execute 'botright' 10 'new'
setlocal nobuflisted bufhidden=unload buftype=nofile
execute a:exe_command
norm gg
setlocal nomodified
endfunction
function! s:engToJapa(arg)
@maguroguma
maguroguma / nkf.vim
Created October 16, 2022 06:30
行Visualで指定した範囲に対して `nkf -Z0` を適用(全角英数字・記号→半角に変換)を行う
if executable('nkf')
function! s:nkf(has_bang, ...) abort range
execute 'silent' a:firstline ',' a:lastline '!nkf -Z0'
endfunction
command! -bar -bang -range=% -nargs=? Nkf <line1>,<line2>call s:nkf(<bang>0, <f-args>)
endif
@maguroguma
maguroguma / open-pr-link.vim
Last active October 16, 2022 06:13
Make github PR search page link, copy it to clipboard, and open it by your default browser.
# TodoList
* [x] ボタンを押すとコーラが出る
* お金 100円 を入れてボタンを押すとコーラが出る。 100円以外は受け付けない。
* [x] 自販機の構造体を作る
* [x] コーラボタンを作る
* [x] 100円を入れる
* [x] 10円を入れる
* [x] 100円が入っているかどうかを判定する
* [x] 100円が入っている状態でボタンを押すとコーラが出る