使用TextMate打开GB2312,BIG等亚洲编码文件

问题就是我们使用TextMate不支持GB2312等编码,用着及其不方便,下面是解决方案:

打开Bundle Editor
选则Show all
选则文件夹TextMate(或者随便你选则什么)
增加一个新的template‘openEncodedFile’(或者随便你自己命名)
在Template data中如下设定
Extension:中 留空

Command(s):

# open CocoaDialog's file select menu
file=$(CocoaDialog fileselect \
        --title "Open an encoded file" \
        --with-directory $HOME/ \
)
# check for valid file
if [ -n "$file" ]; then
# open CocoaDialog's dropdown menu
# for more encodings add them to '--items'
# to list all possibile encodings use the Terminal with 'iconv -l'
        res=$(CocoaDialog dropdown \
                --title "Open an encoded file" \
                --text "Choose the encoding:" \
                ??exit?onchange \
                --button1 "Open" \
                --button2 "Cancel" \
                --items "BIG5" "EUC-TW" "GB2312" "SJIS" "EUC-JP" "KOI8-R" \
        )
# if user canceled exit
        [[ $( (tail -r <<<"$res") | tail -n1)  == "2" ]] && \
                exit_discard
        res=$(tail -n1 <<<"$res")
# add more 'elif' according to '--items' if needed
        if [ "$res" == 0 ]; then
                ENC="BIG5"
        elif [ "$res" == 1 ]; then
                ENC="EUC-TW"
        elif [ "$res" == 2 ]; then
                ENC="GB2312"
        elif [ "$res" == 3 ]; then
                ENC="SJIS"
        elif [ "$res" == 4 ]; then
                ENC="EUC-JP"
        elif [ "$res" == 5 ]; then
                ENC="KOI8-R"
        fi
# start conversion to UTF-8 and send the result as a new file back to TM
        iconv -f "$ENC" -t utf-8 "$file" > "$TM_NEW_FILE"
fi

Output: Insert as Text 
- Activation: Key Equivalent shift+option+o (我的建议) 
- Scope: 留空


From:http://aideehorn.iteye.com/blog/377917

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值