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...
Search
Yoichi NAKAYAMA
February 13, 2023
Programming
0
1.3k
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
130
ターミナル出力の色付け / Terminal output coloring
yoichi
0
160
パイプの話 / on pipe
yoichi
0
490
バイナリリーディング / Binary Reading
yoichi
0
370
OSS開発を楽しく続けてきた話
yoichi
0
820
Other Decks in Programming
See All in Programming
API for docs
soutaro
3
1.5k
カウシェで Four Keys の改善を試みた理由
ike002jp
1
110
20250429 - CNTUG Meetup #67 / DevOps Taiwan Meetup #69 - Deep Dive into Tetragon: Building Runtime Security and Observability with eBPF
tico88612
0
130
監視 やばい
syossan27
11
10k
RuboCop: Modularity and AST Insights
koic
2
2k
generative-ai-use-cases(GenU)の推しポイント ~2025年4月版~
hideg
1
330
Youtube Lofier - Chrome拡張開発
ninikoko
0
2.5k
設計の本質:コード、システム、そして組織へ / The Essence of Design: To Code, Systems, and Organizations
nrslib
10
3.3k
SwiftUI API Design Lessons
niw
1
300
Golangci-lint v2爆誕: 君たちはどうすべきか
logica0419
1
180
2ヶ月で生産性2倍、お買い物アプリ「カウシェ」4チーム同時改善の取り組み
ike002jp
1
100
note の Elasticsearch 更新系を支える技術
tchov
0
180
Featured
See All Featured
A designer walks into a library…
pauljervisheath
205
24k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
The Art of Programming - Codeland 2020
erikaheidi
53
13k
Testing 201, or: Great Expectations
jmmastey
42
7.5k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.4k
Into the Great Unknown - MozCon
thekraken
38
1.7k
Become a Pro
speakerdeck
PRO
28
5.3k
Mobile First: as difficult as doing things right
swwweet
223
9.6k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
5
570
Rebuilding a faster, lazier Slack
samanthasiow
81
8.9k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.2k
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を任意 のプログラムに渡せるように