Linux中文环境快速进入$HOME目录"桌面"的办法

29 篇文章 0 订阅
4 篇文章 0 订阅

安装Linux的时候选择了中文版,桌面的目录就在 $HOME目录下的"桌面"目录;

在gnome terminal要进这个目录,从redhat、FC,到RHEL,ubuntu,没少烦过我:每次敲cd命令后还要把输入法切换到中文,再输入" 桌面";

后来找到一下办法:在.bashrc中export d=~/桌面/,要进“桌面"目录也就输入: "cd $d"


这时,问题又来了:

要把桌面的某个文件移到别的地方,敲mv $d/之后按TAB,bash竟然帮我补全成: "mv \$d/"....无语....

karlzheng@ubuntu:~$ complete |grep mv
complete -o default -F _longopt mv
karlzheng@ubuntu:~$ 

刚开始以为是,default行为或_longopt函数搞的鬼,跟踪了一下发现_longopt调用了_filedir()函数,_filedir()处理完了还没有把"$"号变成“\$",结论:bash后面又处理了一下

解决的办法:在_filedir()函数中把 "$d"替换掉,因此在_filedir()函数最后增加代码:

    local cnt=0
    while [ $cnt -lt ${#COMPREPLY[@]} ];
    do  
        local v=${COMPREPLY[$cnt]}
        if [[ ${v:0:1} == "{1}quot; ]]; then
            COMPREPLY[$cnt]=$(eval echo "$v")
        fi  
        ((cnt++))
    done

最后_filedir()函数变成:

_filedir()
{
    local i IFS=$\'\n\' xspec

    _tilde "$cur" || return 0

    local -a toks
    local quoted tmp

    _quote_readline_by_ref "$cur" quoted
    toks=( ${toks[@]-} $(
        compgen -d -- "$quoted" | {
            while read -r tmp; do
                # TODO: I have removed a "[ -n $tmp ] &&" before 'printf ..',
                #       and everything works again. If this bug suddenly
                #       appears again (i.e. "cd /b<TAB>" becomes "cd /"),
                #       remember to check for other similar conditionals (here
                #       and _filedir_xspec()). --David
                printf '%s\n' $tmp
            done
        }
    ))

    if [[ "$1" != -d ]]; then
        # Munge xspec to contain uppercase version too
        [[ ${BASH_VERSINFO[0]} -ge 4 ]] && \
            xspec=${1:+"!*.@($1|${1^^})"} || \
            xspec=${1:+"!*.@($1|$(printf %s $1 | tr '[:lower:]' '[:upper:]'))"}
        toks=( ${toks[@]-} $( compgen -f -X "$xspec" -- $quoted) )
    fi
    [ ${#toks[@]} -ne 0 ] && _compopt_o_filenames

    # If the filter failed to produce anything, try w/o it (LP: #533985)
    if [[ -n "$1" ]] && [[ "$1" != -d ]] && [[ ${#toks[@]} -lt 1 ]] ; then
       toks=( ${toks[@]-} $( compgen -f -X -- $quoted) )
    fi

    COMPREPLY=( "${COMPREPLY[@]}" "${toks[@]}" )

    local cnt=0
    while [ $cnt -lt ${#COMPREPLY[@]} ];
    do 
        local v=${COMPREPLY[$cnt]}
        if [[ ${v:0:1} == "{1}quot; ]]; then
            COMPREPLY[$cnt]=$(eval echo "$v")
        fi
        ((cnt++))
    done
}




评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值