在bash终端里,怎么将路径名显示在终端的最右边
Tofloor
poster avatar
andy-ian
deepin
2020-05-31 02:42
Author
本帖最后由 andy-ian 于 2020-5-30 19:00 编辑

我在~/.bashrc里面最后添加一下内容:

  1. __current_cursor_offset () {
Copy the Code
  1.              printf  '\e[6n'
Copy the Code
  1.              read -sdR pos
Copy the Code
  1.              pos=${pos#*;}
Copy the Code
  1.               printf $pos
Copy the Code
  1. }
Copy the Code
  1. PS1='[\e[1;32m\u@\h\e[0m]\e[0;33m$(__git_ps1)\e[0m\$ \e[s$(OFFSET="$(__current_cursor_offset)";printf "%*s" $((COLUMNS-OFFSET)) "# $PWD")\e[u'
Copy the Code

出现了光标卡住不动的现象,也无法输入的现象(卡在函数__current_cursor_offset里面了,但是在脚本最后,如果这样 __current_cursor_offset 调用就不会卡住)。
如果添加下面的方式,会有注释中的问题。
  1. PS1='[\e[1;32m\u@\h\e[0m]\e[0;33m$(__git_ps1)\e[0m\$ \e[s$(OFFSET="$(printf "%*s" $((COLUMNS)) "# $PWD")\e[u'
Copy the Code
  1. # 当执行printf "**************" 类似的命令导致路径会换行
Copy the Code



请问各位大神,有什么方式在bash终端里右面显示路径






Reply Favorite View the author
All Replies
avatar
liwl
deepin
2020-05-31 03:00
#1
检索Linux,修改PS变量
Reply View the author
avatar
andy-ian
deepin
2020-05-31 03:01
#2
https://bbs.deepin.org/post/195300
检索Linux,修改PS变量

我这就是修改PS1变量啊
Reply View the author
avatar
andy-ian
deepin
2020-05-31 03:02
#3
https://bbs.deepin.org/post/195300
检索Linux,修改PS变量

我这就是修改PS1变量啊
Reply View the author
avatar
andy-ian
deepin
2020-05-31 04:22
#4
__current_cursor_offset ()
{
       printf  '\e[6n' 1>&2
       read -sdR pos
       pos=${pos#*;}
       printf $pos
}

PS1='[\e[1;32m\u@\h\e[0m]\e[0;33m$(__git_ps1)\e[0m\$ \e[s$(OFFSET="$(__current_cursor_offset)"S1STR="[${USER}@${HOSTNAME}]$(__git_ps1)$";printf "%*s" $((COLUMNS-OFFSET-${#PS1STR})) "# $PWD")\e[u'
Reply View the author