kyletimmermans / shell-color-prompt-tool

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Version 4.4 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 their foreground and background colors! All from the command line. Use brighter colors for extra pop!

Install as a Command - "scpt":

URL="https://github.com/kyletimmermans/shell-color-prompt-tool/releases/download/latest"; curl -q -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 -LJO "$URL/scpt.1" && sudo mv scpt.1 /usr/local/share/man/man1/

Temporary Use in Current Directory:

curl -q -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 on white / light-colored
                             terminal backgrounds

--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

Usage Notes

Note

  • 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)

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

  • $RPROMPT cannot contain newlines (\n)

  • 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 the custom parts options (Custom Text, Emoji, Other Prompt Expansion Variable).

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-Relase
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:
  -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
  -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
  -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 messsages showing incorrect range of color options
  -Updated and cleaned up help/usage flag output
v2.7:
  -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:
  -Better logic for ensuring gawk & gsed usage when using --comment-out or --omz flags
  -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

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 feaatures 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.

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 then give it some color, all from the command line

License:MIT License


Languages

Language:Shell 81.7%Language:Python 11.2%Language:Roff 7.1%