summaryrefslogtreecommitdiff
path: root/.config/bash
diff options
context:
space:
mode:
Diffstat (limited to '.config/bash')
-rw-r--r--.config/bash/rc.d/emacs.sh43
-rw-r--r--.config/bash/rc.sh12
2 files changed, 44 insertions, 11 deletions
diff --git a/.config/bash/rc.d/emacs.sh b/.config/bash/rc.d/emacs.sh
index f484bbb..9c1bf4d 100644
--- a/.config/bash/rc.d/emacs.sh
+++ b/.config/bash/rc.d/emacs.sh
@@ -1,8 +1,41 @@
+#!/bin/bash
+
case "$TERM" in
eterm*)
- SELECTED_EDITOR='emacsclient'
- EDITOR=$SELECTED_EDITOR
- VISUAL=$SELECTED_EDITOR
- export SELECTED_EDITOR EDITOR VISUAL
- :;;
+ SELECTED_EDITOR='emacsclient'
+ EDITOR=$SELECTED_EDITOR
+ VISUAL=$SELECTED_EDITOR
+ export SELECTED_EDITOR EDITOR VISUAL
+ # The following uses the variable _EMACS_BUFFER to store some state
+ _emacs_quote() {
+ local str="$*"
+ str="${str//\\/\\\\}"
+ str="${str//\"/\\\"}"
+ str="\"${str}\""
+ printf '%s' "$str"
+ }
+ _emacs_rename_terminal() {
+ local name="$(_emacs_quote "$(_emacs_get_desired_buffer_name)")"
+ if [[ -n $_EMACS_BUFFER ]]; then
+ local buffer="(get-buffer $_EMACS_BUFFER)"
+ else
+ local buffer='(window-buffer (selected-window))'
+ fi
+ _EMACS_BUFFER="$(emacsclient -e "(with-current-buffer ${buffer} (rename-buffer ${name} t)))" 2>/dev/null)"
+ }
+ _emacs_get_short_cwd() {
+ local base=$1
+ local suffix=''
+ if [[ $base =~ (/(src|pkg|doc|pkg-libre|src-libre|trunk|tags|branches))*$ ]]; then
+ suffix=$BASH_REMATCH
+ base=${base%$suffix}
+ fi
+ base=${base##*/}
+ echo ${base}${suffix}
+ }
+ _emacs_get_desired_buffer_name() {
+ echo "*ansi-term*<$(_emacs_get_short_cwd "$PWD")>"
+ }
+ PROMPT_COMMAND='_emacs_rename_terminal "$(_emacs_get_desired_buffer_name)"'
+ :;;
esac
diff --git a/.config/bash/rc.sh b/.config/bash/rc.sh
index 447796a..2bf60bc 100644
--- a/.config/bash/rc.sh
+++ b/.config/bash/rc.sh
@@ -13,17 +13,16 @@ shopt -s checkhash
################################################################################
# History settings
-export HISTCONTROL=ignoredups
-export HISTFILE=${XDG_CACHE_HOME}/bash/history
-export HISTTIMEFORMAT='[%Y-%m-%d %H:%M] '
-export HISTSIZE=5000
+HISTCONTROL=ignoredups
+HISTFILE=${XDG_CACHE_HOME}/bash/history
+HISTTIMEFORMAT='[%Y-%m-%d %H:%M] '
+HISTSIZE=5000
shopt -s histappend # append to the history file, don't overwrite it
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}"
@@ -57,7 +57,7 @@ if tput setaf 1 &>/dev/null; then
_STATUS+="\$(v=\$?; [[ \$v = 0 ]] && c='${GREEN}' || c='${RED}'; printf %s%03i \$c \$v)"
_STATUS+="${RESET}${BOLD}]${RESET}"
else
- _STATUS='[$?]'
+ _STATUS='[$(printf "%03i" $?)]'
fi
PS1="${_STATUS} $(make_prompt)"'\n\$ '
unset RESET BOLD RED GREEN BLUE _STATUS