10.5.x Terminal Tips

Discussion in 'macOS' started by jmxp69, Dec 30, 2008.

  1. jmxp69 macrumors 6502

    Joined:
    Dec 10, 2008
    #1
    I finally decided to spend a little time tweaking terminal, and I thought I'd share some of what I came up with.

    1) Display files in color:

    - man ls will show you all of this, but I'll summarize
    - Use the G option with ls. I put an alias for ls in my ~/.profile that looks like this:
    Code:
    alias dir='ls -lGhF'
    
    l = Long Format
    G = Colorize output
    h = human readable file sizes
    F = Displays various characters after certain file types such as a / after directories.

    2) To modify the default colors for files, add to your ~/.profile:
    Code:
    LSCOLORS='exfxcxdxbxegedabagacad' ; export LSCOLORS
    
    ** This is the default Mac Terminal Color Set

    Change ex fx cx dx bx eg ed ab ag ac ad as follows:
    * The first byte is the foreground color, the second byte is the background color.

    ex = 1. Directory: blue/default
    fx = 2. Symbolic Link: magenta/default
    cx = 3. Socket: green/default
    dx = 4. Pipe: brown/default
    bx = 5. Executable: red/default
    eg = 6. Block Special: blue/cyan
    ed = 7. Character Special: blue/brown
    ab = 8. Executable with setuid: black/red
    ag = 9. Executable with setgid: black/cyan
    ac = 10. Directory o+w with S bit: black/green
    ad = 11. Directory o+w w/o S bit: black/brown

    The color designators are as follows:

    a black
    b red
    c green
    d brown
    e blue
    f magenta
    g cyan
    h light grey
    A bold black, usually shows up as dark grey
    B bold red
    C bold green
    D bold brown, usually shows up as yellow
    E bold blue
    F bold magenta
    G bold cyan
    H bold light grey; looks like bright white
    x default foreground or background

    3) Customize your bash prompt:

    This is normally a tricky endeavor due to escape sequences and syntax, so I've made it a little easier with some variables in .profile I found the titlebar and user color here. I just added the rest of the colors so you can select what you want, and expanded on his basic prompt a bit. The following goes in ~/.profile of course.
    Code:
    ENDCOLOR="\[\e[0m\]"
    BLACK="\[\e[0;30m\]"
    BLUE="\[\e[0;34m\]"
    GREEN="\[\e[0;32m\]"
    CYAN="\[\e[0;36m\]"
    RED="\[\e[0;31m\]"
    PURPLE="\[\e[0;35m\]"
    BROWN="\[\e[0;33m\]"
    GREY="\[\e[0;37m\]"
    DGREY="\[\e[1;30m\]"
    YELLOW="\[\e[1;33m\]"
    WHITE="\[\e[1;37m\]"
    
    B_BLUE="\[\e[1;34m\]"
    B_GREEN="\[\e[1;32m\]"
    B_CYAN="\[\e[1;36m\]"
    B_RED="\[\e[1;31m\]"
    B_PURPLE="\[\e[1;35m\]"
    
    case $(id -u) in
        0)
    #	   STARTCOLOR='\[\e[31m\]';
    	   STARTCOLOR=$B_RED;
            ;;
        *)
    #           STARTCOLOR='\[\e[36m\]';
                STARTCOLOR=$B_GREEN;
            ;;
    esac
    
    
    
    case $TERM in
        xterm*)
    	TITLEBAR='\[\e]0;\u@\h \w \007\]';
            ;;
        *)
            TITLEBAR="";
            ;;
    esac
    
    PS1="[$DGREY\A $STARTCOLOR\u$GREY@$STARTCOLOR\h$GREY] <$DGREY\# $YELLOW\w/$GREY> $GREY$TITLEBAR"
    
    The following is the result of this work. The prompt shows:

    As a regular user, the username and hostname are Bold Green
    As the root user, the username and hostname are Bold Red
    The title bar of the window shows the username, host and current path

    Dark Grey Date \A
    Bright Green Username \u
    Bright Green Hostname \h
    Dark Grey Current Session Command Count \#
    Yellow Path \w (I use the / to finish it off)

    I left the default directory colors alone except for changing the directories from Blue to Bold Blue.

    Enjoy,

    J
     

    Attached Files:

  2. austinsevo macrumors regular

    Joined:
    Jun 9, 2008
    Location:
    Sherman Oaks: California
  3. jmxp69 thread starter macrumors 6502

    Joined:
    Dec 10, 2008
    #3
    Update: I found two small issues in the PS1 prompt from above that are corrected with:

    PS1="$GREY[$DGREY\A $STARTCOLOR\u$GREY@$STARTCOLOR\h$GREY] <$DGREY\# $YELLOW\w/$GREY> $ENDCOLOR$TITLEBAR"

    I also found another thread on this forum suggesting iTerm from Sourceforge. Apple's terminal app does most of what iTerm does, but the two things I like about iTerm are that it allows transparent windows with Blur and it copies on select.

    Transparent terminal windows are cool, but I find that I have to set the transparency threshold pretty low otherwise when the terminal window is over top of a bright background, the contents of the terminal window become difficult to read.

    Copy on select is very cool, and I missed that feature from putty on Windows. Glad to have that back.

    Here's a picture of the fixed prompt and the iTerm blur.
     

    Attached Files:

  4. b2w macrumors newbie

    Joined:
    Mar 29, 2009
    #4
    Font Type?

    What Font Type do you use. I currently use Monaco.
    Also my colors seem to be far more shrill, I would like them a little softer like you screenshot shows them too.
     
  5. NicP macrumors 6502

    Joined:
    Jun 14, 2005
    #5
    check "use bright colors for bold text" in the terminal prefs
     
  6. jmxp69 thread starter macrumors 6502

    Joined:
    Dec 10, 2008
    #6
    Monaco 12pt, Antialias text, Display ANSI, Use bright colors for bold text.

    J
     
  7. b2w macrumors newbie

    Joined:
    Mar 29, 2009
    #7
    Thnx. Colors still seem a little of(I guess depends a little on displays too), but it is far better now.
    Could have thought of that myself thouhg, but just skipped over it when I opened the preferences the last time ;-).
     

Share This Page