From 8fde415cb0609605f12e3e5a4942c75fbf2a7bf3 Mon Sep 17 00:00:00 2001 From: Leonid Volnitsky Date: Fri, 10 Jul 2009 16:21:51 +0300 Subject: fixed: cwd_truncate; label displas only last path dir --- Makefile | 21 ++++----------------- git-prompt.conf | 2 +- git-prompt.sh | 53 +++++++++++++++++++++++++++++++++++------------------ index.txt | 17 +++++++++++------ 4 files changed, 51 insertions(+), 42 deletions(-) diff --git a/Makefile b/Makefile index 0293330..5fb2098 100644 --- a/Makefile +++ b/Makefile @@ -1,25 +1,12 @@ +HOMEDIR ?= /home/lvv/p/volnitsky.com/ +include $(HOMEDIR)/include.mk +COPY_LIST = git-prompt.sh + install: cp -v git-prompt.sh /etc/ [ -f /etc/git-prompt.conf ] || cp -v git-prompt.conf /etc/ - tgit: xclip -i git-demo echo "ready to paste ..." -WEB_DESTDIR ?= /tmp/localweb -ASCIIDOC ?= asciidoc --unsafe - - -show: localweb - firefox $(WEB_DESTDIR)/index.html - -index.html: index.txt - $(ASCIIDOC) -o $@ $< - -localweb: index.html *.png git-prompt.sh - mkdir -p $(WEB_DESTDIR) - cp -uv $^ $(WEB_DESTDIR) - -clean: - rm -f *.html diff --git a/git-prompt.conf b/git-prompt.conf index a6eab1e..a49221e 100644 --- a/git-prompt.conf +++ b/git-prompt.conf @@ -50,7 +50,7 @@ # fi -##### Per host color. +##### Per host color ### Per host color. If not set, color will be derived from name of host checksum). ### Variable name is uppercase-short-hostname with appended "_host_color" diff --git a/git-prompt.sh b/git-prompt.sh index e5684fc..44dd6c8 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -139,6 +139,14 @@ return 0 fi + #################################################################### MARKERS + screen_marker="sCRn" + if [[ $LANG =~ "UTF" ]]; then + truncated_marker="..." + else + truncated_marker="..." # FIXME: replace with unicode elipse + fi + export who_where @@ -146,27 +154,39 @@ cwd_truncate() { # based on: https://www.blog.montgomerie.net/pwd-in-the-title-bar-or-a-regex-adventure-in-bash # TODO: never abbrivate last dir - [[ $truncate_pwd != "on" ]] && return + # arg1: max path lenght + # returns abbrivated $PWD in public "cwd" var + + case $1 in + full) + cwd=${PWD} + return + ;; + last) + cwd=${PWD##/*/} + return + ;; + *) + local cwd_max_length=$1 + cwd="$PWD" + ;; + esac - local pwd_length=$1 - # Get the current working directory. We'll format it in $dir. - local dir="$PWD" # Substitute a leading path that's in $HOME for "~" - if [[ "$HOME" == ${dir:0:${#HOME}} ]] ; then - dir="~${dir:${#HOME}}" + if [[ "$HOME" == ${cwd:0:${#HOME}} ]] ; then + cwd="~${cwd:${#HOME}}" fi # Append a trailing slash if it's not there already. - #if [[ ${dir:${#dir}-1} != "/" ]] ; then - # dir="$dir/" + #if [[ ${cwd:${#cwd}-1} != "/" ]] ; then + # cwd="$cwd/" #fi - # Truncate if we're too long. - # We preserve the leading '/' or '~/', and substitute + # Truncate if we're too long. We preserve the leading '/' or '~/', and substitute # ellipses for some directories in the middle. - if [[ "$dir" =~ (~){0,1}/.*(.{${pwd_length}}) ]] ; then + if [[ "$cwd" =~ (~){0,1}/.*(.{${cwd_max_length}}) ]] ; then local tilde=${BASH_REMATCH[1]} local directory=${BASH_REMATCH[2]} @@ -180,11 +200,9 @@ cwd_truncate() { # Can't work out if it's possible to use the Unicode ellipsis, # '…' (Unicode 2026). Directly embedding it in the string does not # seem to work, and \u escape sequences ('\u2026') are not expanded. - #printf -v dir "$tilde/\u2026$s", $directory" - dir="$tilde/...$directory" + #printf -v cwd "$tilde/\u2026$s", $directory" + cwd="$tilde/...$directory" fi - - cwd="$dir" } @@ -194,7 +212,7 @@ set_shell_title() { screen_title() { # FIXME: run this only if screen is in xterm (how to test for this?) - xterm_title "sCRn $label$plain_who_where $@" + xterm_title "$screen_marker $label$plain_who_where $@" # FIXME $STY not inherited though "su -" [ "$STY" ] && screen -S $STY -X title "$*" @@ -209,7 +227,6 @@ set_shell_title() { xterm* | rxvt* | gnome-terminal | konsole | eterm | wterm ) # is there a capability which we can to test # for "set term title-bar" and its escapes? - #echo -n "]2;$label$plain_who_where $1" xterm_title "$label$plain_who_where $@" ;; @@ -564,7 +581,7 @@ prompt_command_function() { rc="$rc_color$rc$colors_reset$bell " fi - set_shell_title "$PWD/" + set_shell_title "${PWD##/*/}/" # default label - path last dir parse_vcs_status # if cwd_cmd have back-slash, then assign it value to cwd diff --git a/index.txt b/index.txt index 3a05cf2..8038dbb 100644 --- a/index.txt +++ b/index.txt @@ -1,4 +1,4 @@ -// This is raw asciidoc file. The HTML rendered page is http://volnitsky.com/project/git-prompt +// This is raw asciidoc file. The HTML rendered page is at http://volnitsky.com/project/git-prompt = GIT Prompt @@ -160,7 +160,7 @@ Most of not optional dependencies are probably already installed on your compute == Todo * VCS exclude dir list -* new mail (howto at: `http://kikhome.net/?p=11` ) +* new mail (howto at: httpx://kikhome.net/?p=11[] ) * ctrl-Z subshell indicator * VIM module needs to be moved out of GIT module * How detect current merge? (current method through .git/MERGE_HEAD not always works) @@ -168,11 +168,16 @@ Most of not optional dependencies are probably already installed on your compute include::../volnitsky.com/project/howto-submit-patch.txt[] +People will hate any prompt if there will be delay in prompt display. +Try to avoid use of external commands and +subshells (backticks) in prompt_command_function. It is ok to use +timeconsuming ops in postconfig which is executed only once. + == Authors -- Leonid Volnitsky (original author) http://volnitsky.com -- Niklas Hofer (CWD truncation) http://github.com/niklas/ -- Lee Nussbaum (HG support) lee.nussbaum@gmail.com http://github.com/wln -- Albert Vernon http://xenoclub.wordpress +- Leonid Volnitsky (original author) , http://volnitsky.com +- Niklas Hofer (CWD truncation) , http://github.com/niklas/ +- Lee Nussbaum (HG support) lee.nussbaum@gmail.com, http://github.com/wln +- Albert Vernon http://xenoclub.wordpress.com[] [bibliography] -- cgit v1.2.3