Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

More efficient git parsing #83

Closed
wants to merge 23 commits into from

3 participants

@nojhan
Owner

No description provided.

Ludovic Rous... and others added some commits
Ludovic Rousseau Add support of /etc/debian_chroot
Debian uses the file /etc/debian_chroot to give a name to a chroot.
The default /etc/bash.bashrc contains:

if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fe4f983
Ludovic Rousseau Merge remote branch 'upstream/master' b78882a
Ludovic Rousseau Remove extra new line in case of SVN directory
Without the patch my prompt is (on 3 lines):
[rousseau:~/Documents/sc/nfc/libnfc]

svn ‡

With the patch my prompt is (on 1 line only):
[rousseau:~/Documents/sc/nfc/libnfc] svn ‡

This is because expr(1) adds a new line at the end of the result.
d870fc4
@nojhan Merge branch 'master' of https://github.com/LudovicRousseau/liquidprompt
 into develop
23f31f9
@nojhan clean chroot patch: add chroot for every connexions, modern test, loc…
…al variabls
0efdd9d
@nojhan add an example of sourcing theme and ps1 config 6db36ab
@nojhan Feature: blue @ when connected with X11 support
If the current connection supports X (if we are in a X session or if we have
enabled X11 forwarding under ssh), the @ displayed in front of the hostname
is colored in blue (use LP_COLOR_X11 to change the color).
5794c3a
@nojhan Better default host colorscheme
Add two color for the X11 support, green (support) and yellow (no support, not
set in red, because it is not a critical warning). The bold cyan of the hostname
was to close to the green of the colon and the @, change it to blue.
452ef22
@flepied flepied added support for python virtualenv 0a6d496
Christophe Drevet fix git in a directory containing spaces 337c473
@nojhan Merge branch 'master' of https://github.com/flepied/liquidprompt into…
… develop
cb598c1
@nojhan move virtual env function in the path section, move the display from …
…the front to the path section of the prompt, inside brackets, add flepied as an author, update the readme
45cdcdb
@nojhan fix issue #74 by adding an example bashrc 0375431
@nojhan Merge branch 'master' of https://github.com/jorisv/liquidprompt into …
…develop
0ac4e6b
@nojhan Merge branch 'fix_git_basename' of https://github.com/dr4Ke/liquidprompt
 into develop

Conflicts:
	liquidprompt
1bf7fd9
Christophe Drevet don't process VCS function if root
they do not appear in the result anyway, and they can be quite slow
d6c5f3c
Christophe Drevet LP_ENABLE_VCS_ROOT to enable use of VCS features with root a50b988
Christophe Drevet LP_PS1_PREFIX used to add arbitrary prompt before anything else db313ba
Christophe Drevet added a CUSTOMIZING THE PROMPT section 07e177e
@nojhan Merge branch 'ps1-prefix' of https://github.com/dr4Ke/liquidprompt in…
…to develop
af43ec0
@nojhan Default prefix put a classical prompt as title
Update the doc and themes accordingly
947781b
@dolmen dolmen git: fix variable leaks 942f41d
@dolmen dolmen _lp_git_branch: faster (less external programs calls) db86a65
@dolmen
Collaborator

Don't merge my code yet: it has an issue: I get a "" at the beginning of the prompt, and I still have to find out where it does come from.
Close this PR for now.
Note that I have rebased my branch fix/git on top of the latest develop in my repo.

@dolmen
Collaborator

The "" was not from liquidprompt: my .bashrc originally created by an old version of Ubuntu had a PROMPT_COMMAND set.

So it's now OK for a merge.
(but I have trouble understanding why Github shows 23 commits in the branch...)

@nojhan
Owner

I made this pull request just to remember that there was some interesting code somewhere :-)
There is too much commits here because github proposes the pull request on master by default and that I made the mistake of not changing the branch.
The easier solution is to close this one and let you open a new pull request on the correct branch.

@nojhan nojhan closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 27, 2012
  1. Add support of /etc/debian_chroot

    Ludovic Rousseau authored
    Debian uses the file /etc/debian_chroot to give a name to a chroot.
    The default /etc/bash.bashrc contains:
    
    if [ -z "${debian_chroot:-}" ] && [ -r /etc/debian_chroot ]; then
        debian_chroot=$(cat /etc/debian_chroot)
    fi
    
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
Commits on Sep 7, 2012
  1. Merge remote branch 'upstream/master'

    Ludovic Rousseau authored
Commits on Sep 8, 2012
  1. Remove extra new line in case of SVN directory

    Ludovic Rousseau authored
    Without the patch my prompt is (on 3 lines):
    [rousseau:~/Documents/sc/nfc/libnfc]
    
    svn ‡
    
    With the patch my prompt is (on 1 line only):
    [rousseau:~/Documents/sc/nfc/libnfc] svn ‡
    
    This is because expr(1) adds a new line at the end of the result.
Commits on Sep 9, 2012
Commits on Sep 23, 2012
  1. Feature: blue @ when connected with X11 support

    authored
    If the current connection supports X (if we are in a X session or if we have
    enabled X11 forwarding under ssh), the @ displayed in front of the hostname
    is colored in blue (use LP_COLOR_X11 to change the color).
Commits on Sep 25, 2012
  1. Better default host colorscheme

    authored
    Add two color for the X11 support, green (support) and yellow (no support, not
    set in red, because it is not a critical warning). The bold cyan of the hostname
    was to close to the green of the colon and the @, change it to blue.
Commits on Nov 3, 2012
  1. @flepied
Commits on Dec 6, 2012
  1. fix git in a directory containing spaces

    Christophe Drevet authored
Commits on Jan 3, 2013
  1. move virtual env function in the path section, move the display from …

    authored
    …the front to the path section of the prompt, inside brackets, add flepied as an author, update the readme
Commits on Jan 4, 2013
  1. Merge branch 'fix_git_basename' of https://github.com/dr4Ke/liquidprompt

    authored
     into develop
    
    Conflicts:
    	liquidprompt
  2. don't process VCS function if root

    Christophe Drevet authored
    they do not appear in the result anyway, and they can be quite slow
  3. LP_ENABLE_VCS_ROOT to enable use of VCS features with root

    Christophe Drevet authored
  4. added a CUSTOMIZING THE PROMPT section

    Christophe Drevet authored
  5. Default prefix put a classical prompt as title

    authored
    Update the doc and themes accordingly
Commits on Jan 8, 2013
  1. @dolmen

    git: fix variable leaks

    dolmen authored
  2. @dolmen
This page is out of date. Refresh to see the latest.
View
22 README.md
@@ -46,12 +46,14 @@ and bring it back with `fg`), if there is any;
any;
* the current user, in bold yellow if it is root, in light white if it is not
the same as the login user;
+* a blue @ if the connection has X11 support;
* the current host, if you are connected via an SSH or telnet connection, with
different colors for each case;
* a green colon if the user has write permissions on the current directory,
a red one if he has not;
* the current directory in bold, shortened if it takes too much space, while
preserving the first two directories;
+* the current Python virtual environment, if any;
* an up arrow if an HTTP proxy is in use;
* the name of the current branch if you are in a version control repository
(git, mercurial or subversion), in green if everything is up to date, in red if
@@ -120,6 +122,7 @@ building:
* `LP_ENABLE_GIT`, if you want to have git informations
* `LP_ENABLE_SVN`, if you want to have subversion informations
* `LP_ENABLE_HG`, if you want to have mercurial informations
+* `LP_ENABLE_VCS_ROOT`, if you want to show VCS informations with root account
Note that if required commands are not installed, enabling the
corresponding feature will have no effect.
@@ -127,11 +130,20 @@ Note also that all the `LP_ENABLE_…` variables override the templates,
i.e. if you use `$LP_BATT` in your template and you set `LP_ENABLE_BATT=0`
in your config file, you will not have the battery informations.
+## CUSTOMIZING THE PROMPT
-## PUT THE PROMPT IN A DIFFERENT ORDER
+### ADD A PS1 PREFIX
+
+You can prefix the `LP_PS1` variable with anything you want using the
+`LP_PS1_PREFIX`. The following example activate title change on xterm-like
+windows:
+
+ LP_PS1_PREFIX="\[\e]0;\u@\h: \w\a\]"
+
+### PUT THE PROMPT IN A DIFFERENT ORDER
You can sort what you want to see by sourcing your favorite template file
-(`*.ps1`), after having sourced the liquid prompt.
+(`*.ps1`) in the configuration file.
Those scripts basically export the `LP_PS1` variable, by appending features and
theme colors.
@@ -167,9 +179,7 @@ To erase your new formatting, just bring the `LP_PS1` to a null string:
## THEMES
You can change the colors and special characters of some part of the liquid
-prompt by sourcing your favorite theme file (`*.theme`), before having sourced
-the liquid prompt.
-
+prompt by sourcing your favorite theme file (`*.theme`) in the configuration file.
### COLORS
@@ -202,6 +212,8 @@ Set to a null string "" if you do not want color.
* `LP_COLOR_HOST` local host
* `LP_COLOR_SSH` connected via SSH
* `LP_COLOR_TELNET` connected via telnet
+ * `LP_COLOR_X11_ON` connected with X11 support
+ * `LP_COLOR_X11_OFF` connected without X11 support
* Separation mark (aka permiison in the working dir)
* `LP_COLOR_WRITE` have write permission
* `LP_COLOR_NOWRITE` do not have write permission
View
23 example.bashrc
@@ -0,0 +1,23 @@
+
+# if you want to use the liquidprompt without bothering about its configuration,
+# just:
+# cp example.bashrc ~/.bashrc
+
+# This part is a minimalist bash config file example
+
+# Use the system config if any
+if [ -f /etc/bashrc ]; then
+ . /etc/bashrc # --> Read /etc/bashrc, if present.
+fi
+
+# Use bash completion, if installed
+if [ -f /etc/bash_completion ]; then
+ . /etc/bash_completion
+fi
+
+# If you have your own config for the liquid prompt, edit and uncomment this line:
+# source /path/to/liquidpromptrc
+
+# Use the liquidprompt
+source ~/.liquidprompt
+
View
13 liquid.ps1
@@ -18,12 +18,13 @@
# LP_ERR last error code
# LP_MARK prompt mark
# LP_TIME current time
+# LP_PS1_PREFIX user-defined general-purpose prefix
# Remember that most features come with their corresponding colors,
# see the README.
-# add jobs, load and battery
-LP_PS1="${LP_TIME}${LP_BATT}${LP_LOAD}${LP_JOBS}"
+# add time, jobs, load and battery
+LP_PS1="${LP_PS1_PREFIX}${LP_TIME}${LP_BATT}${LP_LOAD}${LP_JOBS}"
# add user, host and permissions colon
LP_PS1="${LP_PS1}[${LP_USER}${LP_HOST}${LP_PERM}"
@@ -31,13 +32,15 @@ LP_PS1="${LP_PS1}[${LP_USER}${LP_HOST}${LP_PERM}"
if [[ "$EUID" -ne "0" ]]
then
# path in foreground color
- LP_PS1="${LP_PS1}${LP_PWD}]${LP_PROXY}"
+ LP_PS1="${LP_PS1}${LP_PWD}]${LP_VENV}${LP_PROXY}"
# add VCS infos
LP_PS1="${LP_PS1}${LP_GIT}${LP_HG}${LP_SVN}"
else
# path in yellow
- LP_PS1="${LP_PS1}${LP_PWD}]${LP_PROXY}"
- # do not add VCS infos
+ LP_PS1="${LP_PS1}${LP_PWD}]${LP_VENV}${LP_PROXY}"
+ # do not add VCS infos unless told otherwise (LP_ENABLE_VCS_ROOT)
+ [[ "$LP_ENABLE_VCS_ROOT" = "1" ]] && \
+ LP_PS1="${LP_PS1}${LP_GIT}${LP_HG}${LP_SVN}"
fi
# add return code and prompt mark
LP_PS1="${LP_PS1}${LP_ERR}${LP_MARK}"
View
7 liquid.theme
@@ -30,6 +30,9 @@ else
LP_MARK_UNTRACKED="*"
fi
+# Use the prefix to change the title of the terminal window
+LP_PS1_PREFIX="\[\e]0;\u@\h: \w\a\]"
+
# Colors
# Available colors are:
# BOLD, BLACK, BOLD_GRAY, WHITE, BOLD_WHITE,
@@ -63,8 +66,10 @@ LP_COLOR_USER_ROOT="$BOLD_YELLOW" # root
# Hostname
LP_COLOR_HOST="" # local host
-LP_COLOR_SSH="$BOLD_CYAN" # connected via SSH
+LP_COLOR_SSH="$BLUE" # connected via SSH
LP_COLOR_TELNET="$WARN_RED" # connected via telnet
+LP_COLOR_X11_ON="$GREEN" # connected with X11 support
+LP_COLOR_X11_OFF="$YELLOW" # connected without X11 support
# Separation mark (aka permiison in the working dir)
LP_COLOR_WRITE="$GREEN" # have write permission
View
73 liquidprompt
@@ -34,7 +34,7 @@
# Florian Le Frioux <florian@lefrioux.fr> # Use ± mark when root in VCS dir.
# Luc Didry <luc@fiat-tux.fr> # Zsh port
# Olivier Mengué <dolmen@cpan.org> # Major optimizations on host parsing
-
+# Frédéric Lepied # Python virtual env
# See the README.md file for a summary of features.
@@ -189,6 +189,7 @@ _lp_source_config()
LP_PATH_KEEP=${LP_PATH_KEEP:-2}
LP_HOSTNAME_ALWAYS=${LP_HOSTNAME_ALWAYS:-0}
LP_PS1=${LP_PS1:-""}
+ LP_PS1_PREFIX=${LP_PS1_PREFIX:-"\[\e]0;\u@\h: \w\a\]"}
LP_ENABLE_PERM=${LP_ENABLE_PERM:-1}
LP_ENABLE_SHORTEN_PATH=${LP_ENABLE_SHORTEN_PATH:-1}
@@ -200,6 +201,8 @@ _lp_source_config()
LP_ENABLE_SVN=${LP_ENABLE_SVN:-1}
LP_ENABLE_HG=${LP_ENABLE_HG:-1}
LP_ENABLE_TIME=${LP_ENABLE_TIME:-0}
+ LP_ENABLE_VIRTUALENV=${LP_ENABLE_VIRTUALENV:-1}
+ LP_ENABLE_VCS_ROOT=${LP_ENABLE_VCS_ROOT:-0}
LP_MARK_BATTERY=${LP_MARK_BATTERY:-"⌁"}
LP_MARK_ADAPTER=${LP_MARK_ADAPTER:-"⏚"}
@@ -223,8 +226,10 @@ _lp_source_config()
LP_COLOR_USER_ALT=${LP_COLOR_USER_ALT:-$BOLD}
LP_COLOR_USER_ROOT=${_ROOT:-$BOLD_YELLOW}
LP_COLOR_HOST=${LP_COLOR_HOST:-""}
- LP_COLOR_SSH=${LP_COLOR_SSH:-$BOLD_CYAN}
+ LP_COLOR_SSH=${LP_COLOR_SSH:-$BLUE}
LP_COLOR_TELNET=${LP_COLOR_TELNET:-$WARN_RED}
+ LP_COLOR_X11_ON=${LP_COLOR_X11:-$GREEN}
+ LP_COLOR_X11_OFF=${LP_COLOR_X11:-$YELLOW}
LP_COLOR_WRITE=${LP_COLOR_WRITE:-$GREEN}
LP_COLOR_NOWRITE=${LP_COLOR_NOWRITE:-$RED}
LP_COLOR_UP=${LP_COLOR_UP:-$GREEN}
@@ -331,22 +336,37 @@ _lp_connection()
# else diplay the host without color
# The connection is not expected to change from inside the shell, so we
# build this just once
+LP_HOST=""
+if [[ -r /etc/debian_chroot ]] ; then
+ local debchroot
+ debchroot=$(cat /etc/debian_chroot)
+ LP_HOST="${LP_HOST}(${debchroot})"
+fi
+
+# If we are connected with a X11 support
+if [[ -n "$DISPLAY" ]] ; then
+ LP_HOST="${LP_COLOR_X11_ON}${LP_HOST}@${NO_COL}"
+else
+ LP_HOST="${LP_COLOR_X11_OFF}${LP_HOST}@${NO_COL}"
+fi
+
case "$(_lp_connection)" in
lcl)
if [[ "$LP_HOSTNAME_ALWAYS" != 1 ]] ; then
+ # FIXME do we want to display the chroot if local?
LP_HOST="${NO_COL}" # no hostname if local
else
- LP_HOST="${NO_COL}@${LP_COLOR_HOST}${_LP_HOST_SYMBOL}${NO_COL}"
+ LP_HOST="${LP_HOST}${LP_COLOR_HOST}${_LP_HOST_SYMBOL}${NO_COL}"
fi
;;
ssh)
- LP_HOST="${NO_COL}@${LP_COLOR_SSH}${_LP_HOST_SYMBOL}${NO_COL}"
+ LP_HOST="${LP_HOST}${LP_COLOR_SSH}${_LP_HOST_SYMBOL}${NO_COL}"
;;
tel)
- LP_HOST="${NO_COL}@${LP_COLOR_TELNET}${_LP_HOST_SYMBOL}${NO_COL}"
+ LP_HOST="${LP_HOST}${LP_COLOR_TELNET}${_LP_HOST_SYMBOL}${NO_COL}"
;;
*)
- LP_HOST="${NO_COL}@${_LP_HOST_SYMBOL}" # defaults to no color
+ LP_HOST="${LP_HOST}${_LP_HOST_SYMBOL}" # defaults to no color
;;
esac
@@ -489,6 +509,13 @@ _lp_permissions_color()
fi
}
+# Display the current Python virtual environnement, if available.
+_lp_virtualenv()
+{
+ [[ "$LP_ENABLE_VIRTUALENV" != 1 ]] && return
+ [[ -n "$VIRTUAL_ENV" ]] && echo "[$(basename \"$VIRTUAL_ENV\")]"
+}
+
################
# Related jobs #
@@ -561,10 +588,11 @@ _lp_git_branch()
{
[[ "$LP_ENABLE_GIT" != 1 ]] && return
- topdir="$(git rev-parse --git-dir 2>/dev/null)"
- if [[ -n "$topdir" ]] && [[ "$(basename $topdir)" == '.git' ]] && [[ ! -z "$(git branch)" ]] ; then
- echo -n "$(git branch --no-color 2>/dev/null | sed -n '/^\*/s/^\* //p;')"
- fi
+ local gitdir="$(git rev-parse --git-dir 2>/dev/null)"
+ [[ $? -ne 0 || "${gitdir##*/}" != .git ]] && return
+ local branch="$(git symbolic-ref HEAD 2>/dev/null)"
+ [[ $? -ne 0 || -z "$branch" ]] && return
+ echo "${branch#refs/heads/}"
}
# Set a color depending on the branch state:
@@ -666,13 +694,15 @@ _lp_svn_branch()
[[ "$LP_ENABLE_SVN" != 1 ]] && return
local root
local url
+ local result
eval $(LANG=C LC_ALL=C svn info 2>/dev/null | sed -n 's/^URL: \(.*\)/url="\1"/p;s/^Repository Root: \(.*\)/root="\1"/p' )
# Make url relative to root
url="${url:${#root}}"
if [[ "$url" == */trunk* ]] ; then
echo trunk
else
- expr "$url" : '.*/branches/\([^/]*\)' || expr "$url" : '/\([^/]*\)' || basename "$root"
+ result=$(expr "$url" : '.*/branches/\([^/]*\)' || expr "$url" : '/\([^/]*\)' || basename "$root")
+ echo $result
fi
}
@@ -941,8 +971,6 @@ _lp_time()
echo -ne "${LP_COLOR_TIME}$(date +%H:%M:%S)${NO_COL}"
}
-
-
########################
# Construct the prompt #
########################
@@ -973,9 +1001,12 @@ _lp_set_prompt()
LP_PROXY="${LP_COLOR_PROXY}$(_lp_proxy)${NO_COL}"
# right of main prompt: space at left
- LP_GIT=$(_lp_sl "$(_lp_git_branch_color)")
- LP_HG=$(_lp_sl "$(_lp_hg_branch_color)")
- LP_SVN=$(_lp_sl "$(_lp_svn_branch_color)")
+ LP_VENV=$(_lp_sl "$(_lp_virtualenv)")
+ if [[ "$EUID" -ne "0" ]] || [[ "$LP_ENABLE_VCS_ROOT" = "1" ]] ; then
+ LP_GIT=$(_lp_sl "$(_lp_git_branch_color)")
+ LP_HG=$(_lp_sl "$(_lp_hg_branch_color)")
+ LP_SVN=$(_lp_sl "$(_lp_svn_branch_color)")
+ fi
# end of the prompt line: double spaces
LP_MARK=$(_lp_sb "$(_lp_smart_mark)")
@@ -989,7 +1020,7 @@ _lp_set_prompt()
if [[ -z $LP_PS1 ]] ; then
# add time, jobs, load and battery
- PS1="${LP_TIME}${LP_BATT}${LP_LOAD}${LP_JOBS}"
+ PS1="${LP_PS1_PREFIX}${LP_TIME}${LP_BATT}${LP_LOAD}${LP_JOBS}"
# add user, host and permissions colon
PS1="${PS1}[${LP_USER}${LP_HOST}${LP_PERM}"
@@ -997,13 +1028,15 @@ _lp_set_prompt()
if [[ "$EUID" -ne "0" ]]
then
# path in foreground color
- PS1="${PS1}${LP_PWD}]${LP_PROXY}"
+ PS1="${PS1}${LP_PWD}]${LP_VENV}${LP_PROXY}"
# add VCS infos
PS1="${PS1}${LP_GIT}${LP_HG}${LP_SVN}"
else
# path in yellow
- PS1="${PS1}${LP_PWD}]${LP_PROXY}"
- # do not add VCS infos
+ PS1="${PS1}${LP_PWD}]${LP_VENV}${LP_PROXY}"
+ # do not add VCS infos unless told otherwise (LP_ENABLE_VCS_ROOT)
+ [[ "$LP_ENABLE_VCS_ROOT" = "1" ]] && \
+ PS1="${PS1}${LP_GIT}${LP_HG}${LP_SVN}"
fi
# add return code and prompt mark
PS1="${PS1}${LP_ERR}${LP_MARK}"
View
9 liquidpromptrc-dist
@@ -3,6 +3,11 @@
# LIQUID PROMPT CONFIGURATION FILE #
####################################
+# If you want to use different themes and features,
+# you can load the corresponding files here:
+#source ~/code/liquidprompt/nojhan.theme
+#source ~/code/liquidprompt/nojhan.ps1
+
#############
# BEHAVIOUR #
#############
@@ -52,6 +57,10 @@ LP_ENABLE_LOAD=1
# Recommended value is 1
LP_ENABLE_BATT=1
+# Do you want to use vcs features with root account
+# Recommended value is 0
+LP_ENABLE_VCS_ROOT=0
+
# Do you want to use the git special features ?
# Recommended value is 1
LP_ENABLE_GIT=1
Something went wrong with that request. Please try again.