1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

SSH先からローカルのクリップボードにコピーする方法

Posted at

リモートサーバーで作業中、ローカルのクリップボードにテキストをコピーしたいことありますよね。OSC 52エスケープシーケンスを使えば簡単に実現できます。

スクリプト

#!/usr/bin/env bash
buf=$(cat | base64 | tr -d '\n')
printf '\e]52;c;%s\a' "$buf"

セットアップ

# スクリプトを作成
sudo vim /usr/local/bin/osc52

# 実行権限を付与
sudo chmod +x /usr/local/bin/osc52

使い方

# パイプで渡す
echo "コピーしたいテキスト" | osc52

# ファイルの内容をコピー
cat file.txt | osc52

# コマンドの出力をコピー
kubectl get pods | osc52
1
0
0

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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?