Data Functions

These functions are designed to be used by themes.

All data functions will returntrue (meaning return code0) when theyare both enabled and have data. They will returnfalse (meaning return code1) when they do not have data. Most will return2 when they aredisabled, either through the config or because the tool they depend on is notinstalled. Such disable config options will be documented. Exceptions to thisrule are explicitly documented.

When a function returnsfalse, any return variables are not guaranteed tobe set. If running withset-u (or when building a theme to bedistributed), guard any return variable accesses with a check of the returncode, or use${var-} syntax.

Battery

_lp_battery() → var:lp_battery

Returns a return code depending on the status of the battery:

  • 5 if the battery feature is disabled or not available

  • 4 if no battery level is found

  • 3 if charging and the level is above the threshold

  • 2 if charging and the level is under the threshold

  • 1 if discharging and the level is above the threshold

  • 0 if discharging and the level is under the threshold

Returns an integer percentage of the current battery level.

If the threshold is not surpassed, the battery level is still returned.

The threshold is configured withLP_BATTERY_THRESHOLD.

Can be disabled byLP_ENABLE_BATT.

Development Environment

_lp_python_env() → var:lp_python_env

Retunstrue if a Python or Conda environment is detected. Returns thevirtual environment name.

If the environment name contains a forward slash (/), only the substringafter the last forward slash is returned.

Can be disabled byLP_ENABLE_VIRTUALENV.

New in version 2.0.

_lp_software_collections() → var:lp_software_collections

Returnstrue if aRed Hat Software Collection is enabled. Returns thesoftware collection name.

If the software collection name has trailing whitespace, it is removed.

Can be disabled byLP_ENABLE_SCLS.

New in version 2.0.

Environment

_lp_connected_display()

Returnstrue if there is a connected X11 display.

New in version 2.0.

_lp_connection() → var:lp_connection

Returns a string matching the connection context of the shell. Valid values:

  • ssh - connected over OpenSSH

  • lcl - running in a local terminal

  • su - running in asu orsudo shell

  • tel - connected over Telnet

It is not possible for more than one context to be returned. The contextsare checked in the order listed above, and the first one found will bereturned.

It is not possible for no context to be returned.

Changed in version 2.0:Return method changed from stdout.

_lp_dirstack() → var:lp_dirstack

Returnstrue if directory stack support is enabled and the directorystack contains more than one directory. In that case, the return variableis set to the number of directories on the stack.

Can be enabled byLP_ENABLE_DIRSTACK.

New in version 2.0.

_lp_error() → var:lp_error

Returnstrue if the last user shell command returned a non-zero exitcode. Returns (in the return variable) the exit code of that command.

Can be disabled byLP_ENABLE_ERROR.

Note

The return variablelp_error will always be set with the last commandreturn code, as it must be the first thing done by the prompt. Thisfunction should still be used, as it checks for the feature beingdisabled by the user.

New in version 2.0.

_lp_http_proxy() → var:lp_http_proxy

Returnstrue if an HTTP or HTTPS proxy is enabled through environmentvariables in the shell. Returns the first found proxy string.

Can be disabled byLP_ENABLE_PROXY.

New in version 2.0.

_lp_multiplexer() → var:lp_mulitplexer

Returnstrue if the current shell context is inside a terminalmultiplexer. Returns a string matching the multiplexer:

  • tmux

  • screen

New in version 2.0.

_lp_terminal_device() → var:lp_terminal_device

Returns the basename of the terminal device connected to the shell’s standardinput.

Note

This value should never change during the life of the shell.

Note

This data source is unlikely to be wanted by the user, and should not beincluded in themes by default.

New in version 2.0.

Jobs

_lp_detached_sessions() → var:lp_detached_sessions

Returnstrue if any detached multiplexer sessions are found. Returns aninteger count of how many sessions were found.

Can be disabled byLP_ENABLE_DETACHED_SESSIONS.

New in version 2.0.

_lp_jobcount() → var:lp_running_jobs, var:lp_stopped_jobs

Returnstrue if any shell background jobs are found. Returns an integercount of how many jobs are running and how many are stopped.

Stopped jobs are jobs suspended with Ctrl-Z.

Running jobs are jobs started with thecommand& syntax, or stopped jobsstarted again with thebg command.

Can be disabled byLP_ENABLE_JOBS.

New in version 2.0.

Load

_lp_cpu_load() → var:lp_cpu_load

Returns a string of the system load average smallest increment, usually 1minute. The return code is not defined.

_lp_load() → var:lp_load, var:lp_load_adjusted

Returnstrue if the system load average scaled by CPU count is greaterthan the threshold. Returns the system load average inlp_load, and theaverage scaled by CPU count, multiplied by 100 inlp_load_adjusted. Inother words, the load average is multiplied by 100, then divided by thenumber of CPU cores.

lp_load should be displayed to the user, whilelp_load_adjusted should beused to compare values between machines usingLP_LOAD_CAP. Thedefault theme uses this to generate a color scale.

Note

LP_LOAD_CAP is a raw floating point configuration value that isdifficult to do math on._LP_LOAD_CAP contains the same value, butmultiplied by 100 to make comparisons tolp_load_adjusted simple. Useit along withlp_load_adjusted as arguments to_lp_color_map().

If the threshold is not surpassed, the load average is still returned.

The threshold is configured withLP_LOAD_THRESHOLD.

Can be disabled byLP_ENABLE_LOAD.

New in version 2.0.

OS

_lp_chroot() → var:lp_chroot

Returnstrue if a chroot environment is detected. Returns a stringmatching the chroot string if one is found.

New in version 2.0.

_lp_hostname() → var:lp_hostname

Returnstrue if a hostname should be displayed. Returns1 if theconnection type is local andLP_HOSTNAME_ALWAYS is not1.

Returns the hostname string.

Note

The returned string is not the real hostname, instead it is the shellescape code for hostname, so the shell will substitute the real user IDwhen it evaluatesPS1.

Deprecated since version 2.0:Also setsLP_HOST_SYMBOL to the same return string.

Can be disabled byLP_HOSTNAME_ALWAYS set to-1.

New in version 2.0.

_lp_sudo_active()

Returnstrue ifsudo is currently activated with valid credentials.Ifsudo is configured to always allow a user to run commands with nopassword, this will always returntrue.

Can be disabled byLP_ENABLE_SUDO.

New in version 2.0.

_lp_user()

Returns a return code depending on the logged in user:

  • 2 - the user is root

  • 1 - the user is a user other than the original login user

  • 0 - the user is the login user

New in version 2.0.

_lp_username() → var:lp_username

Returnstrue if a username should be displayed. Returns1 if theuser is the login user andLP_USER_ALWAYS is not1.

Returns the current user ID.

Note

The returned string is not a real user ID, instead it is the shell escapecode for user, so the shell will substitute the real user ID when itevaluatesPS1.

Can be disabled byLP_USER_ALWAYS set to-1.

New in version 2.0.

Path

_lp_path_format(path_format=$LP_COLOR_PATH,last_directory_format=$path_format,vcs_root_format=$last_directory_format,shortened_directory_format=$path_format,separator="/"[,separator_format]) → var:lp_path, var:lp_path_format

Returns a shortened and formatted string indicating the current workingdirectory path.lp_path contains the path without any formatting or customseparators, intended for use in the terminal title.lp_path_format containsthe complete formatted path, to be inserted into the prompt.

The behavior of the shortening is controlled byLP_ENABLE_SHORTEN_PATH,LP_PATH_METHOD,LP_PATH_LENGTH,LP_PATH_KEEP,LP_PATH_CHARACTER_KEEP,andLP_PATH_VCS_ROOT. See their descriptions for details on how theychange the output of this function.

The last directory in the displayed path will be shown with thelast_directory_format.

If a VCS repository is detected with_lp_find_vcs(), the root of theVCS repository is formatted withvcs_root_format. The detection method isthe same as for all other VCS display, so if a VCS type or directory isdisabled, it will not be detected.

If the path shortening shortens a directory (or multiple consecutivedirectories), they will be formatted withshortened_directory_format.

A customseparator will only be substituted in thelp_path_format output.Note that this will cut into maximum path length if the separator is longerthan one character.

With no specifiedseparator_format, each separator will take the format ofthe directory section preceding it. Otherwise every separator will beformatted withseparator_format. Note that the root directory is treated asa directory, and is formatted as such.

New in version 2.0.

Runtime

_lp_runtime_format() → var:lp_runtime_format

Returnstrue if the last command runtime was greater than the threshold.Returns a formatted string of the total runtime, split into days, hours,minutes, and seconds. Ex:3h27m6s.

The threshold is configured withLP_RUNTIME_THRESHOLD.

Can be disabled byLP_ENABLE_RUNTIME.

New in version 2.0.

Temperature

_lp_temperature() → var:lp_temperature

Returnstrue if the highest system temperature is greater than thethreshold. Returns the highest temperature integer.

If the threshold is not surpassed, the highest temperature is still returned.

The threshold is configured withLP_TEMP_THRESHOLD.

Can be disabled byLP_ENABLE_TEMP.

New in version 2.0:Note that a function by this name was renamed to_lp_temperature_color.

Time

_lp_time() → var:lp_time

Returnstrue if digital time is enabled. Returns the current digital timestring.

Note

The returned string is not the real time, instead it is the shell escapecode for time, so the shell will substitute the real current time when itevaluatesPS1.

Can be disabled byLP_ENABLE_TIME orLP_TIME_ANALOG set to1.

New in version 2.0.

_lp_analog_time() → var:lp_analog_time

Returnstrue if analog time is enabled. Returns the current analog timeas a single Unicode character, accurate to the closest 30 minutes.

Can be disabled byLP_ENABLE_TIME orLP_TIME_ANALOG set to0.

New in version 2.0.