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:
5if the battery feature is disabled or not available4if no battery level is found3if charging and the level is above the threshold2if charging and the level is under the threshold1if discharging and the level is above the threshold0if 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 with
LP_BATTERY_THRESHOLD.Can be disabled by
LP_ENABLE_BATT.
Development Environment¶
_lp_python_env() → var:lp_python_env¶Retuns
trueif 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 by
LP_ENABLE_VIRTUALENV.New in version 2.0.
_lp_software_collections() → var:lp_software_collections¶Returns
trueif aRed Hat Software Collection is enabled. Returns thesoftware collection name.If the software collection name has trailing whitespace, it is removed.
Can be disabled by
LP_ENABLE_SCLS.New in version 2.0.
Environment¶
_lp_connected_display()¶Returns
trueif 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 OpenSSHlcl- running in a local terminalsu- running in asuorsudoshelltel- 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¶Returns
trueif 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 by
LP_ENABLE_DIRSTACK.New in version 2.0.
_lp_error() → var:lp_error¶Returns
trueif the last user shell command returned a non-zero exitcode. Returns (in the return variable) the exit code of that command.Can be disabled by
LP_ENABLE_ERROR.Note
The return variable
lp_errorwill 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¶Returns
trueif an HTTP or HTTPS proxy is enabled through environmentvariables in the shell. Returns the first found proxy string.Can be disabled by
LP_ENABLE_PROXY.New in version 2.0.
_lp_multiplexer() → var:lp_mulitplexer¶Returns
trueif the current shell context is inside a terminalmultiplexer. Returns a string matching the multiplexer:tmuxscreen
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¶Returns
trueif any detached multiplexer sessions are found. Returns aninteger count of how many sessions were found.Can be disabled by
LP_ENABLE_DETACHED_SESSIONS.New in version 2.0.
_lp_jobcount() → var:lp_running_jobs, var:lp_stopped_jobs¶Returns
trueif 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 the
command&syntax, or stopped jobsstarted again with thebgcommand.Can be disabled by
LP_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¶Returns
trueif 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 using
LP_LOAD_CAP. Thedefault theme uses this to generate a color scale.Note
LP_LOAD_CAPis a raw floating point configuration value that isdifficult to do math on._LP_LOAD_CAPcontains 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 with
LP_LOAD_THRESHOLD.Can be disabled by
LP_ENABLE_LOAD.New in version 2.0.
OS¶
_lp_chroot() → var:lp_chroot¶Returns
trueif 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¶Returns
trueif a hostname should be displayed. Returns1if theconnection type is local andLP_HOSTNAME_ALWAYSis 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 evaluates
PS1.Deprecated since version 2.0:Also sets
LP_HOST_SYMBOLto the same return string.Can be disabled by
LP_HOSTNAME_ALWAYSset to-1.New in version 2.0.
_lp_sudo_active()¶Returns
trueifsudois currently activated with valid credentials.Ifsudois configured to always allow a user to run commands with nopassword, this will always returntrue.Can be disabled by
LP_ENABLE_SUDO.New in version 2.0.
_lp_user()¶Returns a return code depending on the logged in user:
2- the user is root1- the user is a user other than the original login user0- the user is the login user
New in version 2.0.
_lp_username() → var:lp_username¶Returns
trueif a username should be displayed. Returns1if theuser is the login user andLP_USER_ALWAYSis 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 itevaluates
PS1.Can be disabled by
LP_USER_ALWAYSset 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 by
LP_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¶Returns
trueif 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 with
LP_RUNTIME_THRESHOLD.Can be disabled by
LP_ENABLE_RUNTIME.New in version 2.0.
Temperature¶
_lp_temperature() → var:lp_temperature¶Returns
trueif 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 with
LP_TEMP_THRESHOLD.Can be disabled by
LP_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¶Returns
trueif 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 itevaluates
PS1.Can be disabled by
LP_ENABLE_TIMEorLP_TIME_ANALOGset to1.New in version 2.0.
_lp_analog_time() → var:lp_analog_time¶Returns
trueif analog time is enabled. Returns the current analog timeas a single Unicode character, accurate to the closest 30 minutes.Can be disabled by
LP_ENABLE_TIMEorLP_TIME_ANALOGset to0.New in version 2.0.