From 5cfd24a554f57061660a1a32150cd89d24db324a Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Fri, 10 Aug 2012 15:37:13 +0200 Subject: [PATCH] modularisation term_title --- bash/prompt | 19 +------------------ bash/rc | 1 + bash/term_title | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 18 deletions(-) create mode 100644 bash/term_title diff --git a/bash/prompt b/bash/prompt index a508fd5..4a4b74f 100644 --- a/bash/prompt +++ b/bash/prompt @@ -32,35 +32,18 @@ __tpwd() { __truncate_dir "$PWD" } -__bash_prompt_command() { - local pwdmaxlen=25 - local trunc_symbol="…" - - PROMPT_PWD=$(__tpwd) -} - - __set_bash_ps1() { - case $TERM in - xterm*|rxvt*) - local TITLEBAR='\[\033]0;\u:${NEW_PWD}\007\]' - ;; - *) - local TITLEBAR="" - ;; - esac # load color vars source "$DOTFILES_BASH_DIR/ansi_colors" # colorized: - PS1="${TITLEBAR} ${B}[${UC}\u@\h ${G}\${PROMPT_PWD}${B}]${UC}\\$ ${NONE}" + PS1=" ${B}[${UC}\u@\h ${G}\$(__tpwd)${B}]${UC}\\$ ${NONE}" # without colors: #PS1="${TITLEBAR}[\u@\h \${NEW_PWD}]\\$ " # extra backslash in front of \$ to make bash colorize the prompt } -PROMPT_COMMAND=__bash_prompt_command __set_bash_ps1 unset __set_bash_ps1 diff --git a/bash/rc b/bash/rc index 38cd69c..32cdc20 100644 --- a/bash/rc +++ b/bash/rc @@ -2,6 +2,7 @@ source $DOTFILES_BASH_DIR/prompt source $DOTFILES_BASH_DIR/history +source $DOTFILES_BASH_DIR/term_title source $DOTFILES_BASH_DIR/completion # easy on spelling mistakes diff --git a/bash/term_title b/bash/term_title new file mode 100644 index 0000000..43ff8e4 --- /dev/null +++ b/bash/term_title @@ -0,0 +1,28 @@ +# Tell the terminal about the working directory at each prompt. +if [ "$TERM_PROGRAM" == "Apple_Terminal" ] && [ -z "$INSIDE_EMACS" ]; then + update_terminal_cwd() { + # Identify the directory using a "file:" scheme URL, + # including the host name to disambiguate local vs. + # remote connections. Percent-escape spaces. + local SEARCH=' ' + local REPLACE='%20' + local PWD_URL="file://$HOSTNAME${PWD//$SEARCH/$REPLACE}" + printf '\e]7;%s\a' "$PWD_URL" + } + PROMPT_COMMAND="update_terminal_cwd; $PROMPT_COMMAND" +fi + +set_term_title() { + case $TERM in + xterm*|rxvt*) + local title="\033]2;$USER@${HOSTNAME%%.*}:${PWD/#$HOME/~}\a" + ;; + *) + local title="" + ;; + esac + printf "$title" +} +PROMPT_COMMAND="set_term_title; $PROMPT_COMMAND" + +# vim: ft=sh