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

CUIで指定したファイルをGUI上に「Ctrl+V」で渡す方法

0
Posted at

はじめに

この記事は日常的にCUIを使っていて、目的のファイルがGUIのファイルマネージャよりCUIのほうが探しやすいという人向けの記事です。

slackやメールにファイルを添付するとき、ファイルマネージャでマウスをポチポチするより端末で探した方が早いですよね?
ですが、せっかくファイルを見つけてもCUIのコピーとGUIのクリップボードは別物なので、ファイルのコピーができません。
そういうときのために、下記のスクリプトを用意しておけば、

  1. 端末でファイルを指定してクリップボードにコピー
  2. slack等で Ctrl+V でファイル貼り付け

ができるようになります。

スクリプト

#!/bin/bash

if [ $# -lt 1 ]; then
    echo "Usage: $0 <arg>"
    exit 1
fi
file="$1"

echo "file://"`realpath ${file}`  | xclip -sel c -t text/uri-list

使い方

あらかじめ xclip パッケージマネージャ等でインストールしておきます。
上記スクリプトをパスの遠ているところにおいて使ってください。

なお、ファイルではなく普通のテキストのコピー&ペーストも xclip で可能です。

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