Terminal Challenge! v.myshellisbetterthanyours

Discussion in 'OT Technology' started by geekierthanyou, Jan 30, 2009.

  1. geekierthanyou

    geekierthanyou Crews: DSLR, Brolie, Classic Car, Gun, Zombie, Pro

    Joined:
    May 11, 2007
    Messages:
    3,425
    Likes Received:
    0
    Location:
    Covina, CA
    [​IMG]

    Notice the what happens when I type an invalid command on the last two lines :)
     
  2. mobbarley

    mobbarley Active Member

    Joined:
    Mar 4, 2005
    Messages:
    9,256
    Likes Received:
    2
    Location:
    Sydney
  3. Pitt

    Pitt 1-1-11 — Never Forget OT Supporter

    Joined:
    Jul 1, 2003
    Messages:
    150,314
    Likes Received:
    0
    Location:
    Injured Reserve
    .
     
  4. xenon supra

    xenon supra OT Supporter

    Joined:
    Feb 3, 2005
    Messages:
    33,675
    Likes Received:
    0
    Location:
    San Diego, CA
    user name ironing
     
  5. JCrev

    JCrev Where is your god now? OT Supporter

    Joined:
    Jul 18, 2004
    Messages:
    3,852
    Likes Received:
    11
    Location:
    Montreal, Quebec
    I have my prompt change color on failed commands as well as a few other features. MY prompt definitly beats yours.

    [​IMG]

    Code:
    #Custom Prompt [History][username][path] red if last command failed set title to full path
    export PROMPT_COMMAND='PS1="\[\033[0;33m\][\!]\`if [[ \$? = "0" ]]; then echo "\\[\\033[32m\\]"; else echo "\\[\\033[31m\\]"; fi\`[\u][\`if [[ `pwd|wc -c|tr -d " "` > 18 ]]; then echo "\\W"; else echo "\\w"; fi\`]\$\[\033[0m\] "; echo -ne "\033]0;`pwd`\007"' 
     
  6. geekierthanyou

    geekierthanyou Crews: DSLR, Brolie, Classic Car, Gun, Zombie, Pro

    Joined:
    May 11, 2007
    Messages:
    3,425
    Likes Received:
    0
    Location:
    Covina, CA
    I included a screen shot, so clearly I win
     
  7. JCrev

    JCrev Where is your god now? OT Supporter

    Joined:
    Jul 18, 2004
    Messages:
    3,852
    Likes Received:
    11
    Location:
    Montreal, Quebec
  8. geekierthanyou

    geekierthanyou Crews: DSLR, Brolie, Classic Car, Gun, Zombie, Pro

    Joined:
    May 11, 2007
    Messages:
    3,425
    Likes Received:
    0
    Location:
    Covina, CA
    Wait, aside from the numbers at the beginning ours are almost the same... yours doesn't have happy/sad faces though and you added brackets
     
  9. geekierthanyou

    geekierthanyou Crews: DSLR, Brolie, Classic Car, Gun, Zombie, Pro

    Joined:
    May 11, 2007
    Messages:
    3,425
    Likes Received:
    0
    Location:
    Covina, CA
    That being said though, yours is quite nice... I think you should add a happy and sad face though. What are the numbers for?
     
  10. geekierthanyou

    geekierthanyou Crews: DSLR, Brolie, Classic Car, Gun, Zombie, Pro

    Joined:
    May 11, 2007
    Messages:
    3,425
    Likes Received:
    0
    Location:
    Covina, CA
    Ohh, your screenshot is a tiff that's why it isn't embedding
     
  11. JCrev

    JCrev Where is your god now? OT Supporter

    Joined:
    Jul 18, 2004
    Messages:
    3,852
    Likes Received:
    11
    Location:
    Montreal, Quebec
    They are very different. Mine tells me what command number it is in the bash history so I can just type #(and the number) to repeat the command. I have the title of the terminal window set to the current working path and after my user name I include as many portions of the current path that will fit and be under 18 characters. As well as the color coding.
     
  12. geekierthanyou

    geekierthanyou Crews: DSLR, Brolie, Classic Car, Gun, Zombie, Pro

    Joined:
    May 11, 2007
    Messages:
    3,425
    Likes Received:
    0
    Location:
    Covina, CA

    Holy crap I'm stealing that... I've been wanting to do that. I personally just like my current directory listed though... I must say that my prompt is in danger though!
     
  13. geekierthanyou

    geekierthanyou Crews: DSLR, Brolie, Classic Car, Gun, Zombie, Pro

    Joined:
    May 11, 2007
    Messages:
    3,425
    Likes Received:
    0
    Location:
    Covina, CA
    echo -ne "\033]0;`pwd`\007" I LOVE THIS PART OF YOUR SCRIPT
     
  14. mds2004

    mds2004 OT Supporter

    Joined:
    Jul 10, 2004
    Messages:
    10,600
    Likes Received:
    2
    Location:
    Bakersfield, CA
    This thread



























    My head
     
  15. geekierthanyou

    geekierthanyou Crews: DSLR, Brolie, Classic Car, Gun, Zombie, Pro

    Joined:
    May 11, 2007
    Messages:
    3,425
    Likes Received:
    0
    Location:
    Covina, CA
    Okay Runki, I think I have something here that you will like!

    I have merged two scripts, stealing from you and another site here: http://pseudogreen.org/blog/set_tab_names_in_leopard_terminal.html

    to get:
    Code:
        # Define how Bash prompt looks like:
        #
        # User @ Host - working dir
        #export PS1=”\u@\h\w$ ”
        export PS1="\[\e[01;32m\]\u@\h \[\e[01;34m\]\W \`if [ \$? = 0 ]; then echo -e '\e[01;32m:)'; else echo -e '\e[01;31m:('; fi\` \[\e[01;34m\]$\[\e[00m\]"
        
        # Cli Colors
        export CLICOLOR=1
        # use yellow for dir’s
        export LSCOLORS=exfxcxdxbxegedabagacad
    
        # history handling
        #
        # Erase duplicates
        export HISTCONTROL=erasedups
        # resize history size
        export HISTSIZE=10000
        # append to bash_history if Terminal.app quits
        shopt -s histappend
        
    function set_window_and_tab_title
    {
        local title="$1"
        if [[ -z "$title" ]]; then
            title="root"
        fi
    
        local tmpdir=~/Library/Caches/${FUNCNAME}_temp
        local cmdfile="$tmpdir/$title"
    
        # Set window title
        echo -ne "\033]0;`pwd`\007"
    
        # Set tab title
        if [[ -n ${CURRENT_TAB_TITLE_PID:+1} ]]; then
            kill $CURRENT_TAB_TITLE_PID
        fi
        mkdir -p $tmpdir
        ln /bin/sleep "$cmdfile"
        "$cmdfile" 10 &
        CURRENT_TAB_TITLE_PID=$(jobs -x echo %+)
        disown %+
        kill -STOP $CURRENT_TAB_TITLE_PID
        command rm -f "$cmdfile"
    }
    
    PROMPT_COMMAND='set_window_and_tab_title "${PWD##*/}"'
    
    Which changes the tab names, as WELL as the whole window title!
     
  16. kabloded

    kabloded Guest

  17. JCrev

    JCrev Where is your god now? OT Supporter

    Joined:
    Jul 18, 2004
    Messages:
    3,852
    Likes Received:
    11
    Location:
    Montreal, Quebec
    Even after reading the description on the website I can't get my head around what he's doing to set the tab titles... but it works.

    Code:
     #Case-Insensitive Tab Complete
    bind "set completion-ignore-case on" 
    Is the only thing I would add in to your script.
     
  18. geekierthanyou

    geekierthanyou Crews: DSLR, Brolie, Classic Car, Gun, Zombie, Pro

    Joined:
    May 11, 2007
    Messages:
    3,425
    Likes Received:
    0
    Location:
    Covina, CA
    It's actually REALLY damned cool.

    What he is doing is creating a symlink as the name of the file you ran, and executing that link so instead of seeing "ssh" or "bash" you see the name of your folder. ln -s myfoldername ssh && ssh locahost will show myfoldername in the tab!
     

Share This Page