| 1 | import os |
| 2 | import subprocess |
| 3 | import click |
| 4 | |
| 5 | |
| 6 | @click.command("Generate a PS1 prompt") |
| 7 | @click.option( |
| 8 | "--branch-style", |
| 9 | "-b", |
| 10 | default="\\e[32m", |
| 11 | help="The style used for the branch string.", |
| 12 | ) |
| 13 | @click.option( |
| 14 | "--user-style", "-u", default="\\e[33m", help="The style used for the user string." |
| 15 | ) |
| 16 | @click.option( |
| 17 | "--hostname-style", |
| 18 | "-h", |
| 19 | default="\\e[34m", |
| 20 | help="The style used for the hostname string.", |
| 21 | ) |
| 22 | @click.option( |
| 23 | "--path-style", "-p", default="\\e[35m", help="The style used for the path string." |
| 24 | ) |
| 25 | @click.option( |
| 26 | "--additional-info", |
| 27 | "-a", |
| 28 | default="\\d \\t\\n$(random_quote)", |
| 29 | help="Additional information to display in the prompt on the second line.", |
| 30 | ) |
| 31 | @click.option( |
| 32 | "--prompt-symbol", |
| 33 | "-s", |
| 34 | default="🚀", |
| 35 | help="The symbol used to indicate the prompt.", |
| 36 | ) |
| 37 | @click.option( |
| 38 | "--line-start", |
| 39 | "-l", |
| 40 | default=">>> ", |
| 41 | help="The symbol used at the beginning of each new line in the prompt.", |
| 42 | ) |
| 43 | def main( |
| 44 | branch_style, |
| 45 | user_style, |
| 46 | hostname_style, |
| 47 | path_style, |
| 48 | additional_info, |
| 49 | prompt_symbol, |
| 50 | line_start, |
| 51 | ): |
| 52 | branch = subprocess.getoutput("git branch --show-current") |
| 53 | branch_str = f" ({branch_style}{branch}\\e[0m)" if branch else "" |
| 54 | additional_info = f"{additional_info}\\n" if additional_info else "" |
| 55 | |
| 56 | ps1_prompt = ( |
| 57 | f"{line_start}{user_style}\\u" |
| 58 | f"{hostname_style}@\\h" |
| 59 | f"{path_style}:\\w" |
| 60 | f"{branch_str}\\n" |
| 61 | f"{additional_info}" |
| 62 | f"\\e[0m{prompt_symbol} " |
| 63 | ).replace("\\n", f"\\n{line_start}") |
| 64 | |
| 65 | |
| 66 | print(ps1_prompt) |
| 67 | |
| 68 | |
| 69 | if __name__ == "__main__": |
| 70 | main() |