diff options
-rwxr-xr-x | git-prompt.sh | 96 | ||||
-rw-r--r-- | index.txt | 35 |
2 files changed, 59 insertions, 72 deletions
diff --git a/git-prompt.sh b/git-prompt.sh index 53e01bd..d3e8ec4 100755 --- a/git-prompt.sh +++ b/git-prompt.sh @@ -137,10 +137,10 @@ #################################################################### MARKERS screen_marker="sCRn" - if [[ $LANG =~ "UTF" ]]; then - truncated_marker="…" + if [[ $LANG =~ "UTF" && $TERM != "linux" ]]; then + elipses_marker="…" else - truncated_marker="..." + elipses_marker="..." fi export who_where @@ -161,7 +161,7 @@ cwd_truncate() { ;; last) cwd=${PWD##/*/} - [[ $PWD == $HOME ]] && cwd="~" + [[ $PWD == $HOME ]] && cwd="~" return ;; *) @@ -171,17 +171,19 @@ cwd_truncate() { # split path into: head='~/', truncapable middle, last_dir if [[ "$cwd" =~ (~?/)(.*)/([^/]*) ]] ; then # only valid if path have more then 1 dir - path_head=${BASH_REMATCH[1]} - path_middle=${BASH_REMATCH[2]} - path_last_dir=${BASH_REMATCH[3]} + local path_head=${BASH_REMATCH[1]} + local path_middle=${BASH_REMATCH[2]} + local path_last_dir=${BASH_REMATCH[3]} # if middle is too long, truncate + local cwd_middle_max=$(( $cwd_max_length - ${#path_last_dir} )) + [[ $cwd_middle_max < 0 ]] && cwd_middle_max=0 - cwd_middle_max=$(($cwd_max_length +${#truncated_marker}+1 - ${#path_last_dir})) - [[ $cwd_middle_max < 0 ]] && cwd_middle_max=0 - if [[ $path_middle =~ (.{$(($cwd_middle_max))})$ ]]; then - cwd=$path_head$truncated_marker${BASH_REMATCH[1]}/$path_last_dir + if [[ $(( ${#path_middle} > $cwd_middle_max+${#elipses_marker} + 2)) ]]; then # if it will trunc at least 2 chars + if [[ $path_middle =~ (.{$(($cwd_middle_max))})$ ]]; then + cwd=$path_head$elipses_marker${BASH_REMATCH[1]}/$path_last_dir + fi fi fi return @@ -369,40 +371,40 @@ parse_git_status() { unset status modified added clean init added mixed untracked op detached eval ` git status 2>/dev/null | - sed -n ' - s/^# On branch /branch=/p - s/^nothing to commit (working directory clean)/clean=clean/p - s/^# Initial commit/init=init/p - - s/^# \.\./: SKIP/ - - /^# Untracked files:/,/^[^#]/{ - s/^# Untracked files:/untracked=untracked;/p - s/^# \(.*\)/untracked_files[${#untracked_files[@]}+1]=\\"\1\\"/p - } - - /^# Changed but not updated:/,/^# [A-Z]/ { - s/^# Changed but not updated:/modified=modified;/p - s/^# modified: \.\./: SKIP/ - s/^# modified: \(.*\)/modified_files[${#modified_files[@]}+1]=\"\1\"/p - s/^# unmerged: \.\./: SKIP/ - s/^# unmerged: \(.*\)/modified_files[${#modified_files[@]}+1]=\"\1\"/p - } - - /^# Changes to be committed:/,/^# [A-Z]/ { - s/^# Changes to be committed:/added=added;/p - - s/^# modified: \.\./: SKIP/ - s/^# new file: \.\./: SKIP/ - s/^# renamed:[^>]*> \.\./: SKIP/ - s/^# copied:[^>]*> \.\./: SKIP/ - - s/^# modified: \(.*\)/added_files[${#added_files[@]}+1]=\"\1\"/p - s/^# new file: \(.*\)/added_files[${#added_files[@]}+1]=\"\1\"/p - s/^# renamed:[^>]*> \(.*\)/added_files[${#added_files[@]}+1]=\"\1\"/p - s/^# copied:[^>]*> \(.*\)/added_files[${#added_files[@]}+1]=\"\1\"/p - } - ' + sed -n ' + s/^# On branch /branch=/p + s/^nothing to commit (working directory clean)/clean=clean/p + s/^# Initial commit/init=init/p + + s/^# \.\./: SKIP/ + + /^# Untracked files:/,/^[^#]/{ + s/^# Untracked files:/untracked=untracked;/p + s/^# \(.*\)/untracked_files[${#untracked_files[@]}+1]=\\"\1\\"/p + } + + /^# Changed but not updated:/,/^# [A-Z]/ { + s/^# Changed but not updated:/modified=modified;/p + s/^# modified: \.\./: SKIP/ + s/^# modified: \(.*\)/modified_files[${#modified_files[@]}+1]=\"\1\"/p + s/^# unmerged: \.\./: SKIP/ + s/^# unmerged: \(.*\)/modified_files[${#modified_files[@]}+1]=\"\1\"/p + } + + /^# Changes to be committed:/,/^# [A-Z]/ { + s/^# Changes to be committed:/added=added;/p + + s/^# modified: \.\./: SKIP/ + s/^# new file: \.\./: SKIP/ + s/^# renamed:[^>]*> \.\./: SKIP/ + s/^# copied:[^>]*> \.\./: SKIP/ + + s/^# modified: \(.*\)/added_files[${#added_files[@]}+1]=\"\1\"/p + s/^# new file: \(.*\)/added_files[${#added_files[@]}+1]=\"\1\"/p + s/^# renamed:[^>]*> \(.*\)/added_files[${#added_files[@]}+1]=\"\1\"/p + s/^# copied:[^>]*> \(.*\)/added_files[${#added_files[@]}+1]=\"\1\"/p + } + ' ` if ! grep -q "^ref:" $git_dir/HEAD 2>/dev/null; then @@ -537,7 +539,7 @@ parse_vcs_status() { if [[ ${#file_list} -gt $max_file_list_length ]] ; then file_list=${file_list:0:$max_file_list_length} if [[ $max_file_list_length -gt 0 ]] ; then - file_list="${file_list% *} ..." + file_list="${file_list% *} $elipses_marker" fi fi @@ -584,4 +586,4 @@ prompt_command_function() { unset rc id tty modified_files file_list -# vim: set ft=sh ts=8 sw=8 et: +# vim: set ft=sh ts=8 sw=8: @@ -51,7 +51,8 @@ Labels are visual cues to help figure out what terminal is running what command. It is generalization of xterm-title but differ from xterm-title that it can be displayed in other places (on Screen(1) windows titles for example). Also label can display currently executed command (when bash prompt obviously -is not displayed). +is not displayed). Because labels have less space then prompt, instead of path +only last dir in path is shown. On screenshot below labels are in red ovals. image:screenshot-labels.png["labels screenshot", width="300", link="screenshot-labels.png"] @@ -63,26 +64,6 @@ following line in `~/.screenrc`: caption always "%{= kw}%-w%{= bw}%n %t%{-}%+w %-= @%H - %LD %d %LM - %c" --------- -////////////////// -We don't need to do any thing for something like `cd` or `ssh` (if you have -git-prompt on remote host). -For external command we need set label before it is executed. -It would be simple if `bash` set command name to some variable before execution, -but it does not do this. So we have to use wrappers. This is not very elegant -and will work only for commands with defined wrapper. -I use wrapper only for `vim` and `man` in my `~/.bashrc` - -------------------------- -vi() { set_shell_title "vi $@"; /usr/bin/vim -p "$@"; }; export -f vi -man() { set_shell_title "man $@"; /usr/bin/man "$@"; }; export -f man ----------------------------- - -Note that vim sets xterm title , but we still use wrapper so that -`screen` will have labels too. -Function `set_shell_title` defined in `git-prompt.sh`. -/////////////////// - - == Install Download link:git-prompt.sh[] or get it with GIT: @@ -127,11 +108,11 @@ to any of above locations and customize as needed. * cd-ing into something like linux kernel git working directory for the 1st time (with cold cache) might take up to 10 seconds (that is how long `git status` executes). -* Because you will be always reminded about not checked-in files, - it will force you to keep working directory clean, better maintain `.gitignore` and commit more often. +* Because you will be always reminded about dirty repo (not checked-in files), + you will better maintain `.gitignore` and commit more often. * This prompt is most useful if your screen have enough width. If this is not the case, you might want to disable file list display (`max_file_list_length=0`). -* When prompt is longer then screen-width it wraps to second line. +* When prompt is longer then screen-width it wraps to second line. This is always undesirable. Because of bug in `gnome-terminal` (or `readline` ?) some color escape codes can be visible on second line. I've reported gnome-terminal bug. Again, you can disable file list display or limit length (`max_file_list_length`). * By default some terminals display ascii color with maximum color saturation @@ -160,10 +141,14 @@ Most of not optional dependencies are probably already installed on your compute == Todo * VCS exclude dir list +* option for hash/pound marker when `$USER=="root"` * new mail (howto at: httpx://kikhome.net/?p=11[] ) -* ctrl-Z subshell indicator +* Subshells number indicator. Don't know how to do this. There is bash + `"\j"`, but let say I want `">>"` after path instead of `">"` when I have 2 jobs (including current) + running. Running `+++`jobs | ... `+++` is extra bash fork, hate to do this. * VIM module needs to be moved out of GIT module * How detect current merge? (current method through .git/MERGE_HEAD not always works) +* git lock-ed state include::../volnitsky.com/project/howto-submit-patch.txt[] |