myshell 2.0.0
Loading...
Searching...
No Matches
msh_prompt.cpp File Reference

Prompt related utilities. More...

Functions

std::string expand_ps1 (const std::string &ps1)
 Expand a PS1 (Prompt String 1) format string into its corresponding values.
 
std::string generate_prompt ()
 Generate a prompt string.
 

Detailed Description

Prompt related utilities.

Function Documentation

◆ expand_ps1()

std::string expand_ps1 ( const std::string & ps1)

Expand a PS1 (Prompt String 1) format string into its corresponding values.

This function takes a PS1 format string as input and processes escape sequences to replace them with specific values. The supported escape sequences include:

\d - The current date in YYYY-MM-DD format.
\t - The current time in HH:MM:SS format.
\u - The current user.
\h - The current host.
\w - The current working directory.
\W - The current working directory's basename.
\n - A newline character.
\r - A carriage return character.
\s - The current shell.
\v - The current shell version.
\$ - The prompt character.

Parameters
ps1The PS1 format string to be expanded.
Returns
The expanded string with replaced escape sequences.

◆ generate_prompt()

std::string generate_prompt ( )

Generate a prompt string.

This function generates a prompt string by expanding the PS1 environment variable. If the PS1 environment variable is not set, the default prompt defined in msh_prompt.h is used.

Returns
The generated prompt string.