From 2aeb4cce82448d0216411fb8a0b6676f5e87d7da Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Sat, 7 Dec 2013 12:42:39 -0500 Subject: bash: rename the buffer in Emacs' ansi-term --- .config/bash/rc.d/emacs.sh | 20 ++++++++++++++++++++ .config/bash/rc.sh | 2 +- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/.config/bash/rc.d/emacs.sh b/.config/bash/rc.d/emacs.sh index f484bbb..7e84651 100644 --- a/.config/bash/rc.d/emacs.sh +++ b/.config/bash/rc.d/emacs.sh @@ -4,5 +4,25 @@ case "$TERM" in EDITOR=$SELECTED_EDITOR VISUAL=$SELECTED_EDITOR export SELECTED_EDITOR EDITOR VISUAL + _set_buffer_name() { + local name="$*" + local name_esc="${name//\\/\\\\}" + name_esc="${name_esc//\"/\\\"}" + emacsclient -e " +(with-current-buffer (window-buffer (selected-window)) + (if (not (string= \"${name}\" (buffer-name))) + (rename-buffer (generate-new-buffer-name \"${name}\")))) +" &>/dev/null + } + _create_buffer_name() { + local base=$PWD suffix='' + if [[ $base =~ /(src|pkg|doc|pkg-libre|src-libre|trunk|tags|branches)$ ]]; then + suffix=$BASH_REMATCH + base=${base%$suffix} + fi + base=${base##*/} + echo "*ansi-term*<${base}${suffix}>" + } + PROMPT_COMMAND='_set_buffer_name "$(_create_buffer_name)"' :;; esac diff --git a/.config/bash/rc.sh b/.config/bash/rc.sh index 633f81e..62cc8ec 100644 --- a/.config/bash/rc.sh +++ b/.config/bash/rc.sh @@ -23,7 +23,6 @@ mkdir -p "${HISTFILE%/*}" # General settings shopt -s checkwinsize # update the values of LINES and COLUMNS shopt -s globstar # Let ** recursively scan directories -PROMPT_COMMAND='' ################################################################################ # Overly complicated setting of PS1 # @@ -38,6 +37,7 @@ term-title() { esac printf "$fmt" "$*" } +PROMPT_COMMAND='' make_prompt() { echo "${BOLD}${GREEN}\u@\h${BLUE}:\w${RESET}" -- cgit v1.2.3-54-g00ecf