Commit Graph

478 Commits

Author SHA1 Message Date
Olivier Mengué
782fad08fd Save IFS at startup to restore it in _lp_set_prompt
We already restore IFS to its default value. This patch only changes the
way it is done to avoid a call to 'echo' in a sub-shell at runtime.
Fixes #267.
2014-01-22 22:56:48 +01:00
François Schmidts
89540d3125 replacing replacing "git status" option "--short" by "--porcelain"
The behavior of porcelain seems more adapted to the liquidprompt usage

From the "git status" documentation :

The porcelain format is similar to the short format, but is guaranteed
not to change in a backwards-incompatible way between git versions or
based on user configuration. This makes it ideal for parsing by scripts.
The description of the short format above also describes the porcelain
format, with a few exceptions:

1. The user’s color.status configuration is not respected;
   color will always be off.
[...]
2014-01-22 16:48:26 +01:00
François Schmidts
6c012c28d6 fixing the untracked flag being always up 2014-01-22 16:47:58 +01:00
Anthony Gelibert
f6a9bdeee9 has_commit is an integer. 2014-01-22 09:42:51 +01:00
Anthony Gelibert
b5830cdf28 Reduce the verbosity of git calls. 2014-01-22 09:42:33 +01:00
Anthony Gelibert
a61e382bb2 Replace "pmset -g batt" parsing. 2014-01-22 09:38:30 +01:00
Anthony Gelibert
3f1df58ae5 Respect the _lp_battery API. 2014-01-22 09:38:08 +01:00
Anthony Gelibert
10121e3d13 Rename misnamed local variable. 2014-01-22 09:34:46 +01:00
Anthony Gelibert
c9bdefe020 Quote $LP_MARK_DEFAULT to avoid problem with space. 2014-01-22 09:32:26 +01:00
Olivier Mengué
a201e152f7 hg: remove usage of tail+awk in favor of sed 2014-01-19 19:56:00 +01:00
Olivier Mengué
8df6cffef7 hg: minor code layout 2014-01-19 16:03:28 +01:00
Olivier Mengué
6bfa957689 hg: improve speed of check for uncommitted stuff 2014-01-19 16:02:26 +01:00
Olivier Mengué
4955326aa5 hg: refactor outgoing commits counting
Rename variable 'has_commit' to 'commits' and declare it as integer.
2014-01-19 15:15:52 +01:00
Olivier Mengué
35e39d8b50 hg: improve untracked files detection (speed) 2014-01-19 15:05:30 +01:00
yannack
5f8fcc46ea Support for counting screen sessions running with extra parameters
In some cases (multi user enabled in screen for example), the count of
detached screen sessions was incorrect. The command to locate these has
been improved using a more tolerant regex, which does not require
'detached' to be the first word inside the parenthesis.

To test, open a new screen session, add multiuser (type Ctrl+A, then
':', then multiuser on), then detach (Ctrl+A, Ctrl+D), and see that
liquidprompt detects the screen, as would "screen -list".
2014-01-19 10:35:52 +01:00
Frédéric Mahé
aed833058f Consistent style for loops (while and for) 2014-01-19 10:08:38 +01:00
Frédéric Mahé
df26c49ff9 Use $() instead of ticks 2014-01-19 10:08:37 +01:00
Frédéric Mahé
83a2215163 Use a redirection to avoid a call to cut (second) 2014-01-19 10:08:37 +01:00
Frédéric Mahé
74778659ae Use a redirection to avoid a call to cut 2014-01-19 10:08:37 +01:00
Frédéric Mahé
549f820e9d Use less wc calls
Use grep -c to avoid a call to wc
2014-01-19 10:08:37 +01:00
Frédéric Mahé
1808f69405 Use builtins when possible
a call to cat can be replaced by a redirection.
2014-01-19 10:08:37 +01:00
polyphemus
64f93eb564 shorten_path: Escape '%' instead of using a var
When ${var//orig/replace} is intended with orig as '%' there is no need
to use a variable to avoid the '//%' form if the '%' is escaped.
2014-01-12 21:59:49 +01:00
Olivier Mengué
b50f9e2e9e Shorten path: fix escaping on both bash and zsh
Thanks to polyphemus (Rolf Morel) for the catch!
2014-01-08 09:06:03 +01:00
Olivier Mengué
252526f36e Do not load if $TERM is not valide (fixes #161) 2014-01-07 22:22:09 +01:00
Olivier Mengué
7249cffb44 VIRTUALENV: avoid usage of 'basename' (external command) 2014-01-06 22:15:46 +01:00
Olivier Mengué
def03a7ffd Refactor VIRTUAL_ENV support for improved speed 2014-01-06 22:10:42 +01:00
Olivier Mengué
96e42929a6 Refactor LP_PERM 2014-01-06 21:38:15 +01:00
Olivier Mengué
2ddd3bf500 Credit polyphemus 2014-01-06 19:51:01 +01:00
Olivier Mengué
0d9cace346 DIRTRIM: fix comment explaining how to enable the feature 2014-01-06 09:24:28 +01:00
Olivier Mengué
83b0ea8ea8 shorten path: properly escape \ (bash) or % (zsh) 2014-01-03 09:32:08 +01:00
polyphemus
5b52a1d4d0 Remove unneeded local keyword 2014-01-03 09:27:55 +01:00
polyphemus
8c69a27543 Check if root when striping trailing slash 2014-01-03 09:27:42 +01:00
polyphemus
81c4ff1c05 Always show complete current dir when shortening path
When LP_PATH_KEEP=0 and current dirname were over maximum length the
name was also shorten. With this fixed _lp_shorten_path should now
always return at least the complete current dirname.
2014-01-03 09:27:25 +01:00
polyphemus
467490f20f fix promblematic shorten path function
The previous implementation had shell specific paths which did not
produce the same result. It did not respect the maximum length which it
calculated. And for specific cases even repeated part of the path.

This implementation is portable across bash and zsh.
It respects maximum length strictly and only exceeds it when it has to
respect LP_PATH_KEEP leading dirs.
It adds support for only showing the current directory, without leading
ones. This fixes Issue #219.

(Rebased by Olivier Mengué on top of more recent changes in that
fucntion)
2014-01-02 09:05:11 +01:00
Olivier Mengué
e92a8e2630 Rewrite _lp_upwards_find for speed (#255) 2013-12-30 19:39:58 +01:00
Olivier Mengué
5e63fca606 Fix LP_ENABLE_RUNTIME default value for zsh
... and avoid an invalid warning.
2013-12-28 01:41:25 +01:00
Olivier Mengué
f4c20b05fc Refactor _lp_as_text for speed
Uses 'sed' once instead of 2 ; move building of the sed program from
ruuntime to init time.
2013-12-28 00:29:33 +01:00
Olivier Mengué
5d93b64c6a Refactor _lp_title
Major refactoring of the TITLE feature to move all $TERM checks to init
time. The _lp_title function is now reduced to two lines.
2013-12-27 23:56:51 +01:00
Olivier Mengué
6aa43e140e Move $TERM checks out of _lp_title
Move $TERM checks for the TITLE feature (LP_ENABLE_TITLE) from runtime
to init time as the terminal will not change during the shell's life.
2013-12-27 22:41:08 +01:00
Olivier Mengué
d91e1422b0 Fix regexp for LP_ENABLE_TITLE
LP_ENABLE_TITLE is now fixed, at least on GNU/Linux with gnome-terminal.
2013-12-27 21:47:20 +01:00
Olivier Mengué
e883c8e41d Fix more bad code for LP_ENABLE_TITLE
Fix one more portability hack that was really inefficient.
2013-12-27 19:16:05 +01:00
Olivier Mengué
10a3ecb17c Fix more quoting shit, to fix LP_ENABLE_TITLE 2013-12-27 19:13:18 +01:00
Olivier Mengué
3a54eaa881 Fix quoting in _lp_upwards_find usage
Should fix some issues with VCS detection.
2013-12-27 18:48:54 +01:00
Olivier Mengué
1aca2d7e3d Fix quoting bug in _lp_upwards_find #255
Thanks to @bkc for the pointer to this issue and a partial fix.
2013-12-27 17:36:36 +01:00
Olivier Mengué
a0509ac15a _lp_source_config: fix quoting for LP_MARK_ variables 2013-12-18 00:18:22 +01:00
Olivier Mengué
455da0d4fa Cleanup previous commit about LP_PATH_DEFAULT
- avoid overriding the existing LP_PATH_DEFAULT from the environment
- use the _LP_*_SYMBOL convention for shell dependent default values
2013-12-17 21:39:48 +01:00
François Schmidts
eb0119a08f Add LP_PATH_DEFAULT to allow to customize how $PWD is shown
See feature request #219.
2013-12-17 21:36:27 +01:00
Olivier Mengué
ecb1adcd48 Use proper quoting when handling PROMPT_COMMAND
May fix issue #250.
2013-12-17 21:16:43 +01:00
Alex
d2cb19fed8 Compute lines of *unstaged* changes in prompt
Parse `git diff --shortstat` to get the line count of *unstaged* changes.

Improvements of the git related stuff are still possible, using more
plumbing commands, like:
* `git diff-index --quiet HEAD` to check for uncommitted changes (branch
  color), rather than relying on the `git diff --shortstat HEAD`
* `git ls-files --exclude-standard --others` to check for untracked
  files
2013-12-17 00:28:14 +01:00
Olivier Mengué
3ff556a759 _lp_shorten_path: don't use a sub shell anymore
Instead of using a subshell, _lp_shorten_path now directly sets its
result into the LP_PWD variable.
This is not just for style, but for speed.
2013-12-17 00:12:14 +01:00
Olivier Mengué
964f77834e _lp_shorten_path: set value for locals on separate line (zsh)
zsh doesn't like if we set the value of a local while we declare it.
2013-12-17 00:06:32 +01:00
Olivier Mengué
81c93c1d52 bash/PROMPT_DIRTRIM: complete rewrite
Complete rewrite of the _lp_get_dirtrim into _lp_set_dirtrim with a much
faster implementation that avoids char by char processing of $PWD.
Also use (( )) builtin.
2013-12-16 22:33:55 +01:00
Olivier Mengué
f38be781bc Reset LP_OLD_PWD on startup
Reset the LP_OLD_PWD variable on startup.
This makes debugging easier: previously we had to change directory
after a reload to see the changes of the new code for the PWD-cached
parts.
2013-12-16 22:23:11 +01:00
François Schmidts
7d2c1b0ce7 keeping liquidprompt from overriding PROMPT_DIRTRIM when path shortening is disabled 2013-12-16 21:12:51 +01:00
Olivier Mengué
f3b34ed8cd Fix usage of $_LP_SHELL_bash 2013-12-16 21:07:25 +01:00
Olivier Mengué
e019813dab Remove update_terminal_cwd from _LP_OLD_PROMPT_COMMAND
... as we now have special handling for that feature of the terminal in
_LP_TERM_IPDATE_DIR
2013-12-07 11:16:26 +01:00
Olivier Mengué
d4275c1312 Run the old PROMPT_COMMAND with eval
Because it may contain multiple commands separated with ';'.
See #196.
2013-12-07 11:16:25 +01:00
Olivier Mengué
9adfd973d0 cpu_load: merge back Darwin and FreeBSD 2013-12-07 11:16:25 +01:00
Olivier Mengué
ce345aa24d Improve support for MacOS X directory icon (update_terminal_cwd)
Improvements:
- check if update_terminal_cwd is available instead of relying on the
  kernel version
- test the feature once at init time instead of at prompt time

Note that zsh is not yet supported for that feature unless the
update_terminal_cwd has been imported in your environment.
I think it would be possible to support it, but I don't have access to
MacOS X machines, so... patches are welcome!
2013-12-07 11:16:25 +01:00
Kyle P Davis
4bf9a43cef Fix battery indicator on Darwin 2013-12-07 11:14:26 +01:00
Olivier Mengué
48f435b8d4 WIP: add backend for wifi level
Very early work in progress.
Need help to design the output. LP_MARK_WIFI?
2013-12-06 00:38:51 +01:00
dryman
4111ffc493 Use LP_MARK_PREFIX="\n" to seperate the prompt into two lines 2013-12-06 00:08:16 +01:00
Olivier Mengué
8e2cc80a54 _lp_temp_*: get result through variable instead of stdout 2013-12-05 00:24:19 +01:00
Olivier Mengué
47d093dbe6 _lp_temp_acpi: handle multiple temperature sensors (multi CPU) 2013-12-05 00:13:57 +01:00
Olivier Mengué
f634a94418 Temperature/Linux: fetch using "acpi -t" 2013-12-05 00:00:38 +01:00
Olivier Mengué
34835335c7 screen: stricter matching in detached sessions counting 2013-12-04 23:38:20 +01:00
Yannack
8d090f584a Support for counting screen sessions with parameters
In some cases (multi user enabled in screen for example), the count of
detached screen sessions was incorrect. The command to locate these has
been improved using a more tolerant regex, which also makes sure the
"Detached" word appears inside a parenthesis (so it's not an attached
screen to a machine called Detach for example).
2013-12-04 23:32:21 +01:00
Olivier Mengué
c5b1c3d705 Fix tabs in source (fossil support) 2013-12-04 22:54:03 +01:00
Olivier Mengué
83266cd6a5 Fix spaces in source 2013-12-04 22:51:48 +01:00
Olivier Mengué
4840795bf7 Merge branch 'develop': post release fixes 2013-12-02 15:01:28 +01:00
polyphemus
50e91cd3e3 Fix use of non-exist variable 'count'
Fixes shell error:
""bash: 46 / : syntax error: operand expected (error token is "/ ")
2013-12-01 17:42:04 +01:00
Anthony Gelibert
9e5bb5c0d3 Add forgotten local declaration. 2013-12-01 17:39:56 +01:00
nojhan
8f149fd892 nojhan, original author and dolmen, maintener 2013-11-30 16:06:41 +01:00
Olivier Mengué
189a6fd71b Credit myself as co-maintainer 2013-11-28 00:08:47 +01:00
Anthony Gelibert
bdfe920d39 Typos in comments. 2013-11-28 00:06:45 +01:00
Anthony Gelibert
1c7defb11d Add myself in the authors. 2013-11-28 00:05:01 +01:00
Anthony Gelibert
b87e0c0f9f Corret LC_ALL setting in git branch. 2013-11-28 00:02:50 +01:00
Anthony Gelibert
da940677ee Correct a bug in git parsing. 2013-11-28 00:00:16 +01:00
Anthony Gelibert
141131502a zsh compat: separate variable declaration from first set 2013-11-27 23:56:05 +01:00
George Macon
02d6f3f376 Update mac-battery support to use pmset instead of ioreg
pmset's output is much closer to the point.
2013-11-27 12:32:25 +01:00
George Macon
d66cafb86a Enable battery on Mac OS X
This uses ioreg to read the battery status.  This was tested on
Mac OS 10.8.3, but will probably work a few versions back as well.
2013-11-27 12:32:25 +01:00
Ryan Wilson-Perkin
75afb57855 Fix #124: zsh magic of %~ with environment variables
unset local variables that interfere with autonamedirs in oh-my-zsh
1) unset local variable p before use in zsh pwd truncation
2) prefix LP_OLD_PWD with "LP:" to avoid autonaming
2013-11-26 23:27:57 +01:00
Taahir Ahmed
c7c57732a2 Fixed an error in _lp_upwards_find, and enhanced it slightly.
_lp_upwards_find was using a single-quoted $@, not double-quoted, so
find was actually looking for files called '$@'.

In addition, once _lp_upwards_find finds the file it's looking for, it
breaks out so it doesn't need to always traverse to root.  I doubt
this actually saves much in practice, but it might as well be there.
2013-11-26 09:08:33 +01:00
Taahir Ahmed
31a86c9327 Added "upwards find" tests for expensive dvcs.
Mercurial and Bazaar are written in Python, which, on my system,
causes a noticeable hitch in the prompt generation when changing
directories.  I have added code that, before invoking the 'hg' or
'bzr' executables, first tests if we could possibly be in a bazaar or
hg repository checkout by traversing the directory structure upwards
to the root, looking for an '.hg' or '.bzr' folder.

At least for me, this makes the prompt instantaneous.  There may be
more elegant solutions to this problem, but this one works.
2013-11-26 09:04:32 +01:00
Olivier Mengué
7fe87a5cf5 Revert fix applied on the wrong branch (lp_temp_sensors)
Revert "Added null check for count in _lp_temp_sensors() to stop division by zero errors in case count is still zero."
Closes #214.
Thanks @jaesivsm

This reverts commit 9d96a82c80.

Conflicts:
	liquidprompt
2013-11-25 23:12:43 +01:00
Olivier Mengué
6da1e9bc6a Fix a typo in variable name that makes a variable leak
Closes #232.
2013-11-25 22:45:36 +01:00
Olivier Mengué
bc4450e3ec _lp_git_branch: minor optimization 2013-08-20 20:09:26 +02:00
Olivier Mengué
aeb0a6afed Fix initialisation of _LP_RUNTIME_LAST_SECONDS 2013-08-01 08:23:42 +02:00
Olivier Mengué
bf8ef5b513 Bypass shell aliases on the 'git' command. Closes #213 2013-07-26 10:30:50 +02:00
nojhan
635285fbc4 Merge branch 'mainerror-master' into develop
Conflicts:
	liquidprompt
2013-07-07 15:25:56 +02:00
nojhan
0a161a6d3f Use the same convention for test as elsewhere in the code 2013-07-07 15:22:19 +02:00
nojhan
3a6798334d Merge branch 'runtime-squashed' of https://github.com/mrks/liquidprompt into mrks-runtime-squashed 2013-07-07 15:12:31 +02:00
nojhan
993979c213 Merge branch 'dxtr-openbsd' into develop
Conflicts:
	liquidprompt
2013-07-07 15:08:48 +02:00
Kim Lidström
2f2f79f9d6 Made _lp_cpu_load more consistent under OpenBSD 2013-07-01 14:01:16 +02:00
Kim Lidström
8624a4f6c6 Added OpenBSD support 2013-07-01 13:42:48 +02:00
Octavian Damiean
9d96a82c80 Added null check for count in _lp_temp_sensors() to stop division by zero errors in case count is still zero. 2013-06-30 22:04:00 +02:00
Markus Dreseler
f783e5f979 Changed expr to bash arithmetic expression 2013-06-24 11:57:20 +02:00
Markus Dreseler
b075b46c85 Added runtime displaying 2013-06-23 12:30:44 +02:00
nojhan
a39c2c8342 do not unset LP_OS, used in _llp_set_prompt (at runtime) 2013-06-19 21:24:55 +02:00
Olivier Mengué
e79a8707f0 FreeBSD, Darwin: _lp_cpu_load improvements
FreeBSD: fixed _lp_cpu_load
Darwin: optimized _lp_cpu_load

Note that this change may break syntax coloring in Vim if Vim is not
configured to read the file as 'bash'. Workaround: create a symbolic
link with a '.bash' extension and open that file.
2013-06-17 21:09:43 +02:00