gpt4 book ai didi

macos - zsh缩短电流路径的长度

转载 作者:行者123 更新时间:2023-12-01 00:54:35 25 4
gpt4 key购买 nike

每当我深入目录时,zsh都会在提示中显示完整路径。

而不是显示
x@y:~/i/am/a/really/really/really/really/long/path/somewhere
我想有
x@y:~/path/somewhere
我怎样才能做到这一点?

我在OSX Yosemite 10.10.4上的iTerm中使用zsh。

编辑:

这是我的bashrc文件:

  1 # System-wide .bashrc file for interactive bash(1) shells.
2 if [ -z "$PS1" ]; then
3 return
4 fi
5
6 PS1='\h:\W \u\$ '
7 # Make bash check its window size after a process completes
8 shopt -s checkwinsize
9 # Tell the terminal about the working directory at each prompt.
10 if [ "$TERM_PROGRAM" == "Apple_Terminal" ] && [ -z "$INSIDE_EMACS" ]; then
11 update_terminal_cwd() {
12 # Identify the directory using a "file:" scheme URL,
13 # including the host name to disambiguate local vs.
14 # remote connections. Percent-escape spaces.
15 local SEARCH=' '
16 local REPLACE='%20'
17 local PWD_URL="file://$HOSTNAME${PWD//$SEARCH/$REPLACE}"
18 printf '\e]7;%s\a' "$PWD_URL"
19 }
20 PROMPT_COMMAND="update_terminal_cwd; $PROMPT_COMMAND"
21 fi

最佳答案

要指定路径中显示的许多尾随组件,请在提示符下将整数插入相应的转义序列。在您的情况下,%2~将解决问题。 zshmisc(1)的节选:

%d 
%/ Current working directory. If an integer follows the `%',
it specifies a number of trailing components of the current
working directory to show; zero means the whole path. A
negative integer specifies leading components, i.e. %-1d
specifies the first component.

%~ As %d and %/, but if the current working directory starts
with $HOME, that part is replaced by a `~'. Furthermore, if
it has a named directory as its prefix, that part is replaced
by a `~' followed by the name of the directory, but only if
the result is shorter than the full path; see Dynamic and
Static named directories in zshexpn(1).

关于macos - zsh缩短电流路径的长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30323993/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com