osx - Subdirectories in prompt?

06
2014-04
  • ArtOfWarfare

    I'm working on making my prompt as useful as possible. Right now, it contains the date, time, and directory, along with a colored divider line so I can easily see where each batch of input starts.

    I was wondering - would it be possible to make it so my prompt automatically listed a few files / folders in a subdirectory? It seems like it would make for a nice cheat sheet kind of thing... instead of typing LSenter (I know, what a burden) and then getting the cheat sheet, I just automatically have it printed for me.

    Thoughts?

  • Answers
  • Oliver Salzburg

    Maybe you could just set up an alias?

    cd() { builtin cd "$1" ; ls ; }
    

    Code from http://superuser.com/a/355483/36744

  • Paul Capestany

    If you're interested in adding further utility to your prompt (and generally make your terminal experience better), it may be worth thinking about switching from bash to zsh for your shell. Check out the themes at oh my zsh to see how creative people get with their prompts.

    Beyond a better prompt though, the most useful thing I've found is zsh syntax highlighting — it makes writing command line scripts in terminal much nicer.


  • Related Question

    Bash command prompt overwrites the current line
  • Fernando

    My bash command prompt is:

    \e[32;1m[\e[m\h.\u \e[33;1m\W\e[m\e[32;1m]\e[0;36m::\e[m
    

    There must be something wrong with it, because on long lines, the current line is overwritten, instead of continuing on the next line.

    I'm using OSX and bash 3.2.48


  • Related Answers
  • cYrus

    Every non printable sequence of characters must be enclosed between \[ and \]:

    '\[\e[32;1m\][\[\e[m\]\h.\u \[\e[33;1m\]\W\[\e[m\e[32;1m\]]\[\e[0;36m\]::\[\e[m\]'