LoginSignup
0

ターミナルエミュレータ内でクリッカブルなリンクを作る方法

Last updated at Posted at 2018-07-30

iTerm2で下記コマンドを実行すると

$ echo -e '\e]8;;http://example.com\aThis is a link\e]8;;\a'

This is a link というテキストが下線つきで表示される。

image.png

このテキストをCmdキーを押しながらマウスでクリックすると http://example.com が開く。

このエスケープシーケンスはOSC 8と呼ばれる(OSCはOperating System Commandの略で\e]を意味する)。
iTerm2以外でもkitty, wezterm, Alacritty, Windows Terminalなどモダンなターミナルエミュレータは対応しているが、古めのものは対応していないようだ。
https://github.com/Alhadis/OSC8-Adoption/

iTerm2でもscreenを実行しているとダメ。

ちなみにiTerm2はこのエスケープシーケンスを使わずとも、URLの上でCmd+クリックすると開ける。同様の機能はurxvtやminttyなど多数のターミナルエミュレータに実装されている。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0