summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--color-test19
-rwxr-xr-xgit-logc67
-rwxr-xr-xgit-prompt.sh136
-rw-r--r--upstream-remote1
4 files changed, 159 insertions, 64 deletions
diff --git a/color-test b/color-test
new file mode 100644
index 0000000..4f30a0e
--- /dev/null
+++ b/color-test
@@ -0,0 +1,19 @@
+#!/bin/bash
+reset=`tput sgr0`
+c=`tput sgr0; tput setaf 0`;echo "-black-${c}testTEST${reset}"
+c=`tput sgr0; tput setaf 1`;echo "-red-${c}testTEST${reset}"
+c=`tput sgr0; tput setaf 2`;echo "-green-${c}testTEST${reset}"
+c=`tput sgr0; tput setaf 3`;echo "-yellow-${c}testTEST${reset}"
+c=`tput sgr0; tput setaf 4`;echo "-blue-${c}testTEST${reset}"
+c=`tput sgr0; tput setaf 5`;echo "-magenta-${c}testTEST${reset}"
+c=`tput sgr0; tput setaf 6`;echo "-cyan-${c}testTEST${reset}"
+c=`tput sgr0; tput setaf 7`;echo "-white-${c}testTEST${reset}"
+
+c=`tput setaf 0; tput bold`;echo "-BLACK-${c}testTEST${reset}"
+c=`tput setaf 1; tput bold`;echo "-RED-${c}testTEST${reset}"
+c=`tput setaf 2; tput bold`;echo "-GREEN-${c}testTEST${reset}"
+c=`tput setaf 3; tput bold`;echo "-YELLOW-${c}testTEST${reset}"
+c=`tput setaf 4; tput bold`;echo "-BLUE-${c}testTEST${reset}"
+c=`tput setaf 5; tput bold`;echo "-MAGENTA-${c}testTEST${reset}"
+c=`tput setaf 6; tput bold` # why 14 doesn't work?;echo "-CYAN-${c}testTEST${reset}"
+c=`tput setaf 7; tput bold`;echo "-WHITE-${c}testTEST${reset}"
diff --git a/git-logc b/git-logc
new file mode 100755
index 0000000..147b1e3
--- /dev/null
+++ b/git-logc
@@ -0,0 +1,67 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use 5.014;
+use Term::ANSIColor ':constants';
+
+my $tty=-t STDOUT;
+$ENV{ANSI_COLORS_DISABLED}=1 unless $tty;
+
+sub parse_line {
+ my ($line) = @_;
+
+ my ($graph,$hash,$decor,$date,$name,$subj) = split /\0/,$line;
+ return $graph unless defined $hash;
+ $decor =~ s{^\s+\(|\)$}{}g;
+ my @decors = split /, /,$decor;
+ return $graph,$hash,\@decors,$date,$name,$subj;
+}
+
+sub class_decor {
+ my ($decor) = @_;
+
+ my $colour=BRIGHT_BLUE;
+ if ($decor eq 'HEAD') {
+ $colour=BRIGHT_CYAN;
+ }
+ elsif ($decor =~ s{^(?:tag: )?refs/tags/}{tag: }) {
+ $colour=BRIGHT_YELLOW;
+ }
+ elsif ($decor =~ s{^refs/remotes/}{}) {
+ $colour=BRIGHT_RED;
+ }
+ elsif ($decor =~ s{^refs/heads/}{}) {
+ $colour=BRIGHT_GREEN;
+ }
+ return $colour,$decor;
+}
+
+open my $fh,'-|','git','log',@ARGV,'--graph','--decorate=full','--pretty=format:%x00%h%x00%d%x00%ar%x00%aN%x00%s',($tty ? '--color=always' : ());
+my $out;
+if ($tty) {
+ open $out,'|-','less';
+ $SIG{PIPE}=sub{exit 0};
+}
+else {
+ open $out,'>&',\*STDOUT;
+}
+
+while (my $line = <$fh>) {
+ my ($graph,$hash,$decors,$date,$name,$subj) = parse_line($line);
+ if (not defined $hash) {
+ print $out $graph;
+ next;
+ }
+
+ my $ret = $graph.YELLOW."$hash ".RESET;
+
+ if (@$decors) {
+ $ret .= '('. join(', ',map {
+ my ($col,$str) = class_decor($_);
+ BOLD.$col.$str.RESET
+ }
+ @$decors).') '
+ }
+ $ret .= RED."[$date]".RESET." ".GREEN."$name".RESET." $subj";
+ print $out $ret;
+}
diff --git a/git-prompt.sh b/git-prompt.sh
index d1e88b3..1eed094 100755
--- a/git-prompt.sh
+++ b/git-prompt.sh
@@ -9,6 +9,7 @@
# clear vars from previous invocation
unset dir_color rc_color user_id_color root_id_color init_vcs_color clean_vcs_color
+ unset prompt_color jobs_color time_color
unset modified_vcs_color added_vcs_color addmoded_vcs_color untracked_vcs_color op_vcs_color detached_vcs_color hex_vcs_color
unset rawhex_len
@@ -39,10 +40,13 @@
#### dir, rc, root color
- cols=`tput colors` # in emacs shell-mode tput colors returns -1
+ cols="$(tput colors)" # in emacs shell-mode tput colors returns -1
if [[ -n "$cols" && $cols -ge 8 ]]; then # if terminal supports colors
dir_color=${dir_color:-CYAN}
+ time_color=${time_color:-BLUE}
rc_color=${rc_color:-red}
+ jobs_color=${jobs_color:-cyan}
+ prompt_color=${prompt_color:-CYAN}
virtualenv_color=${virtualenv_color:-green}
user_id_color=${user_id_color:-blue}
root_id_color=${root_id_color:-magenta}
@@ -53,8 +57,8 @@
unset cols
#### prompt character, for root/non-root
- prompt_char=${prompt_char:-'>'}
- root_prompt_char=${root_prompt_char:-'>'}
+ prompt_char="${prompt_char:-'>'}"
+ root_prompt_char="${root_prompt_char:-'>'}"
#### vcs colors
init_vcs_color=${init_vcs_color:-WHITE} # initial
@@ -75,7 +79,7 @@
count_only=${count_only:-off}
rawhex_len=${rawhex_len:-5}
- aj_max=20
+ aj_max=${aj_max:-20}
##################################################################### post config
@@ -113,32 +117,32 @@
### if term support colors, then use color prompt, else bold
- black='\['`tput sgr0; tput setaf 0`'\]'
- red='\['`tput sgr0; tput setaf 1`'\]'
- green='\['`tput sgr0; tput setaf 2`'\]'
- yellow='\['`tput sgr0; tput setaf 3`'\]'
- blue='\['`tput sgr0; tput setaf 4`'\]'
- magenta='\['`tput sgr0; tput setaf 5`'\]'
- cyan='\['`tput sgr0; tput setaf 6`'\]'
- white='\['`tput sgr0; tput setaf 7`'\]'
+ black='\['"$(tput sgr0; tput setaf 0)"'\]'
+ red='\['"$(tput sgr0; tput setaf 1)"'\]'
+ green='\['"$(tput sgr0; tput setaf 2)"'\]'
+ yellow='\['"$(tput sgr0; tput setaf 3)"'\]'
+ blue='\['"$(tput sgr0; tput setaf 4)"'\]'
+ magenta='\['"$(tput sgr0; tput setaf 5)"'\]'
+ cyan='\['"$(tput sgr0; tput setaf 6)"'\]'
+ white='\['"$(tput sgr0; tput setaf 7)"'\]'
- BLACK='\['`tput setaf 0; tput bold`'\]'
- RED='\['`tput setaf 1; tput bold`'\]'
- GREEN='\['`tput setaf 2; tput bold`'\]'
- YELLOW='\['`tput setaf 3; tput bold`'\]'
- BLUE='\['`tput setaf 4; tput bold`'\]'
- MAGENTA='\['`tput setaf 5; tput bold`'\]'
- CYAN='\['`tput setaf 6; tput bold`'\]'
- WHITE='\['`tput setaf 7; tput bold`'\]'
+ BLACK='\['"$(tput setaf 0; tput bold)"'\]'
+ RED='\['"$(tput setaf 1; tput bold)"'\]'
+ GREEN='\['"$(tput setaf 2; tput bold)"'\]'
+ YELLOW='\['"$(tput setaf 3; tput bold)"'\]'
+ BLUE='\['"$(tput setaf 4; tput bold)"'\]'
+ MAGENTA='\['"$(tput setaf 5; tput bold)"'\]'
+ CYAN='\['"$(tput setaf 6; tput bold)"'\]'
+ WHITE='\['"$(tput setaf 7; tput bold)"'\]'
- dim='\['`tput sgr0; tput setaf p1`'\]' # half-bright
+ dim='\['"$(tput sgr0; tput setaf p1)"'\]' # half-bright
- bw_bold='\['`tput bold`'\]'
+ bw_bold='\['"$(tput bold)"'\]'
on=''
off=': '
- bell="\[`eval ${!error_bell} tput bel`\]"
- colors_reset='\['`tput sgr0`'\]'
+ bell="\["$(eval ${!error_bell} tput bel)"\]"
+ colors_reset='\['"$(tput sgr0)"'\]'
# replace symbolic colors names to raw treminfo strings
init_vcs_color=${!init_vcs_color}
@@ -162,6 +166,7 @@
fi
#################################################################### MARKERS
+ screen_marker="sCRn"
if [[ "$LC_CTYPE $LC_ALL" =~ "UTF" && $TERM != "linux" ]]; then
elipses_marker="…"
else
@@ -209,7 +214,7 @@ cwd_truncate() {
if [[ ${#path_middle} -gt $(( $cwd_middle_max + ${#elipses_marker} + 5 )) ]]; then
# truncate
- middle_tail=${path_middle:${#path_middle}-${cwd_middle_max}}
+ middle_tail="${path_middle:${#path_middle}-${cwd_middle_max}}"
# trunc on dir boundary (trunc 1st, probably tuncated dir)
[[ $middle_tail =~ '[^/]*/(.*)$' ]]
@@ -217,7 +222,7 @@ cwd_truncate() {
# use truncated only if we cut at least 4 chars
if [[ $(( ${#path_middle} - ${#middle_tail})) -gt 4 ]]; then
- cwd=$path_head$elipses_marker$middle_tail$path_last_dir
+ cwd="$path_head$elipses_marker$middle_tail$path_last_dir"
fi
fi
fi
@@ -234,7 +239,7 @@ set_shell_label() {
screen_label() {
# FIXME: run this only if screen is in xterm (how to test for this?)
- xterm_label "$plain_who_where $@"
+ xterm_label "$screen_marker $plain_who_where $@"
# FIXME $STY not inherited though "su -"
[ "$STY" ] && screen -S $STY -X title "$*"
@@ -263,13 +268,13 @@ set_shell_label() {
export -f set_shell_label
###################################################### ID (user name)
- id=`id -un`
- id=${id#$default_user}
+ id="$(id -un)"
+ id="${id#$default_user}"
########################################################### TTY
- tty=`tty`
- tty=`echo $tty | sed "s:/dev/pts/:p:; s:/dev/tty::" ` # RH tty devs
- tty=`echo $tty | sed "s:/dev/vc/:vc:" ` # gentoo tty devs
+ tty="$(tty)"
+ tty="$(echo $tty | sed "s:/dev/pts/:p:; s:/dev/tty::")" # RH tty devs
+ tty="$(echo $tty | sed "s:/dev/vc/:vc:")" # gentoo tty devs
if [[ "$TERM" = "screen" ]] ; then
@@ -288,7 +293,10 @@ set_shell_label() {
esac
dir_color=${!dir_color}
+ time_color=${!time_color}
rc_color=${!rc_color}
+ prompt_color=${!prompt_color}
+ jobs_color=${!jobs_color}
virtualenv_color=${!virtualenv_color}
user_id_color=${!user_id_color}
root_id_color=${!root_id_color}
@@ -299,19 +307,19 @@ set_shell_label() {
# How to find out if session is local or remote? Working with "su -", ssh-agent, and so on ?
## is sshd our parent?
- # if { for ((pid=$$; $pid != 1 ; pid=`ps h -o pid --ppid $pid`)); do ps h -o command -p $pid; done | grep -q sshd && echo == REMOTE ==; }
+ # if { for ((pid=$$; $pid != 1 ; pid="$(ps h -o pid --ppid $pid)")); do ps h -o command -p $pid; done | grep -q sshd && echo == REMOTE ==; }
#then
host=${HOSTNAME}
if [[ $short_hostname = "on" ]]; then
if [[ "$(uname)" =~ "CYGWIN" ]]; then
- host=`hostname`
+ host="$(hostname)"
else
- host=`hostname -s`
+ host="$(hostname -s)"
fi
fi
host=${host#$default_host}
- uphost=`echo ${host} | tr a-z-. A-Z_`
+ uphost="$(echo ${host} | tr a-z-. A-Z_)"
if [[ $upcase_hostname = "on" ]]; then
host=${uphost}
fi
@@ -319,7 +327,7 @@ set_shell_label() {
host_color=${uphost}_host_color
host_color=${!host_color}
if [[ -z $host_color && -x /usr/bin/cksum ]] ; then
- cksum_color_no=`echo $uphost | cksum | awk '{print $1%6}'`
+ cksum_color_no="$(echo $uphost | cksum | awk '{print $1%6}')"
color_index=(green yellow blue magenta cyan white) # FIXME: bw, color-256
host_color=${color_index[cksum_color_no]}
fi
@@ -331,11 +339,11 @@ set_shell_label() {
#################################################################### WHO_WHERE
# [[user@]host[-tty]]
-
- if [[ -n $id || -n $host ]] ; then
+
+ if [[ -n $id || -n $host || -n $special_env ]] ; then
[[ -n $id && -n $host ]] && at='@' || at=''
- color_who_where="${id}${host:+$host_color$at$host}${tty:+ $tty}"
- plain_who_where="${id}$at$host"
+ color_who_where="${special_env:+($special_env) }${id}${host:+$host_color$at$host}${tty:+ $tty}"
+ plain_who_where="${special_env:+($special_env) }${id}$at$host"
# add trailing " "
color_who_where="$color_who_where "
@@ -359,23 +367,23 @@ parse_svn_status() {
vcs=svn
### get rev
- eval `
+ eval "$(
svn info |
sed -n "
s@^URL[^/]*//@repo_dir=@p
s/^Revision: /rev=/p
"
- `
+ )"
### get status
unset status modified added clean init added mixed untracked op detached
- eval `svn status 2>/dev/null |
+ eval "$(svn status 2>/dev/null |
sed -n '
s/^A... \([^.].*\)/modified=modified; modified_files[${#modified_files[@]}]=\"\1\";/p
s/^M... \([^.].*\)/modified=modified; modified_files[${#modified_files[@]}]=\"\1\";/p
s/^\?... \([^.].*\)/untracked=untracked; untracked_files[${#untracked_files[@]}]=\"\1\";/p
'
- `
+ )"
# TODO branch detection if standard repo layout
[[ -z $modified ]] && [[ -z $untracked ]] && clean=clean
@@ -392,16 +400,16 @@ parse_hg_status() {
### get status
unset status modified added clean init added mixed untracked op detached
- eval `hg status 2>/dev/null |
+ eval "$(hg status 2>/dev/null |
sed -n '
s/^M \([^.].*\)/modified=modified; modified_files[${#modified_files[@]}]=\"\1\";/p
s/^A \([^.].*\)/added=added; added_files[${#added_files[@]}]=\"\1\";/p
s/^R \([^.].*\)/added=added;/p
s/^! \([^.].*\)/modified=modified;/p
s/^? \([^.].*\)/untracked=untracked; untracked_files[${#untracked_files[@]}]=\\"\1\\";/p
- '`
+ ')"
- branch=`hg branch 2> /dev/null`
+ branch="$(hg branch 2> /dev/null)"
[[ -f $hg_root/.hg/bookmarks.current ]] && bookmark=`cat "$hg_root/.hg/bookmarks.current"`
@@ -418,9 +426,9 @@ parse_git_status() {
# TODO add status: LOCKED (.git/index.lock)
- git_dir=`[[ $git_module = "on" ]] && git rev-parse --git-dir 2> /dev/null`
- #git_dir=`eval \$$git_module git rev-parse --git-dir 2> /dev/null`
- #git_dir=` git rev-parse --git-dir 2> /dev/null`
+ git_dir="$([[ $git_module = "on" ]] && git rev-parse --git-dir 2> /dev/null)"
+ #git_dir="$(eval \$$git_module git rev-parse --git-dir 2> /dev/null)"
+ #git_dir="$( git rev-parse --git-dir 2> /dev/null)"
[[ -n ${git_dir/./} ]] || return 1
@@ -521,7 +529,7 @@ parse_git_status() {
#### GET GIT HEX-REVISION
if [[ $rawhex_len -gt 0 ]] ; then
- rawhex=`git rev-parse HEAD 2>/dev/null`
+ rawhex="$(git rev-parse HEAD 2>/dev/null)"
rawhex=${rawhex/HEAD/}
rawhex="$hex_vcs_color${rawhex:0:$rawhex_len}"
else
@@ -542,7 +550,7 @@ parse_git_status() {
else
if [[ "$detached" ]] ; then
- branch="<detached:`git name-rev --name-only HEAD 2>/dev/null`"
+ branch="<detached:$(git name-rev --name-only HEAD 2>/dev/null)"
elif [[ "$op" ]]; then
@@ -590,9 +598,9 @@ parse_vcs_status() {
if [[ $vim_module = "on" ]] ; then
# equivalent to vim_glob=`ls .*.vim` but without running ls
unset vim_glob vim_file vim_files
- old_nullglob=`shopt -p nullglob`
+ old_nullglob="$(shopt -p nullglob)"
shopt -s nullglob
- vim_glob=`echo .*.sw?`
+ vim_glob="$(echo .*.sw?)"
eval $old_nullglob
if [[ $vim_glob ]]; then
@@ -659,8 +667,8 @@ disable_set_shell_label() {
enable_set_shell_label() {
disable_set_shell_label
# check for BASH_SOURCE being empty, no point running set_shell_label on every line of .bashrc
- trap '[[ -z "$BASH_SOURCE" && ($BASH_COMMAND != prompt_command_function) ]] &&
- set_shell_label $BASH_COMMAND' DEBUG >& /dev/null
+ trap '[[ "$BASH_COMMAND" != prompt_command_function ]] &&
+ set_shell_label "$BASH_COMMAND"' DEBUG >& /dev/null
}
declare -ft disable_set_shell_label
@@ -692,15 +700,13 @@ alias jumpstart='echo ${aj_dir_list[@]}'
prompt_command_function() {
rc="$?"
- if [[ "$rc" == "0" ]]; then
- rc=""
- else
- rc="$rc_color$rc$colors_reset$bell "
- fi
+ rc="$rc_color($rc)$colors_reset"
- cwd=${PWD/$HOME/\~} # substitute "~"
+ cwd="${PWD/$HOME/~}" # substitute "~"
set_shell_label "${cwd##[/~]*/}/" # default label - path last dir
+ timestamp="$(date -Iseconds)"
+
parse_virtualenv_status
parse_vcs_status
@@ -713,7 +719,9 @@ prompt_command_function() {
# else eval cwd_cmd, cwd should have path after exection
eval "${cwd_cmd/\\/cwd=\\\\}"
- PS1="$colors_reset$rc$head_local$color_who_where$dir_color$cwd$tail_local$dir_color$prompt_char $colors_reset"
+ jobs="$jobs_color[\j]$jobs_color"
+
+ PS1="$colors_reset$time_color$timestamp$colors_reset\n$color_who_where$dir_color$cwd $head_local$colors_reset\n$rc$jobs$prompt_color$prompt_char $colors_reset"
unset head_local tail_local pwd
}
diff --git a/upstream-remote b/upstream-remote
new file mode 100644
index 0000000..41d86c0
--- /dev/null
+++ b/upstream-remote
@@ -0,0 +1 @@
+origin git://github.com/lvv/git-prompt.git