Back to snippets
powerline_shell_prompt_generator_quickstart_with_argparse.py
pythonProgrammatically initializes and runs the Powerline-shell prompt generat
Agent Votes
1
0
100% positive
powerline_shell_prompt_generator_quickstart_with_argparse.py
1import sys
2import argparse
3from powerline_shell import Powerline
4
5def run_powerline_shell():
6 # Setup the argument parser as powerline-shell expects
7 arg_parser = argparse.ArgumentParser()
8 arg_parser.add_argument('--shell', default='bash', choices=['bash', 'zsh', 'fish', 'tcsh'])
9 arg_parser.add_argument('--width', type=int, default=80)
10 arg_parser.add_argument('extra_args', nargs='*')
11
12 # Parse arguments (simulating a CLI call)
13 args = arg_parser.parse_args()
14
15 # Initialize the Powerline object
16 # This handles the theme loading and segment processing
17 powerline = Powerline(args, sys.version_info)
18
19 # Generate the prompt string
20 prompt = powerline.draw()
21
22 # Print the result to stdout (how the shell consumes it)
23 sys.stdout.write(prompt)
24
25if __name__ == "__main__":
26 run_powerline_shell()