1. 29 Jul, 2021 3 commits
    • Mark Vander Stel's avatar
      Refactor hooks · 0ce76465
      Mark Vander Stel authored
      Hooks have always been a mess. There was no organization when they were
      added, as when the project first started there was no need for them.
      To make things consistent, break out disabling hooks into
      __lp_disable_hooks(), and make prompt_on() be the enabler of hooks. Then
      have lp_activate() disable hooks at the start, and enable hooks at the
      Some small changes around how state is detected, but no functional
      difference here.
    • Mark Vander Stel's avatar
      Stop squashing Zsh prompt options · 58969b20
      Mark Vander Stel authored
      Based on the work done in ecdde384, the
      prompt_bang and prompt_subst options, which handle '!' and '$'/'`'
      characters respectively, can be left untouched. When running
      __lp_escape(), those options are checked, and if set, their characters
      are escaped.
      prompt_percent however, must still be enabled always. The shell sequence
      escapes, '%{' and '%}' only work when the option is enabled. Maybe
      someday we can detect when the option is off and disable all terminal
      formatting, but it doesn't seem worth the effort.
      Backslashes must be escaped even on Zsh to prevent confusion with a
      backslash directly preceding a character that would give is special
    • Mark Vander Stel's avatar
      Fix bash __lp_escape() for backtick expansion · a1d0a540
      Mark Vander Stel authored
      For some reason, Bash ignores a '\$' sequence when the promptvars option
      is off, printing it as '$'. It does not do the same for a backtick
      escaped: '\`' is printed as '\`'. To prevent this issue, detect if the
      option is on, and if so, escape both '$' and '`'.
      Running 'shopt' is actually faster than either a [[ ]] or (( ))
  2. 06 Jul, 2021 1 commit
    • Emil Lerch's avatar
      Add AWS Vault support · b0007032
      Emil Lerch authored
      Extension to #496 to add [AWS Vault](https://github.com/99designs/aws-vault)
      support. AWS Vault does not set the AWS_PROFILE/AWS_DEFAULT_PROFILE
      variables, but does add AWS_VAULT. Since this is philosophically the
      same as showing an AWS profile on the prompt, I simply added AWS_VAULT
      to the detection chain.
  3. 28 Jun, 2021 1 commit
  4. 15 Jun, 2021 1 commit
    • Mark Vander Stel's avatar
      Add missing Ruby VENV template section in docs · 486cf147
      Mark Vander Stel authored
      This was missed in the PR for the Ruby Virtualenv section.
      The order in the docs for Terraform and Kubecontext was backwards from
      the order in the code.
      Moved parts of the PS1 building to different lines to make it easier to
      read and add new sections.
      Resolves #676
  5. 14 Jun, 2021 1 commit
    • Ian Smith's avatar
      Ian Smith authored
      LP_KUBECONTEXT_DELIMITER_SUFFIX removes a suffix (dev-cluster and - becomes ->
      dev). But sometimes the boilerplate part is a prefix, as when using AWS
      EKS (Elastic Kubernetes Service).
      `aws eks update-kubeconfig --name $CLUSTER_NAME` sets the cluster's ARN
      as the context name, most of which is boilerplate:
  6. 30 May, 2021 1 commit
  7. 09 May, 2021 1 commit
    • Mark Vander Stel's avatar
      Fix temperature erroring if tool returns no data · 4c81ef40
      Mark Vander Stel authored
      Rarely, sensors or acpi can return no temperature data. In this case,
      the data function would return false and 0, but the detect function
      would error if set -u was enabled.
      Harden all of the four temperature functions against this, and greatly
      increase the test coverage to cover these four functions, as well as
      adding a specific case for the tools returning no data.
      This also allows for the temperature functions to return values less
      than 0, if somehow a device has all temp sensors returning less than
      Mention in the function documentation that it is possible for the
      function to return a not set string.
      Fixes 670
  8. 02 May, 2021 1 commit
  9. 27 Apr, 2021 1 commit
    • Mark Vander Stel's avatar
      Fix local bug in Zsh-5.0 · 7db4ada7
      Mark Vander Stel authored
      Zsh 5.0 continues to be a huge pain. As noted in the shell wiki, all
      variables assigned to another variable as part of a 'local' or 'typeset'
      line must be quoted, or things will break. The reason I caught these
      many instances was a failing test on Zsh-5.0.8 because of the bad line
      in __lp_pwd_tilde().
  10. 20 Apr, 2021 1 commit
    • Mark Vander Stel's avatar
      Fix Zsh crash on rbenv output parse · fee75427
      Mark Vander Stel authored
      Parameter substitution is (like most standards) weakly defined, and here
      is a case where it was not tested on Zsh. Simple fix of wrapping the
      whole string (the '(' was the bad character) in quotes.
      Also add a test case to catch a regression.
      Fixes #667
  11. 13 Apr, 2021 2 commits
  12. 08 Apr, 2021 1 commit
    • Mark Vander Stel's avatar
      Add raw string passing to fix title issues · a23af792
      Mark Vander Stel authored
      The problem is simple enough: the extra backslashes or percents that
      __lp_escape() adds show up in the title, as the title is changed in the
      previous commit to no longer be printed as part of PS1. The fix is not
      so simple.
      This patch adds "raw" copy of the data strings for username, hostname,
      and current path with no color or shell character escaping. This is
      designed for putting into the terminal title, but it could also be used
      for comparisons. lp_path_format() already had a no formatting return var
      in lp_path, but now it is not shell escaped.
      The title is changed from duplicating the prompt to instead showing just
      the core bits in the central brackets: username, hostname, current path,
      followed by the prompt mark. As well as the user prefix, postfix, and
      MARK_PREFIX. This is a change from the long standing default, but it is
      customizable both by themes and users, and I have long seen complaints
      of the current title layout being less than helpful.
      There is one small issue though: to prevent LP_PS1_PREFIX,
      LP_PS1_POSTFIX, and LP_MARK_PREFIX that have color from messing up the
      title, the whole title string is still passed into lp_formatted_title()
      to strip color out. This is less than ideal, but faster than treating
      those 3 variables by themselves.
  13. 26 Mar, 2021 1 commit
    • Michael Livshin's avatar
      bash: don't touch the promptvars option · ecdde384
      Michael Livshin authored
      * In general, it is not proper for liquidprompt to change shell
        options that it does not absolutely have to change.
      * LP_PS1_{PREFIX,POSTFIX} are a thing, and are in fact an effective
        means to combine liquidprompt with other prompt-touching logics
        (such as emacs-vterm).  So it is not good to prevent those other
        logics from actually working.
      This commit restores the bash version of __lp_escape to what it did
      prior to 62f02708 (escaping dollar signs in addition to backslashes)
      and removes all interference with the promptvars shell option.
      NOTE: I don't know much about shells other than bash, so left the
      parallel logic for zsh as is.
  14. 10 Mar, 2021 1 commit
    • Mark Vander Stel's avatar
      Add Title command feature · 0c23a33e
      Mark Vander Stel authored
      This feature depends on the removal of the prompt escape sequences that
      came before. Part of that is the removal of adding the title to $PS1:
      now it is just print to the screen. This could improve speed slightly,
      as the shell doesn't need to parse that text. But it does prevent usage
      of prompt escape codes in the title.
      Which causes a rare issue where __lp_escape() adds duplicate backslashes
      or percents to escape a string for the prompt, but now are not needed in
      the title. It will just print double in the title, so it isn't a huge
      issue, but is something that should be fixed. I'm not sure how to handle
      it though, since the current architecture requires escaping the strings
      before formatting is added to them.
      I also needed to rework how the runtime feature was handled, since it
      monopolized the DEBUG trap in Bash. Now it can handle multiple features
      that need to run after the user has submitted the command, but before it
      The feature itself is simple: lookup the latest command in the history,
      and print the normal title postpended by that command to the screen,
      formatted as a terminal title. Note that Bash's $BASH_COMMAND is not
      great, as it only contains the current _command_, not the whole command
      Resolves #609
  15. 05 Mar, 2021 5 commits
    • Mark Vander Stel's avatar
      Add __lp_escape() calls to path_format() · 36ab8fa8
      Mark Vander Stel authored
      This was forgotten before.
    • Mark Vander Stel's avatar
      Remove backslash escaping from Zsh __lp_escape() · 658ce84c
      Mark Vander Stel authored
      This was added in commit 74e14fe0. I
      don't understand why, except that maybe a single backslash display would
      look like an escape code for a control character, like \n. But that is
      not the case for Bash, so why the difference?
      Zsh only uses percents (%) to escape things in the prompt, where Bash
      only uses bashslashes. This changes makes the same input string print
      the same way in the prompt for both shells.
    • Mark Vander Stel's avatar
      Replace hostname shell prompt escape with env vars · 03685237
      Mark Vander Stel authored
      Again further work on #651. This time it is simple: both Bash and Zsh
      set the exact same hostname that they use for their prompt escape
      sequences into HOSTNAME and HOST, respectively.
      Then it is a simple matter to replicate their "short" version by
      truncating the string to the first period.
    • Mark Vander Stel's avatar
      Remove username shell prompt escape code · 61df03a0
      Mark Vander Stel authored
      Another replacement for #651, this one was mostly simple. Unfortunately,
      not all shells set an environment variable for user. Zsh always sets
      USERNAME, but neither Bash nor Zsh set USER. login(1) does however, so
      it _should_ always be set. See https://unix.stackexchange.com/a/76356/421569
      for some good info.
      Fall back to id -nu just in case the variables don't work. I don't know
      how portable that command is, but since it is a backup, it should be
    • Mark Vander Stel's avatar
      Add date call to remove shell escape and formatting · dd1f8f87
      Mark Vander Stel authored
      By calling date(1), another shell prompt escape sequence is removed.
      This also allows for custom formatting strings.
      Add and update docs for time functions.
      Resolves #281
  16. 01 Mar, 2021 1 commit
    • Mark Vander Stel's avatar
      Replace prompt mark shell escape string · 1a22e1ec
      Mark Vander Stel authored
      Part of #651, this removes a shell prompt escape string, making it
      easier to work with terminal titles, as well as making it possible to
      customize the prompt mark for the root user. This patch does not do
      that, as the functionality has remained the same, but it would now be
      possible to add a LP_MARK_ROOT.
      This patch should have no functional difference, as the checks that Bash
      and Zsh did in the prompt escape are exactly the same that Liquidprompt
      is doing: comparing EUID to 0.
  17. 26 Feb, 2021 1 commit
    • Sam Pearson's avatar
      Add support for AWS_PROFILE environment variable · 0e552ba7
      Sam Pearson authored
      This will add `[profile_name]` to the prompt should it find either
      `AWS_PROFILE` or `AWS_DEFAULT_PROFILE` set in the environment.
      This is useful when switching between different AWS profiles and
      working with multiple accounts.
  18. 23 Feb, 2021 1 commit
    • Martin Schütte's avatar
      Add current Kubernetes context data source feature · 0660342d
      Martin Schütte authored
      Add a data source to get the current Kubernetes context. Includes a
      mechanism for truncating the context to the first matching character,
      The data source is disabled by default. The truncation is also disabled
      by default (disabled by setting the config option to the empty string).
      Add a default theme function to format the context like the other
      development environments.
  19. 16 Feb, 2021 1 commit
    • Mark Vander Stel's avatar
      Fix Git worktrees not registering as VCS dirs · fc44d972
      Mark Vander Stel authored
      Git worktrees (see git worktree --help) are registered as .git _files_
      instead of directories. This meant Liquidprompt would fail to detect
      them. Since other VCSs do not have similar files, add a special case for
      Git files like this.
      Fixes #658
  20. 07 Feb, 2021 4 commits
    • Mark Vander Stel's avatar
      Change default path colors to work on light terminals · 58693b06
      Mark Vander Stel authored
      On terminals with the default background color as white, the colors used
      by default for the path sections would stand out strongly. By removing a
      specific background color, and making most of the sections have no
      specific foreground color, the colors will work on both dark and light
      backgrounds. The "lowlight" colors, used for shortened paths and path
      separators, are now middle of the spectrum grey, which works for both
      light and dark as well.
      Update the documentation to match these slightly changed defaults.
      This will be a patch version bump, as the defaults should be no
      different for users with dark backgrounds, but should very much improve
      for those with light backgrounds.
      Fixes #657
    • Mark Vander Stel's avatar
      Fix unset unsafe USER usage on Windows · 461f0ee0
      Mark Vander Stel authored
      Windows Bash does not set USER, at least inside Github actions.
    • Mark Vander Stel's avatar
      Add unset saftey to TERM usage · dc11eb48
      Mark Vander Stel authored
      While liquidprompt has a unset safe TERM check at the top of the file
      that will bail out of liquidprompt if it is not set, that check can be
      skipped with the --no-activate flag, which is used in the tests. Zsh
      seems to not set the TERM var when run with no terminal, so these need
      to be safe.
    • Mark Vander Stel's avatar
      Fix unset errors in theme-preview on Bash 3.2 · e121179d
      Mark Vander Stel authored
      Bash 3.2 scans a whole line for unset problems, unlike later versions,
      which will exit the line if the boolean expression returns False
      already. So we need to have a safe exit when unsafe for
      _LP_RUNTIME_SECONDS on Bash 3.2.
      This SO post is super helpful: https://stackoverflow.com/a/61551944/8338372
      This is why the ${array[@]+"${array[@]}"} form is used, anywhere either
      the arary could be empty, or the array could have empty strings as
      values. Most of our array usages we know for sure there are good values
      in, but user config ones we have no way to know for sure.
      Change source path for liquidprompt file in theme-preview. Zsh expects a
      sourced filed with no path to be on the Bin path, which liquidprompt
      won't be. By changing to a relative path, that is fixed. While that
      script is designed to be run under Bash, it works just fine under Zsh,
      so why not run it under Zsh to test Liquidprompt as a whole.
      Also add an exit condition in the theme-preview where the passed in
      theme does not exist.
      Add tests for the two tools scripts, just to check that they don't exit
      with errors.
      Fixes #656
  21. 26 Jan, 2021 2 commits
    • Mark Vander Stel's avatar
      Change default of LP_LOAD_CAP to 2.0 · 5069c22d
      Mark Vander Stel authored
      This config variable is a great case of "no perfect default for anyone".
      Every machine is different, and each user wants to see different things.
      That is why I added it as a config option.
      But there are two good arguments for making this change to the default:
      * Often users report that they reach the top of the color range too
      * Only four of the LP_COLORMAP colors would be displayed with the old
        default. With this change, seven will be. This means there are more
        colors shown for a longer gradient, and when the value is starting to
        be displayed it doesn't start right away at "danger" colors.
    • Mark Vander Stel's avatar
      Make load display actual load instead of adjusted · e058b619
      Mark Vander Stel authored
      The load average display has been notoriously not helpful. It is scaled
      by the CPU count, and then multiplied by 100 to make it apear like a
      percentage. But load average and CPU utilization have almost nothing to
      do with each other.
      This change displays the actual load average, while keeping the
      threshold and color calculations the same. This means the functionality
      is no different, just that the display has changed formats.
      To make the configuration options LP_LOAD_THRESHOLD less confusing, it
      too has been changed to be an actual load value, no longer "centiload".
      Old values are still supported, which is done by checking for a period
      ('.') in the string. So for this historical reason, all new values must
      have a period in them. Which should not be a problem, any useful value
      would be a float.
      Change the greater-than comparison to a greater-than-or-equal-to, since
      it is a little more intuitive to what would be expected from the config
      Since I was at it, I added a new config option LP_LOAD_CAP, to configure
      the range for color values output by _lp_color_map() for load averages.
      It too takes a load average float value. As it does not have the
      historical reason above, it does not accept "centiload" values.
      The implementation details are long. Floating point math does not exist
      in shells (which I suspect is the reason that "centiload" was used in
      the first place). To make it possible to compare, the values are scaled
      up by 100 just like before. They are not shown to the user. 100 scaling
      should be plenty for the precision we need.
      To do the scaling, __lp_floating_scale() is added, which as a standalone
      function, can be unit tested.
      And for good measure, the lp_load return value is passed through
      __lp_escape(), just in case.
      Special thanks to Tore Anderson (@toreanderson) for helping dig through
      the issues here.
  22. 23 Jan, 2021 2 commits
    • Mark Vander Stel's avatar
      Add check for supported versions of Zsh · 5bd80ce1
      Mark Vander Stel authored
      I have yet to come accross any instance of Zsh less than version 5.0.0,
      but the check is cheap, and I would rather be explicit. As far as my
      testing and interpritation of the Zsh release docs
      (http://zsh.sourceforge.net/releases.html) goes, we should have no
      problem supporting versions of Zsh back to 5.0.8 or so. I have not seen
      any version less than 5.0.8, but I would assume that they should work.
    • Mark Vander Stel's avatar
      Fix all local declarations that broke on Zsh-5.0 · 0f98dbb1
      Mark Vander Stel authored
      Before zsh-5.1, assignments after a local/typeset were treated like any
      other argument, not assignments, and so they were expanded as such. To
      fix this, simply quote them like arguments, or move them to their own
      line to make them parse like arguments.
      I went for a mixed use, where single variable declarations I kept on one
      line and quoted, but multi-variable declarations I moved the assignments
      to following lines.
  23. 22 Jan, 2021 1 commit
    • Mark Vander Stel's avatar
      Fix multi-char separator crashing on Zsh · ec696221
      Mark Vander Stel authored
      This is why code coverage is amazing. I missed writting tests for this
      specific case, which allowed a bug to slip through.
      Zsh did not know how to handle a ${var//[!"string"]} syntax, so remove
      the quotes and replace it with a backslash.
      Add tests to cover that case to prevent a regression.
  24. 21 Jan, 2021 5 commits
    • Mark Vander Stel's avatar
      Finallize lp_path return variable · 57cf1d9c
      Mark Vander Stel authored
      Some of the execution paths of _lp_path_format() would return a correct
      lp_path value, but most would not. This variable should contain the same
      shortened path as lp_path_format, but without any of the formatting or
      special separators.
      Add tests to test lp_path for each shortening method.
    • Mark Vander Stel's avatar
      Add defaults for new path formatted colors · 8a00830b
      Mark Vander Stel authored
      These are tame defaults, no colors, just shades of white for the
      different path elements.
    • Mark Vander Stel's avatar
      Add compatability shims for deprecated options · ece4dbc6
      Mark Vander Stel authored
      Both LP_PATH_DEFAULT and PROMPT_DIRTRIM needed shell escape sequences to
      work, which is impossible to add our formatting to.
      There is no way to support LP_PATH_DEFAULT and add our formatting, so
      don't add the formatting in the shim.
      We can get a pretty close approximation of PROMPT_DIRTRIM + our
      calculating function by using the default shorten method.
      LP_PATH_KEEP=-1 has not changed in function, only that now that we have
      a LP_PATH_METHOD selection, that is the prefered way to do it.
    • Mark Vander Stel's avatar
      Add truncate_to_last_dir path shortening method · a4e849bd
      Mark Vander Stel authored
      It works exactly like how LP_PATH_KEEP=-1 does. Simply display the
      current directory. It will be formatted with the last dir format, unless
      LP_PATH_VCS_ROOT=1 and the current directory is the root, in which case
      it will be the vcs formatting instead.
    • Mark Vander Stel's avatar
      Complete truncate_chars_from_path_left feature · d8c8f922
      Mark Vander Stel authored
      In Liquidprompt v1, this path truncation was simple; just cut out the
      correct number of characters. But now that we can have a "special"
      directory in the middle of the path (the VCS root) and also each
      separator and directory needs its own formatting, this is much harder.
      The extra tricky part is that a check is needed to see if we are
      currently shortening already, and if so, not to fail out of the shorten
      if it looks like we would "break even".