LoginSignup
2
1

More than 5 years have passed since last update.

Ubuntuで、zipファイルをダブルクリックで開けるよ!

Posted at

MacOS同様、Ubuntuでもzipファイルをダブルクリックで開く方法を教えてもらったのでシェアしておきます。

デモ

demo-extract.gif

環境

Ubuntu 16.04 LTS

手順

  1. .desktopファイルを作成
  2. xdg-mineコマンドを実行
  3. シェルスクリプトを作る

1 .desktopファイルを作成

/usr/share/applications/に、以下のファイルを作ります。ファイル名はextract-here.desktopとしておきましょうか。

extract-here.desktop
[Desktop Entry]
Name=extract-here
Exec=/usr/bin/extract-here.sh %U
Terminal=false
Type=Application
MimeType=application/zip;

2. xdg-mineコマンドを実行

$ xdg-mime default extract-here.desktop "application/zip"

なお、再起動してもこの設定は引き継がれます。

3. シェルスクリプトを作る

以下のシェルスクリプトを/usr/bin/以下に作ります。

extract-here.sh
#!/bin/bash
/usr/bin/file-roller -h "$1";

file-roller -hは、「ここで展開」と同じです。
$1をダブルクォーテーションで囲っていれば、圧縮ファイル名に空白が入っていても大丈夫です。

tar.gzも展開できるようにする

まず、tar.gzのmimetypeを調べます。

mimetype hoge.tar.gz

すると以下のような結果が返ってくると思います。

hoge.tar.gz: application/x-compressed-tar

どうやら、tar.gzのmimetypeはapplication/x-compressed-tarのようですね。
mimetypeがわかったところで、xdg-mimeコマンドを実行しましょう。

xdg-mime default extract-here.desktop "application/x-compressed-tar"

こうすれば、tar.gzファイルもダブルクリックで解凍できるようになります。便利ですね!

参考

Ubuntuで、zipファイルをダブルクリックで展開するにはどうすればいいか。
Use custom command to open files
bash get the parent directory of current directory

あとがき

とても気軽に圧縮ファイルを展開できるので便利です。

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