prompt Tools
The prompt supports a few things:
user@host ~/pathprefix- Exit status of previous command is displayed
- Manage a queue of functions to run on each shell command
Tools to work with the shell prompt PS1
bashPromptModule_binBuildis a module forbashPromptwhich sets the Zesk Build home depending on your current directorybashPromptModule_ApplicationPathis a module forbashPromptwhich displays the current application/path as a badge in iTermconsoleDefaultTitlecan be used as a module to set the current title
Examples:
bashPrompt bashPromptModule_binBuild consoleDefaultTitle
bashPrompt --colors "$(bashPromptColorScheme forest)"
Functions
Usage
bashPrompt [ module ] [ --remove module ] [ --reset ] [ --list ] [ --first ] [ --last ] [ --order order ] [ --format promptFormat ] [ --success successText ] [ --failure failureText ] [ --label promptLabel ] [ --colors colorsText ] [ --skip-prompt ] [ --help ]
Bash prompt creates the PS1 prompt with the following extra features:
- Easy colorization
- Easy customization
- Return code of prior command dynamically displayed in following prompt
- Easily extend your bash prompt with modules
PROMPT MODULES
Modules are any binary or executable to run each prompt, and can be added, removed or managed here.
COLORS
The --colors are currently a :-separated list of color names (not escape codes), in order:
1. Success color (Array index 0)
2. Failure color (Array index 1)
3. User color (Array index 2)
4. Host color (Array index 3)
5. Directory color (Array index 4)
Arguments
module- Callable. Optional. Module to enable or disable.--remove module- Callable. Optional. Remove the module specified (should match exactly)--reset- Flag. Optional. Remove all prompt modules.--list- Flag. Optional. List the current modules. Modules are also added or removed, otherwise no changes are made.--first- Flag. Optional. Add all subsequent modules first to the list.--last- Flag. Optional. Add all subsequent modules last to the list.--order order- UnsignedInteger. Optional. Set the order index for this prompt. 0 is first, higher numbers are later.--format promptFormat- String. Optional. Display this label on each prompt.--success successText- EmptyString. Optional. Text to display in the prompt when the previous command succeeded.--failure failureText- EmptyString. Optional. Text to display in the prompt when the previous command failed.--label promptLabel- String. Optional. The prompt format string. See PROMPT FORMATTING below--colors colorsText- String. Optional. Set the prompt colors. See COLORS below.--skip-prompt- Flag. Optional. Do not modify the prompt.--help- Flag. Optional. Display this help.
Debugging settings
Append to the value of BUILD_DEBUG (a comma-delimited (,) list) and add these tokens to enable debugging:
bashPrompt- Debug prompt command execution
Return codes
0- Success1- Environment error2- Argument error
Environment
- PROMPT_COMMAND - Callable. Command is run prior to displaying the prompt, receives exit status from prior command
Usage
bashPromptColorScheme [ colorScheme ] [ --help ]
Color schemes for prompts Options are: - forest - light (default) - dark
Arguments
colorScheme- String. Optional. Color scheme to choose:light,dark,forest--help- Flag. Optional. Display this help.
Return codes
0- Success1- Environment error2- Argument error
Usage
bashPromptColorsFormat text
Given a list of color names, generate the color codes in a colon separated list
Writes to standard output
Outputs color codes separated by colons.
Arguments
text- String. Required. List of color names in a colon separated list.
Return codes
0- Success1- Environment error2- Argument error
Requires
decorations read inArray decorate listJoin
Usage
bashPromptMarkers [ --help ] [ prefix ] [ suffix ]
Set markers for terminal integration Outputs the current marker settings, one per line (0, 1, or 2 lines will be output).
Arguments
--help- Flag. Optional. Display this help.prefix- EmptyString. Optional. Prefix for all prompts.suffix- EmptyString. Optional. Suffix for all prompts.
Return codes
0- Success1- Environment error2- Argument error
Usage
bashUserInput [ --help ] [ ... ]
Prompt the user properly honoring any attached console.
Arguments are the same as read, except:
-r is implied and does not need to be specified
Arguments
--help- Flag. Optional. Display this help....- Arguments. Optional. Identical arguments toread(but includes-r)
Return codes
0- Success1- Environment error2- Argument error
Bash Prompt Modules
-
bashPromptModule_BuildProject - Check which bin/build we are running and keep local to (source)
-
bashPromptModule_ApplicationPath - Show current application and path as a badge in iTerm2 (source)
-
bashPromptModule_dotFilesWatcher - Watches your HOME directory for
.files which are added (source) -
bashPromptModule_TermColors - Sets the console colors based on the project you are (source)
To enable:
bashPrompt bashPromptModule_binBuild bashPromptModule_ApplicationPath
bashPromptModule_BuildProject
Check which bin/build we are running and keep local to
Usage
bashPromptModule_BuildProject
Check which bin/build we are running and keep local to current project. Activates when we switch between projects.
- Re-sources bin/build so versions do not conflict.
- Runs hook project-deactivate in the old project (using that bin/build library)
- Runs the project-activate hook in the new project
- Displays the change in Zesk Build version
Arguments
- none
Return codes
0- Success1- Environment error2- Argument error
bashPromptModule_ApplicationPath
Show current application and path as a badge in iTerm2
Usage
bashPromptModule_ApplicationPath
Show current application and path as a badge in iTerm2
Arguments
- none
Examples
bashPrompt bashPromptModule_ApplicationPath
Return codes
0- Success1- Environment error2- Argument error
Usage
bashPromptModule_dotFilesWatcher
Watches your HOME directory for . files which are added and unknown to you.
Arguments
- none
Examples
bashPrompt bashPromptModule_dotFilesWatcher
Return codes
0- Success1- Environment error2- Argument error
Requires
sort buildEnvironmentGetDirectory touch returnEnvironment read basename inArray decorate printf confirmYesNo statusMessage grep rm
Usage
bashPromptModule_TermColors
Sets the console colors based on the project you are currently in.
Define your color configuration file (values of bg=FFF etc. one per line, comments allowed)
Will fill in missing bright or non-bright colors which are unspecified. (blue implies br_blue and so on)
Sets decorateStyle for valid styles
Support for iTerm2 is built-in and automatic
Arguments
- none
Debugging settings
Append to the value of BUILD_DEBUG (a comma-delimited (,) list) and add these tokens to enable debugging:
term-colors- WhenbashPromptModule_TermColorsis enabled, will show colors and how they are applied
Examples
bashPrompt --order 80 bashPromptModule_TermColors
Return codes
0- Success1- Environment error2- Argument error
Environment
- BUILD_TERM_COLORS_STATE - String. State to store state of current terminal color state
Requires
buildHome statusMessage buildEnvironmentGetDirectory directoryRequire shaPipe --cachedecorate buildDebugEnabled iTerm2SetColors consoleConfigureColorMode
dotFilesWatcher Tools
Example during setup:
dotFilesApproved bash > "$(dotFilesApprovedFile)"
And then in your bash prompt:
bashPrompt bashPromptModule_dotFilesWatcher
Any new dot files which appear will then show a warning in your console.
Usage
dotFilesApprovedFile [ --help ]
The dot files approved file. Add files to this to approve.
Arguments
--help- Flag. Optional. Display this help.
Return codes
0- Success1- Environment error2- Argument error
Usage
dotFilesApproved [ listType ]
Lists of dot files which can be added to the dotFilesApprovedFile
If none specified, returns bash list.
Special value all returns all values
Arguments
listType- String. Optional. One ofall,bash,git,darwin, ormysql
Return codes
0- Success1- Environment error2- Argument error
reloadChanges Tools
Usage
reloadChanges --source source [ --name name ] --path path --file file [ --stop ] [ --show ] [ source ] [ path|file ... ] [ --help ]
Watch or more directories for changes in a file extension and reload a source file if any changes occur.
Arguments
--source source- File. Required. Source file to source upon change.--name name- String. Optional. The name to call this when changes occur.--path path- Directory. Required. OneOrMore. A directory to scan for changes in.shfiles--file file- File. Required. OneOrMore. A file to watch.å--stop- Flag. Optional. Stop watching changes and remove all watches.--show- Flag. Optional. Show watched settings and exit.source- File. Optional. If supplied directly on the command line, sets the source.- path|-
file ...- DirectoryOrFile. Optional. Ifsourcesupplied, then any other command line argument is treated as a path to scan for changes. --help- Flag. Optional. Display this help.
Debugging settings
Append to the value of BUILD_DEBUG (a comma-delimited (,) list) and add these tokens to enable debugging:
reloadChanges- prompt module will show debugging informationreloadChangesProfile- prompt module will show profiling information
Return codes
0- Success1- Environment error2- Argument error
Background Process Tools
Arguments
--verbose- Flag. Optional. Be verbose.--report- Flag. Optional. Show a long report of all processes.--summary- Flag. Optional. Show a summary of all processes.--monitor- Flag. Optional. Interactively show report and refresh.--watch- Flag. Optional. Repeat showing summary.--verbose-toggle- Flag. Optional. Toggle the global verbose reporting.--terminate- Flag. Optional. Terminate all processes and delete all background process records.--go- Flag. Optional. Check all process states and update them.--new-only- Flag. Optional. Output a message for new processes only.--stop stopSeconds- PositiveInteger. Optional. Check every stop seconds after starting to see if should be stopped.--wait waitSeconds- PositiveInteger. Optional. After stopping, wait this many seconds before trying again.--frequency checkSeconds- PositiveInteger. Optional. Check condition at this frequency.condition ...- Callable. Required. Condition to test. Output of this is compared to see if we should stop process and restart it.--- Delimiter. Required. Separates command.command ...- Callable. Required. Function to run in the background.--help- Flag. Optional. Display this help.
Return codes
0- Success1- Environment error2- Argument error