Welcome 微信登录

首页 / 操作系统 / Linux / Linux中文环境快速进入$HOME目录“桌面”的办法

安装Linux的时候选择了中文版,桌面的目录就在 $HOME目录下的"桌面"目录;在gnome terminal要进这个目录,从RedHat、FC,到RHEL,Ubuntu,没少烦过我:每次敲cd命令后还要把输入法切换到中文,再输入" 桌面";后来找到一下办法:在.bashrc中export d=~/桌面/,要进“桌面"目录也就输入: "cd $d"这时,问题又来了:要把桌面的某个文件移到别的地方,敲mv $d/之后按TAB,bash竟然帮我补全成: "mv $d/"....无语....
  1. www.linuxidc.com@linuxidc:~$ complete |grep mv  
  2. complete -o default -F _longopt mv  
  3. www.linuxidc.com@linuxidc:~$   
刚开始以为是,default行为或_longopt函数搞的鬼,跟踪了一下发现_longopt调用了_filedir()函数,_filedir()处理完了还没有把"$"号变成“$",结论:bash后面又处理了一下 解决的办法:在_filedir()函数中把 "$d"替换掉,因此在_filedir()函数最后增加代码:
  1. local cnt=0  
  2. while [ $cnt -lt ${#COMPREPLY[@]} ];  
  3. do    
  4.     local v=${COMPREPLY[$cnt]}  
  5.     if [[ ${v:0:1} == "{1}quot; ]]; then  
  6.         COMPREPLY[$cnt]=$(eval echo "$v")  
  7.     fi    
  8.     ((cnt++))  
  9. done  
最后_filedir()函数变成:
  1. _filedir()  
  2. {  
  3.     local i IFS=$" " xspec  
  4.   
  5.     _tilde "$cur" || return 0  
  6.   
  7.     local -a toks  
  8.     local quoted tmp  
  9.   
  10.     _quote_readline_by_ref "$cur" quoted  
  11.     toks=( ${toks[@]-} $(  
  12.         compgen -d -- "$quoted" | {  
  13.             while read -r tmp; do  
  14.                 # TODO: I have removed a "[ -n $tmp ] &&" before "printf ..",   
  15.                 #       and everything works again. If this bug suddenly   
  16.                 #       appears again (i.e. "cd /b<TAB>" becomes "cd /"),   
  17.                 #       remember to check for other similar conditionals (here   
  18.                 #       and _filedir_xspec()). --David   
  19.                 printf "%s " $tmp  
  20.             done  
  21.         }  
  22.     ))  
  23.   
  24.     if [[ "$1" != -d ]]; then  
  25.         # Munge xspec to contain uppercase version too   
  26.         [[ ${BASH_VERSINFO[0]} -ge 4 ]] &&   
  27.             xspec=${1:+"!*.@($1|${1^^})"} ||   
  28.             xspec=${1:+"!*.@($1|$(printf %s $1 | tr "[:lower:]" "[:upper:]"))"}  
  29.         toks=( ${toks[@]-} $( compgen -f -X "$xspec" -- $quoted) )  
  30.     fi  
  31.     [ ${#toks[@]} -ne 0 ] && _compopt_o_filenames  
  32.   
  33.     # If the filter failed to produce anything, try w/o it (LP: #533985)   
  34.     if [[ -n "$1" ]] && [[ "$1" != -d ]] && [[ ${#toks[@]} -lt 1 ]] ; then  
  35.        toks=( ${toks[@]-} $( compgen -f -X -- $quoted) )  
  36.     fi  
  37.   
  38.     COMPREPLY=( "${COMPREPLY[@]}" "${toks[@]}" )  
  39.   
  40.     local cnt=0  
  41.     while [ $cnt -lt ${#COMPREPLY[@]} ];  
  42.     do   
  43.         local v=${COMPREPLY[$cnt]}  
  44.         if [[ ${v:0:1} == "{1}quot; ]]; then  
  45.             COMPREPLY[$cnt]=$(eval echo "$v")  
  46.         fi  
  47.         ((cnt++))  
  48.     done  
  49. }  
Linux P2P音视频聊天系统实现步骤[简]VirtualBox 下使用招商银行网银专业版(U盾)相关资讯      Linux教程 
  • Linux教程:如何在命令行中查看目  (07/28/2014 12:22:23)
  • Linux 修改root密码  (11/03/2012 07:53:38)
  • su - root 与su root的区别  (06/06/2012 00:39:40)
  • Linux进程间通信:消息队列  (01/28/2013 09:43:00)
  • U盘安装Linux开机无法启动解决方法  (10/07/2012 08:55:52)
  • Windows 7/Linux 同步时间  (05/15/2012 06:17:55)
本文评论 查看全部评论 (0)
表情: 姓名: 字数