2015-05-19 8 views
5

Immer wenn ich tiefer in ein Verzeichnis navigiere, zeigt zsh den vollständigen Pfad in der Eingabeaufforderung an.zsh verkürzen die Länge des aktuellen Pfads

Statt

[email protected]:~/i/am/a/really/really/really/really/long/path/somewhere

der Anzeige würde ich lieber mag

[email protected]:~/path/somewhere

haben Wie kann ich das erreichen?

Ich verwende zsh mit iTerm auf OSX Yosemite 10.10.4.

EDIT:

Hier ist meine .bashrc-Datei:

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 
+1

Verwandte: [Nur aktuelle Verzeichnisnamen (nicht vollständiger Pfad) auf Bash-Prompt] (http://superuser.com/q/60555/204979). In der akzeptierten Antwort finden Sie einige gute Informationen über das Tuning von 'PS1'. – fedorqui

+0

Die angenommene Antwort sagt etwas über ein Großbuchstabe '\ W' aus. Ich habe meine Frage mit meiner Bashrc-Datei aktualisiert. PS1 ist bereits auf \ W eingestellt, also hilft mir das leider nicht weiter. Weitere Empfehlungen? – sqe

+0

Betrachten Sie die Links provorn in dieser Antwort. Außerdem entspricht die aktuelle PS1 nicht der hier angegebenen Definition. Ich würde für mehr Definitionen von "PS1" in Ihren Konfigurationsdateien "grep". 'grep PS1 ~ /.*' – fedorqui

Antwort

14

Um eine Anzahl der angezeigten Hinter Komponenten des Pfades geben Sie eine ganze Zahl einfügen in Escape-Sequenz in der Eingabeaufforderung entspricht. In Ihrem Fall wird %2~ den Trick machen. Auszug aus 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).