From ce345aa24d80b36058c6ace9c5076f359b98e60c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Mengu=C3=A9?= Date: Mon, 17 Jun 2013 21:40:56 +0200 Subject: [PATCH] Improve support for MacOS X directory icon (update_terminal_cwd) Improvements: - check if update_terminal_cwd is available instead of relying on the kernel version - test the feature once at init time instead of at prompt time Note that zsh is not yet supported for that feature unless the update_terminal_cwd has been imported in your environment. I think it would be possible to support it, but I don't have access to MacOS X machines, so... patches are welcome! --- liquidprompt | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/liquidprompt b/liquidprompt index a42e0e1..8eb389d 100755 --- a/liquidprompt +++ b/liquidprompt @@ -372,6 +372,18 @@ else LP_BRACKET_CLOSE="${LP_MARK_BRACKET_CLOSE}" fi +# update_terminal_cwd is a shell function available on MacOS X Lion that +# will update an icon of the directory displayed in the title of the terminal +# window. +# See http://hints.macworld.com/article.php?story=20110722211753852 +if [[ "$TERM_PROGRAM" == Apple_Terminal ]] && command -v update_terminal_cwd >/dev/null; then + _LP_TERM_UPDATE_DIR=update_terminal_cwd + [[ "$PROMPT_COMMAND" == update_terminal_cwd ]] && PROMPT_COMMAND= +else + _LP_TERM_UPDATE_DIR=: +fi + + # Escape the given strings # Must be used for all strings that may comes from remote sources, # like VCS branch names @@ -1602,15 +1614,8 @@ _lp_set_prompt() local IFS="$(echo -e ' \t') " # space, tab, LF - # execute the old prompt if not on Mac OS X (Mountain) Lion - case "$LP_OS" in - Linux|FreeBSD|OpenBSD|SunOS) $LP_OLD_PROMPT_COMMAND ;; - Darwin) - case "$(LP_DWIN_KERNEL_REL_VER)" in - 11|12) update_terminal_cwd ;; - *) $LP_OLD_PROMPT_COMMAND ;; - esac ;; - esac + # execute the old prompt + $LP_OLD_PROMPT_COMMAND # left of main prompt: space at right LP_JOBS="$(_lp_sr "$(_lp_jobcount_color)")" @@ -1633,6 +1638,9 @@ _lp_set_prompt() LP_RUNTIME=$(_lp_sl "$(_lp_runtime)") if [[ "$LP_OLD_PWD" != "LP:$PWD" ]]; then + # Update directory icon for MacOS X + $_LP_TERM_UPDATE_DIR + LP_VCS="" LP_VCS_TYPE="" # LP_HOST is a global set at load time