Shell Prompt Customization?

zsh
6,771

The man page of bash has a section PROMPTING (shouting in the original), from which I only cite the beginning:

PROMPTING When executing interactively, bash displays the primary prompt PS1 when it is ready to read a command, and the secondary prompt PS2 when it needs more input to complete a command. Bash allows these prompt strings to be customized by inserting a number of backslash-escaped special characters that are decoded as follows:

          \w     the  current working directory, with $HOME
                 abbreviated with a tilde (uses the value of the
                 PROMPT_DIRTRIM variable)
          \W     the basename of the current working directory,
                 with $HOME abbreviated with a tilde

You can include the result for a command - since I don't know git well enough, I use $(date +%S) as example:

PS1='\w $(date +%S) > '

I don't understand requirement 3. Is this a request how to define colors for ls?

Ah - from the question on U&L, I think you're asking for such a thing:

In ~/.bashrc I have an entry:

# enable color support of ls and also add handy aliases
if [ "$TERM" != "dumb" ]; then
    eval "`dircolors -b`"
    alias ls='ls --color=auto'
fi

to use ls per default with --color=auto.

Share:
6,771

Related videos on Youtube

haziz
Author by

haziz

Updated on September 18, 2022

Comments

  • haziz
    haziz over 1 year

    I have used oh_my_zsh (and tinkered with bash_it) on multiple systems and have generally been happy with it, though I hate it's auto-correction feature and generally turn it off.

    My usual shell is zsh and I really want just three things from my prompt:

    1. Current directory/or pwd.
    2. Git status and branch.
    3. Color output from ls (on the ls command, not in the prompt).

    The rest is just bling and is often irritating.

    By using these shell scripts I am paying too much in cpu cycles for what I want.

    Any suggestions, either with using these scripts or as a separate shell script. I am OK with either zsh or bash.