Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
git-jumpを解放する / loosen editor dependency of git-jump
Search
Yoichi NAKAYAMA
February 13, 2023
Programming
0
1.2k
git-jumpを解放する / loosen editor dependency of git-jump
社内Lightning Talkの資料です
Yoichi NAKAYAMA
February 13, 2023
Tweet
Share
More Decks by Yoichi NAKAYAMA
See All by Yoichi NAKAYAMA
小さなOSS貢献の実践例 / A practical example of a small contribution to OSS
yoichi
0
97
ターミナル出力の色付け / Terminal output coloring
yoichi
0
110
パイプの話 / on pipe
yoichi
0
410
バイナリリーディング / Binary Reading
yoichi
0
280
OSS開発を楽しく続けてきた話
yoichi
0
720
Other Decks in Programming
See All in Programming
Android開発者のための Kotlin Multiplatform入門
ntaro
0
190
「2024年版 Kotlin サーバーサイドプログラミング実践開発」の補講 〜O/Rマッパー編〜
n_takehata
2
260
スクラムマスターって孤独じゃないですか?
yoshitaroyoyo
1
140
Advanced App Shrinking Techniques
cbeyls
2
150
Modern Angular: Renovation for Your Applications
manfredsteyer
PRO
0
140
Polarsの成長: v0.14からv1.0までの変遷と今後の展望
zerebom
1
350
Temporalを取り巻く仕様を整理する
sajikix
0
110
【Go言語】ジェネリクス
tomo1227
0
170
CSC307 Lecture 10
javiergs
PRO
0
310
リハビリmruby
kishima
1
160
CSC307 Lecture 05
javiergs
PRO
0
210
ドメイン駆動設計の実践
masuda220
PRO
19
5.2k
Featured
See All Featured
Producing Creativity
orderedlist
PRO
340
39k
Infographics Made Easy
chrislema
238
18k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
502
140k
Six Lessons from altMBA
skipperchong
24
3.2k
Ruby is Unlike a Banana
tanoku
96
10k
Robots, Beer and Maslow
schacon
PRO
157
8.1k
Done Done
chrislema
179
15k
The Invisible Side of Design
smashingmag
294
50k
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
90
47k
YesSQL, Process and Tooling at Scale
rocio
166
14k
The World Runs on Bad Software
bkeepers
PRO
63
11k
Atom: Resistance is Futile
akmur
261
25k
Transcript
git-jumpを解放する Yoichi Nakayama
gitのサブコマンド “git ほにゃらら [args…]” の「ほにゃらら」 どんなサブコマンドを知ってますか?
gitのサブコマンドいろいろ git のサブコマンドを作ったことがありますか? • git clone • git checkout •
git add • git commit • git branch • git tag • git log • git blame • git merge • git reset • git rebase • git status • git push • git fetch • git pull • …
gitのサブコマンドの作り方 git-foo という実行可能ファイルをPATHに配置 →サブコマンド git foo を定義できる 例: % echo
'echo "hello world"' > ~/bin/git-hello % chmod +x ~/bin/git-hello % git hello hello world
サブコマンドの例: git-set-file-times (rsyncに付属) ワーキングツリーのファイルのタイムスタンプをコミット時刻に合わせる https://github.com/WayneD/rsync/blob/master/support/git-set-file-times https://speakerdeck.com/yoichi/a-practical-example-of-a-small-contribution-to-oss
サブコマンドの例: git-restore-branch (自作) 削除したローカルブランチをリストアップ、復元する https://github.com/yoichi/git-restore-branch/blob/main/git-restore-branch https://zenn.dev/yoichi/articles/git-restore-branch
今日の題材: git-jump (git に付属) 興味のある要素にエディタでジャンプする • diff: diff hunks •
merge: merge conflicts • grep: grep hits • ws: whitespace errors https://github.com/git/git/blob/master/contrib/git-jump/git-jump
git-jumpの利用シーン • git grep キーワードにマッチした行を表示 • 周りの行を見たいなー → git grep
-C で前後の行も合わせて表示 • エディタで見れたらいいのになー → git jump grep
git-jumpの実装(シェルスクリプト) • 興味のある要素を「ファイル名:行番号:コンテンツ」の形式でファイル出力 • vim -q で開く https://vim-jp.org/vimdoc-ja/quickfix.html
「ファイル名:行番号:コンテンツ」の形式 git-jumpに限らず、 あちこちで見かける: • コンパイラのエラー出力 • 静的解析ツールの出力 • grep -n
の出力 これを入力として受け取れる プログラムはVim以外もある →Vim縛りを外すには?
「ファイル名:行番号:コンテンツ」の形式 git-jumpに限らず、 あちこちで見かける: • コンパイラのエラー出力 • 静的解析ツールの出力 • grep -n
の出力 これを入力として受け取れる プログラムはVim以外もある →Vim縛りを外すには? https://speakerdeck.com/yoichi/on-pipe
やったこと:git jumpで標準出力に出すオプションを追加 →quickfix list を任意のプログラム(例えば、Emacs の M-x grep)で使える
git-jumpの出力をEmacsで扱える ≠ git-jumpのEmacs対応 git jump –stdout で任意のプログラム(e.g. M-x grep)に出力を渡せるようになった •
diff: diff hunks • merge: merge conflicts • grep: grep hits • ws: whitespace errors git-jumpの機能: • 興味のある要素にエディタでジャンプする • =ターミナルでコマンドを打つと、素早くエディタが立ち上がる → Vimだけでなく、Emacsも制御できるようにしたい
やったこと:git jumpでEmacsを制御できるように EDITOR環境変数の複数のパターンに対応 • emacs 新しいEmacsプロセスを起動(同期) • emacsclient 既存のEmacsフレームを使う(非同期) •
emacsclient -c 新しいEmacsフレームを作る(同期) • emacsclient -t 現在のターミナルに新しいEmacsフレームを作る(同期) 工夫と手抜き • emacsとemacsclientで共通の –eval オプションを使う • 非同期の場合に一時ファイル削除の競合条件が発生しないよう待ち合わせ • 一時ファイルパス中の特殊文字への対応は従来のVim向けと同程度まで
デモ: git-jump with EDITOR=”emacsclient -t”
https://github.com/git/git/blob/master/Documentation/RelNotes/2.40.0.txt (次の版) "git jump" (in contrib/) learned to present the
"quickfix list" to its standard output, and learned to also drive emacs/emacsclient. まとめ:git-jumpを特定エディタへの依存から解放した git-jump –stdout 任意のプ ログラム git-jump git-jump Vimだけでなく、Emacsも制御できるように 標準出力を経由して、 git由来のquickfix listを任意 のプログラムに渡せるように