最近の tar
は圧縮 tar ball 展開の際、拡張子によって自動的に伸長プログラムを決定しているようです。
古いのだと…
% tar zxf foo.tar.gz
としなければいけなかったのが、
% tar xf foo.tar.gz
でイケるというわけです。xf
しか指定しなくてイイ。
すると tar
に渡す圧縮形式指定によって補完を決めている zsh
がちょっとうざくなりまして…。
それで圧縮形式指定を無視するようにしてみました。
まず、zsh 関数を置く場所を決めます。ここでは ~/.zsh/functions
とします。
次に .zshrc
に以下のコードを追加します。
fpath=(~/.zsh/functions $fpath)
次に、指定したディレクトリ (ここでは ~/.zsh/functions
) に次のファイルを置きます。ファイル名は _tar_archive
でなければなりません。
_tar_archive
# -*- shell-script -*-
#autoload
local expl
[[ $# -eq 0 && $+_tar_cmd -ne 0 ]] && set "$_tar_cmd"
_description files expl 'archive file'
if [[ "$1" = *[urtx]* ]]; then
local pattern1='(tar|TAR|iso|ISO|cpio).(|(gz|GZ|Z|bz2|lzma|xz))'
local pattern2='tgz|tbz|jar|zip|txz'
_files "$expl[@]" -g "*.(${pattern1}|${pattern2})(-.)"
else
_files "$expl[@]"
fi
以下を参考にしました。
https://github.com/DragonFlyBSD/DPorts/blob/master/shells/zsh/files/extra-patch-bsdtar
http://zsh.sourceforge.net/Doc/Release/Functions.html