Skip to content

Create your own Zsh/Bash terminal prompt from scratch and give it some color, all from the command line

License

Notifications You must be signed in to change notification settings

kyletimmermans/shell-color-prompt-tool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Version 5.0 Zsh 5.8 Bash 5.1.16 Latest Commit Latest Release kyletimmermans Twitter

Shell-Color-Prompt-Tool

Customize your Zsh/Bash terminal prompt with a menu-style selection guide. Choose what info you want the prompt to display (username, hostname, symbols, etc.) and customize their foreground and background colors—all from the command line. Use brighter colors for extra pop!

Install as a Command - "scpt" (man page included):

URL="https://github.com/kyletimmermans/shell-color-prompt-tool/releases/download/latest"; curl -q -s -S -LJO "$URL/shell-color-prompt-tool.sh" && chmod a+x shell-color-prompt-tool.sh && sudo mv shell-color-prompt-tool.sh /usr/local/bin/scpt && curl -q -s -S -LJO "$URL/scpt.1" && sudo mv scpt.1 /usr/local/share/man/man1/

Temporary Use in Current Directory:

curl -q -s -S -LJO "https://github.com/kyletimmermans/shell-color-prompt-tool/releases/download/latest/shell-color-prompt-tool.sh" && chmod +x shell-color-prompt-tool.sh

Dependencies (For the --comment-out and --omz flags to work, if you choose to use them):

Linux (Debian-based)
sudo apt install -y gawk
macOS (Homebrew)
brew install gawk gnu-sed
macOS (MacPorts)
sudo port install gawk gsed

Sample Program Walkthrough

Sample Program Walkthrough

Resulting Prompt

Resulting Prompt

Note: I don't think anyone would create a prompt setup as chaotic as this one, but I wanted to show off all of the different variables/symbols/colors and how they're handled

Demo Video

Demo Video

Demo Resulting Prompt

Demo Resulting Prompt

Program Flags

-u, --usage, -h, --help      Show usage/help menu

-v, --version                Get program version. Reveal if a newer version is available on
                             GitHub

--uninstall                  Undoes the "Install as a Command" installation option. It will
                             delete /usr/local/bin/scpt (program) and the associated
                             man page

--comment-out                Comment out older prompt lines in .zshrc / .bashrc
                             e.g. PROMPT= / PS1= to help prevent conflicting prompt
                             definitions

--omz                        Disables your 'Oh My Zsh' theme if you have one, which could
                             get in the way of applying your new prompt

--light-mode                 Better color contrast for the color picker menu and other
                             various portions on white/light-colored terminal backgrounds.
                             If you plan on using this flag, always put it first, before
                             all other flags/args

--no-extras                  Don't automatically add a newline to the start of the prompt
                             and a space to the end of the prompt

--separate-file              Place the prompt string in a separate file instead of putting
                             it in .zshrc / .bashrc for any reason
                             E.g. --separate-file="~/test.txt"

--no-watermarks              Don't add the "# Added by Shell-Color-Prompt-Tool" comment to
                             .zshrc / .bashrc when adding the prompt string and don't add the
                             "# Commented out by Shell-Color-Prompt-Tool" comment when
                             using --comment-out or --omz

--char-table                 Display a table of cool UTF-8 characters for copy-and-pasting
                             into prompt part choices. If you can't see the characters or
                             if they show up incorrectly, ensure that your terminal supports
                             the UTF-8 charset

Char Table

Char Table

Usage Notes

Note

  • To add a number as a raw string and to not get it recognized as a menu-number choice, or to add 'n'/'N' and not exit the part selector, add a '!' before the number or 'n'/'N' e.g. '!14' yields '14' and '!n' yields 'n'

  • You don't need to add a newline character at the beginning of your prompt for spacing between actual prompts, one will be added for you. Same with a space after the prompt so there's space between the prompt and inputted commands, one will automatically be added for you. This feature can be disabled with the --no-extras flag

  • If you want to use the --comment-out or --omz flags, you must have 'gawk' and 'gsed' installed. On Mac, you'll need to install both. On Linux, you just need gawk, as gsed should already be your default sed version

  • --comment-out and --omz can break the config if the variables that are getting commented out, are defined within things like if-statements or case-statements

  • For the actual prompt string in the .zshrc / .bashrc file, some text editors like Sublime Text will show the ANSI escape characters like "\e[0;30m" as "<0x1b>". Use a text editor like Vim to show the raw text

  • Fullscreen terminals will be able to fit the spacing and styling of the interactive prompt the best

  • Colors may vary from system to system. When using the Custom RGB option, make sure your terminal supports TRUECOLOR (See here)

  • Some terminals may not display the background color for the "Tab" part, either in the preview or the actual prompt

  • If your command is too long, $RPROMPT will visually be temporarily overwritten

  • $RPROMPT cannot contain newlines (\n)

  • For part option "Custom Datetime", the datetime string is formatted using the 'strftime' function. See strftime(3) for more details. E.g.'%Y-%m-%d %k:%M:%S' would become: '2024-11-09 14:37:34'

  • For more prompt expansion variables not listed in this program: Zsh & Bash

Reset Prompt Back to Default

Don't like the prompt that got saved and want to change it back to its default?
1. In your Terminal type: vi ~/.zshrc or vi ~/.bashrc
2. Hit 'i' on your keyboard to start editing the file and remove the line(s) at the bottom of the file, e.g. "export PROMPT=etc" (Zsh) or "export PS1=etc" (Bash), that has the comment above it:
"# Added by Shell-Color-Prompt-Tool"
3. If you used --comment-out or --omz, uncomment your old prompt lines where the line above it says:
"# Commented out by Shell-Color-Prompt-Tool"
4. Hit 'escape (esc)' on your keyboard and then type :wq and hit enter
5. Back in your Terminal now, type source ~/.zshrc or source ~/.bashrc and hit enter
6. Restart your Terminal
7. Good as new!

Security Warning

Caution

Exercise caution when copy and pasting code from someone else and/or code that you do not understand, into any of the parts option picker. Which includes, but is not limited to, the "Custom Datetime", "Other Zsh/Bash Prompt Expansion Variable", and "Other Environment Variable" choices.

Shell prompts are fully capable of running commands and entire command pipelines.

Bad code can break your host (e.g. rm -rf something), and malicious code (e.g. reverse shell), can harm your host.

Program Workflow

graph TD;
    CST(Choose Shell Type)-- Zsh --->ZSH(Choose Prompt Type: $PROMPT, $RPROMPT, or Both)
    ZSH-->CHP(Choose Parts #40;Variables, Symbols, etc.#41;)
    CST-- Bash ---CHP
    CHP-->CSC(Choose Colors #40;Foreground and Background#41; for the Chosen Parts)
    CSC-->Preview(Preview the Prompt Before Saving)
    Preview-->Save(Save Prompt #40;Y/n#41;?)

    style CST stroke:#e81416
    style ZSH stroke:#ffa500
    style CHP stroke:#faeb36
    style CSC stroke:#79c314
    style Preview stroke:#487de7
    style Save stroke:#70369d
Loading

Changelog

v1.0: Initial-Release
v1.1:
  -Fixed: Issue where symbol choices misaligned with actual symbol output, found by @christiankuhtz
  -Added: period symbol to list of part choices
  -Added: --version and -v command line flag
  -Fixed: Prompt spacing and wording
v2.0:
  -Added: Support for Bash added so its been changed from "Zsh-Color-Prompt-Tool" to "Shell-Color-Prompt-Tool"
  -Added: Option to edit either PROMPT or RPROMPT, or both for Zsh
  -Added: Any added line(s) will have the comment above it, "# Added by Zsh Color Prompt Tool" so the user knows which prompts were generated by the program
  -Added: --omz, --light-mode, --comment-out, and --no-extras flags
  -Added: More symbols and colors to chose from in the menus
  -Added: automatic newline to front of generated prompt and extra space to the end for cleaner prompt and terminal UX
  -Fixed: Messing up a color no longer makes you redo the foreground and background color, just the one that was incorrect
  -Fixed: Issue where colors weren't properly escaped and could cause visual bugs
  -Added: -h/--help & -u/--usage flags
v2.5:
  -Added: Custom RGB color option
  -Fixed: error messages showing incorrect range of color options
  -Updated: and cleaned up help/usage flag output
v2.7:
  -Added: Force gawk usage, even on Linux, as there could be multiple awk types installed
  -Removed: OS-specific commands in --comment-out and --omz functionality (Everything is using gawk and gsed now)
  -Fixed: Some wording in the --help menu
v3.0:
  -Added: Better logic for ensuring gawk & gsed usage when using --comment-out or --omz flags
  -Added: The version flag will show reveal whether an updated version of the tool is available
v3.1:
  -Added: Error handling for version update check
v4.0:
  -Fixed: RPROMPT means "Right Prompt" in Zsh, not "Root Prompt"
    -Subsequently, you can now create a Zsh PROMPT and RPROMPT in one run
  -Fixed: Multiple "Custom Text" options don't stick together anymore
  -Fixed: Some Bash prompt expansion variables were not working properly
  -Fixed: --comment-out / --omz logic bug that could break adding comments above added lines
  -Added: "Other Zsh/Bash Prompt Expansion Variable" to parts menu/options
  -Added: Newline to parts menu/options
    -Can handle multiline prompts now
  -Added: --separate-file flag
  -Added: --no-watermarks flag
  -Added: "Box Drawing" symbols to parts menu/options
  -Added: "Arrows" symbols to parts menu/options
  -Refactored and simplified file output logic section
  -Refactored flag parsing - Now all parsing done in case statement
  -Added more info and formatting to usage/help output
  -General code cleanup: Removed redundant or unnecessary code, wrapped code in functions
  -Better prompt preview now that RPROMPT is printed on the right side of the terminal
  -Log levels and coloring added to log statements
v4.1:
  -Added: Traps to handle SIGINT/SIGTERM signals while program is running
  -Added: --uninstall flag (Deletes scpt & man page)
  -Refactor: Used ShellCheck linter - applied minor fixes
  -Repo: Created man page
  -Repo: Added screenshot automation/helper files to /media
v4.2:
  -Fixed: Further improved filename arg parsing for the --separate-file flag
  -Fixed: Handle unknown flags/options properly
  -Fixed: For error logging, swapped "> /dev/stderr" to ">&2" for better portability
v4.3:
  -Added: Better formatting for prompt preview section
  -Added: When displaying preview of prompt, the RPROMPT preview will now have a space at the end, just like the actual $RPROMPT does
v4.4:
  -Added: More arg parsing and error handling for --separate-flag and moved all its logic into separate_file()
  -Added: 'read' now using -r flag to avoid backslash issues for inputs
  -Refactor: Removed redundant code, de-nested several if-statements
v5.0:
  -Fixed: Certain prompt expansion variables were swapped out or renamed because they did not work or exist
  -Added: "Custom Datetime" part to "Prompt Expansion Variables" section
  -Added: "Environment Variables" section to parts menu/options
  -Added: Tab (\t) to the "Special" section of the parts menu/options
  -Added: --char-table flag - Shows cool UTF-8 symbols that can be copy-pasted for use in prompt creation
  -Added: escape_chars() to prevent any interpretation issues of char literals in the evaluated prompt
  -Added: Improved wording of menu instructions
  -Changed/Removed: No more "Symbols", "Arrows", or "Custom" sections in parts menu/options. Users can now enter in symbols and text without needing to pick a number
  -Refactor: When doing checks for certain part choices, actual part will be referenced and not its index number since that can change in new versions
  -Refactor: Removed custom_array from prompt creation workflow to simplify process
  -Refactor: parts_array stores (TYPE,PART) for each part and color_array stores (FG,BG) for each part. Resulting in easier checks and keeping related info together
  -Refactor: Created variables for setting range checks of parts and colors so only one part needs to be changed when the range is added to
  -Refactor: Better declaration and use of light mode throughout the program

Prompt Inspiration

Need inspiration and ideas for cool prompts? Check out this list!

Zsh:

Bash:

FAQ

What’s the point of making this, hasn’t this been done already?

I've seen a few programs, mainly web-based ones, that help you to build out and customize shell prompts. I wanted to make something that was native to the shell environment, no need to copy from the website and then needing to paste into your config on the command line. I wanted it to be all in one place. There's a few other features I wanted to see in a prompt customization program as well:

  • Show the user all of the options they have for customizing their prompt, which includes all of the terminal variables (username, hostname, etc.) and many of the colors available
  • Simple menu-style system for choosing which components and colors you'd like to be in the prompt
  • No additional software required (besides for 2 flags, potentially) - Most Unix-based systems (Linux, macOS) already have Bash pre-installed, so there’s no need to install any additional interpreters or libraries
  • No need to edit the .bashrc / .zshrc file at all, no need to copy and paste the variable in there. The program will put it in there for you

Will you support other shells?

The plan is to potentially support other shells in the future. A big refactor would be needed to be able to support other ones. Right now Zsh and Bash are the main shells that are supported, but if you put in an issue or even submit a PR, I can work with you to add support for another shell.

Why does the program use a Bash shebang instead of Zsh, sh, or another shell?

A Bash shebang is used because it covers both Bash and Zsh users. Almost everyone that has Zsh, has Bash installed. However, not everyone that has Bash, has Zsh installed. Therefore, the Bash shebang covers all use cases. We can't use the "sh" shebang because that could invoke a shell that's not Bash or Zsh.

How do I get a multiline $RPROMPT like with Powerlevel10k or {insert OhMyZsh theme here}?

What themes like Powerlevel10k are doing to get the multiline RPROMPT effect, is using a print statement that runs every time, just before the PROMPT and RPROMPT are drawn. The extra line is not actually a part of the $RPROMPT variable, it just appears to be with some clever programming. romkatv, who created Powerlevel10k, has a code snippet here that explains how its done.

Does this project have anything to do with AppleScript and its .scpt files?

Nope! I realized too late after naming this project that .scpt files existed.

About

Create your own Zsh/Bash terminal prompt from scratch and give it some color, all from the command line

Resources

License

Stars

Watchers

Forks

Packages

No packages published