4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

文字コードを瞬時に変更するための zsh 関数

Last updated at Posted at 2012-08-24

nkf コマンドを覚えられないので、.zshrc に以下の関数を定義している。

function euc() {
    for i in $*; do
        if [[ -f $i ]] then
            nkf -e -Lu $i >! /tmp/euc.$$ # -Lu :改行を LF にする
            mv -f /tmp/euc.$$ $i
        fi
    done
}
function utf() {
    for i in $*; do
        if [[ -f $i ]] then
            nkf -w -Lu $i >! /tmp/utf.$$ # -Lu :改行を LF にする
            mv -f /tmp/utf.$$ $i
        fi
    done
}
function sjis() {
    for i in $*; do
        if [[ -f $i ]] then
            nkf -s -Lw $i >! /tmp/sjis.$$ # -Lw :改行を CR+LF にする
            mv -f /tmp/sjis.$$ $i
        fi
    done
}

utf * でディレクトリ内のファイル全ての文字コードを UTF-8 にしたりできる。個人的に重宝してる設定の一つ。

バックアップを作成するかどうかや、改行コードを何にするかなどは各自書き換えるといいだろう。

4
4
1

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
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?