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
xonshとかいうshellの話
Search
vaaaaanquish
February 19, 2020
Science
2.1k
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
xonshとかいうshellの話
社内LTイベントでの発表資料です。
vaaaaanquish
February 19, 2020
More Decks by vaaaaanquish
See All by vaaaaanquish
人はいかにして 確率的な挙動を 受け入れていくのか
vaaaaanquish
6
4k
生成AIによるソフトウェア開発の収束地点 - Hack Fes 2025
vaaaaanquish
36
22k
LLMが機械学習分野と他分野に起こしたキャズムから見極めるエンジニアの未来像
vaaaaanquish
1
470
エムスリー流!難読クイズを作ってPythonの深淵に触れるコツ! - 技育CAMPアカデミア
vaaaaanquish
2
570
pandasはPolarsに性能面で追いつき追い越せるのか
vaaaaanquish
7
6.9k
Pythonのパッケージ管理の中級者の壁を超える stapy#98
vaaaaanquish
19
23k
Tech LT #4 人を選ぶ技術
vaaaaanquish
3
5k
CADDi AI LabにおけるマネージドなMLOps
vaaaaanquish
2
3.8k
RustとCADDi AI LabとML
vaaaaanquish
1
1.2k
Other Decks in Science
See All in Science
CVPR2026_VGGTとその仲間たち
mickey_0226
0
1.1k
O(log n)-Approximation Algorithms for Bipartiteness Ratio
tasusu
0
180
Physical AIを支えるWeights & Biases
olachinkei
1
580
機械学習 - ニューラルネットワーク入門
trycycle
PRO
0
1.2k
How a camera trap data standard enabled an ecosystem of interoperable tools
peterdesmet
0
130
[TMLR 2026, Featured Certification] Double Bounded α-Divergence Optimization for Density Estimation
gkazunii
1
110
Wet Active Matter
rajeshrinet
0
150
Where does the rigor go? Research software and the future of trustworthy science.
arfon
0
100
知能とはなにか -ヒトとAIのあいだ-
tagtag
PRO
0
180
SAT ソルバーの仕組みと制約ソルバーへの応用
tsoh
1
110
20260410_SystemsThinking
takusamar
1
150
勾配流から乖離した学習ダイナミクス
hanbao
0
710
Featured
See All Featured
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
310
Practical Orchestrator
shlominoach
191
12k
ラッコキーワード サービス紹介資料
rakko
1
4.8M
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
380
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.8k
Git: the NoSQL Database
bkeepers
PRO
432
67k
Discover your Explorer Soul
emna__ayadi
2
1.3k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3k
What Being in a Rock Band Can Teach Us About Real World SEO
427marketing
0
1.1k
Designing Powerful Visuals for Engaging Learning
tmiket
1
530
How to Ace a Technical Interview
jacobian
281
24k
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.1k
Transcript
xonshとかいうshellの話 @vaaaaanquish
自己紹介的なやつ • AI・機械学習チーム、河合、ばんくし • xontributor ◦ 多分日本人では一番 PR出してる (#12) ◦
補完時の画面描画とか非同期化とか ◦ xontrib 3つ作ってる • PyCon JP 2019でxonshの話した • xonshアドベントカレンダー2017, 2018を企画 ◦ 16/50 本を担当 ◦ 日常的にもxonsh記事を書いている
xonshの概要(一般教養ですが念の為) • Python + shell scriptを実現するPythonで書かれたshell • 現在v0.9.13 ◦ v1.0.0へのTracking
issueあり ◦ 私がdefault shellにするレベル • Anthony Scopatz ◦ サウスカロライナ大学 助教 ◦ Enthoughtという企業で働いた後 天文物理学で博士号 ◦ 今は原子力工学の動画 YouTubeにあげたり 普通に仕事しつつ草を生やす化け物 ◦ So cool
xonshの立ち位置 • Python + shell scriptを実現するPythonで書かれたshell • 概念はPython REPLに近いがインタプリタよりはshell寄り fish
xonsh POSIX-compatible Python Bourne Shell (sh) PyConで使った最高の図
そもそもshellとは • ユーザの入力をターミナルから受け取りOS kernelに伝える • システムコールをプロンプトとコマンドで対話的に利用するためのツール • POSIX (IEEE Std
1003.2) で標準化された sh ◦ 派生としてbash, zshを代表に多くのshellが使われている ◦ ash, bsh, csh, ksh,...と長いが現在は bash, zsh, fishがメジャー ターミナル Shell Kernel 気軽に低レイヤー屋に見せたら処される図 - PROMPT - コマンド - 入出力
xonshが実現するshell機能 • PLY (Python Lex-Yacc) による構文解析 -> AST • 現在のxonshが動くPythonプロセス内のcontextに構文があるかを判定
→ pythonとしてexecで実行 → shell commandとしてsubprocess execで実行 • 例:`ls -l` を見た時 → 一般的にはshellコマンド → python変数の可能性も
xonshが実現するshell機能 • PLY (Python Lex-Yacc) による構文解析 -> AST • 現在のxonshが動くPythonプロセス内のcontextに構文があるかを判定
→ pythonとしてexecで実行 → shell commandとしてsubprocess execで実行 • 例:`ls -l` を見た時 → 一般的にはshellコマンド → python変数の可能性も ここを上手いことやっているのが xonshの本質 • ターミナルを構築する機能は python prompt-toolkit (ptk) なるツールのwrapper • 本来のKernelにコマンドを伝える部分は subprocess のshellが行っている
xonshが実現するshell機能 • PLY (Python Lex-Yacc) による構文解析 -> AST • 現在のxonshが動くPythonプロセス内のcontextに構文があるかを判定
→ pythonとしてexecで実行 → shell commandとしてsubprocess execで実行 • 例:`ls -l` を見た時 → 一般的にはshellコマンド → python変数の可能性も ターミナル ptk Shell (or in Python) Kernel 気軽に低レイヤー屋に見せたら処される図 その2 xonsh
xonshが出来ること • 独自Syntax ( $(), ![], @(),...,etc ) を利用したshell script
+ python • モダンなshellが行うようなtab補完、Gray Suggest (ptkの機能)
xonshが出来ること • Python + shell scriptによるconfig記述 (.xonshrc) ◦ $PROMPT, color,
◦ keybindings, completer, history ◦ xonsh自体もpythonなのでoverrideも • pandas, matplotlib等の描画 ◦ Pythonで日常的に開発してると less感覚で使えて嬉しい • 独自のenvライブラリによる環境管理 (vox) ◦ 「hoge envと相性悪い」みたいな事がない
みんなが使う意味ある? • ほぼない
みんなが使う意味ある? • 既存のshellからの移行 ◦ 専用のsource_bashなるコマンドもあり概ね既存スクリプトはよしなに実行できる ◦ bashの上でxonshプロセスを起動するなどして多重の環境変数や補完も (やや難しい) ◦ 全部移行可能かと問われると微妙
(zshの拡張使いたいとか ) • 起動時間問題 • Pythonが憎い ◦ わかる • vaaaanquishブログしか技術記事が出てこない ◦ わかる ◦ それな ◦ ごめんて
xonshを使うメリットは? • 他のShellと比べて ◦ スクリプト言語を区別せず書けるという思想では多分一番使える ◦ lispのLush、SchemeのScsh、RustのNu shell…等はあくまでzsh, bashの再現 ◦
似た思想としてRubyのRushがあるが開発進んでない感 ◦ Goで似たshell作ってる人もちらほら居るが完成度ならまだ xonsh ▪ それでもzshやfishの方が情報やコミュニティが大きい (小さいと楽しいこともあるけど ) • Pythonの資産を既に持っていると幸せになれる ◦ requests, pandas, matplot, ptk, iTerm2 API, OS X API, vim… ◦ 画像出力やaws cli, gcloudコマンドを簡単に拡張できる • ちょっとShellやCLIツールに詳しくなる • Anthony Scopatzが優しい ◦ すぐ「so cool!!」って言ってくれる
3年xonshを推してみて(個人的な主観) • ShellもといCLIをカスタマイズしたい需要自体が年々下がっている ◦ zshの機能性、完成度 ◦ 進化するIDE、VSCode、GitHubクライアント、Jupyter、Google Cloud Console、… ◦
スクリプト言語の繁栄( Python、Ruby、Go…etc) ▪ sed, awkに行くまで道のりが長い ▪ そもそも2020年に複雑なshell scriptをメンテしたいかと言われると … ◦ Docker、リモートサーバの中に入って作業する事も人に依っては多くはない ◦ 伸びてるのはシェル芸 botくらいか…羨ましい… • 長らく別のshellを使っている人は移行しにくい ◦ 身体がshell scriptで出来ている人の無限の bashrc, zshrc ◦ VSCodeみたく「デフォルトで結構使える」「 GUIで設定できる」みたいな方向性に行くか …? • そもそもPythonじゃなくてよくね… ◦ それな ◦ xonshのコアライブラリptkのGo言語版最近見てる
おわりに • xonshはいいぞ • Tech Talk Shell Script会やりましょう! ◦ みんなの便利コマンド、シェル芸が見たい!聞きたい!