From 9b89244a826e65c4643830e4c5b0fda10756810f Mon Sep 17 00:00:00 2001 From: 10sr <8slashes+git@gmail.com> Date: Mon, 26 Mar 2012 16:10:10 +0900 Subject: [PATCH] fix some bug --- bashrc | 25 ++++++++++++++++--------- emacs.el | 29 ++++++++++++++++------------- 2 files changed, 32 insertions(+), 22 deletions(-) diff --git a/bashrc b/bashrc index 14faedd..d6a9272 100755 --- a/bashrc +++ b/bashrc @@ -65,12 +65,6 @@ uname -a echo TERM $TERM on $(tty), running $BASH $BASH_VERSION echo -if [ "${EMACS}" = "t" ]; then # for emacs shell - true export PS1="\u@\H \d \t \w\nemacs shell\$ " -elif echo "$EMACS" | grep term >/dev/null 2>&1; then # for emacs term - echo "Emacs Term" -fi - ################################### # some aliases and functions @@ -78,7 +72,7 @@ test "$TERM" == dumb || _coloroption=" --color=always" alias ls="ls -hCF --time-style=long-iso${_coloroption}" # export GREP_OPTIONS="" -alias grep="grep${_coloroption}" +alias grep="grep -n${_coloroption}" # alias ll="ls -l" # alias la="ls -A" # alias lla="ls -Al" @@ -379,7 +373,7 @@ __my_battery_status(){ alias bat='__my_battery_status %s\\n' ip-address(){ - local ip=$(LANG=C ifconfig | grep "inet " | grep -v "127.0.0.1" | awk '{print $2}') + local ip=$(LANG=C ifconfig | grep --color=never "inet " | grep --color=never -v "127.0.0.1" | awk '{print $2}') test -n "$ip" && printf $1 $ip } @@ -420,12 +414,25 @@ __my_prompt_function(){ # used by PS1 __my_battery_status %s >$bst & fi # local battery=$(battery-state [%s] | sed -e 's`%`%%`g') # very slow + + __my_set_title + printf " [${c1}${pwd}${cdef}<${c3}${oldpwd}${cdef}]${git}${svn}${battery}${ip}\n" printf "${c2}${USER}@${HOSTNAME}${cdef} ${date}\n" printf "shlv:${SHLVL} jobs:${jobnum} last:${lastreturn} " +} + +__my_set_title(){ TERMTITLE="${USER}@${HOSTNAME} ${PWD}" - test -n "$DISPLAY" && test -z "$EMACS" && echo -n -e "\033]0;${TERMTITLE}\007" + case $TERM in + rxvt*|xterm*|aterm) + test -t 1 && + test -n "$DISPLAY" && + test -z "$EMACS" && + echo -n -e "\033]0;${TERMTITLE}\007" + ;; + esac } # from https://wiki.archlinux.org/index.php/X_resources diff --git a/emacs.el b/emacs.el index ba80136..6614580 100644 --- a/emacs.el +++ b/emacs.el @@ -31,9 +31,14 @@ (defun set-terminal-title (&rest args) "" (interactive "sString to set as title: ") - (send-string-to-terminal (apply 'concat - "\033]0;" - `(,@args "\007")))) + (let ((tty (or (frame-parameter nil + 'tty-type) + ""))) + (when (eq t (compare-strings "xterm" 0 5 tty 0 5)) + (send-string-to-terminal (apply 'concat + "\033]0;" + `(,@args "\007")))))) + (defun my-set-terminal-title () "" (set-terminal-title "[" @@ -44,16 +49,14 @@ (symbol-name system-type) "] " (abbreviate-file-name default-directory))) -(and (getenv "DISPLAY") - (not window-system) - (defvar old-directory default-directory) - (add-hook 'post-command-hook - (lambda () - (unless (eq old-directory default-directory) - (setq old-directory default-directory) - (my-set-terminal-title)))) - (add-hook 'suspend-resume-hook - 'my-set-terminal-title)) +(defvar previous-directory default-directory) +(add-hook 'post-command-hook + (lambda () + (unless (eq previous-directory default-directory) + (setq previous-directory default-directory) + (my-set-terminal-title)))) +(add-hook 'suspend-resume-hook + 'my-set-terminal-title) (defun buffer-list-not-start-with-space () (let ((bl (buffer-list))