Page 1 of 3 123 LastLast
Results 1 to 10 of 24

Thread: Random terminal colors

  1. #1
    Join Date
    Apr 2006
    Location
    Bangalore
    Beans
    69
    Distro
    Ubuntu 10.04 Lucid Lynx

    Thumbs down Random terminal colors

    I want to have random colors on my terminal. Let's say I have a list of 10 pre-defined foreground and background color combinations stored somewhere. Everytime I invoke terminal, I want some script to to pick up a random color from the list and invoke the terminal using that. Is there an app that accomplishes this ? Or a link to a BASH script that does it?

  2. #2
    Join Date
    Nov 2008
    Location
    #!
    Beans
    1,749

    Re: Random terminal colors

    Quote Originally Posted by =CrAzYG33K= View Post
    I want to have random colors on my terminal. Let's say I have a list of 10 pre-defined foreground and background color combinations stored somewhere. Everytime I invoke terminal, I want some script to to pick up a random color from the list and invoke the terminal using that. Is there an app that accomplishes this ? Or a link to a BASH script that does it?
    From within terminal, you can have as many profiles as you want and then invoke which one you want when you start terminal. Not as clean as a script, but effective.

  3. #3
    Join Date
    Apr 2006
    Location
    Bangalore
    Beans
    69
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Random terminal colors

    Quote Originally Posted by VastOne View Post
    From within terminal, you can have as many profiles as you want and then invoke which one you want when you start terminal. Not as clean as a script, but effective.
    I know that, but I wanted an elegant script which would invoke random defined colors from an already defined source everytime I invoked terminal.

  4. #4
    Join Date
    Nov 2008
    Location
    #!
    Beans
    1,749

    Re: Random terminal colors

    Quote Originally Posted by =CrAzYG33K= View Post
    I know that, but I wanted an elegant script which would invoke random defined colors from an already defined source everytime I invoked terminal.
    This should give you the know how to create your scripts.

    Found by googling Linux + Terminal + Color

  5. #5
    Join Date
    Apr 2006
    Location
    Bangalore
    Beans
    69
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Random terminal colors

    @VastOne

    That thing just drives me crazy. I wanted a simple tweak to probably change my terminal color every time I opened up Terminal.. Python is probably the last thing that I'd want to try on.

    Something simpler, uhm, like modifying by .bashrc script?

  6. #6
    Join Date
    Jan 2008
    Beans
    4,757

    Re: Random terminal colors

    OK, no testing has been done here, just going off on a tangent presuming this will work.

    OK, I assume you use Gnome Terminal. Gnome Terminal colours are no longer customisable via a startup switch (and haven't been for some time).

    You can, however, write a wrapper script that:
    1. Has a predefined list of colours to mix
    2. Chooses a random one
    3. Sets the random colours via gconftool-2, and starts the real gnome-terminal.


    Code:
    #!/bin/sh
    
    # Predefined colour sets.
    BG_COLOURS=(
        FFFFFFFFDDDD  # Cream Yellow
        FFFFFFFFFFFF  # White
        000000000000  # Black
        000000000000  # Black
        000000000000  # Black
    )
    
    FG_COLOURS=(
        000000000000  # Black
        000000000000  # Black
        AAAAAAAAAAAA  # Grey
        0000FFFF0000  # Green
        FFFFFFFFFFFF  # White
    )
    
    # Number of elems in the array.
    NUM=${#FG_COLOURS[@]}
    
    # Pick a random number
    ELEM=$(($RANDOM % $NUM))
    
    # Set colours
    gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/background_color "#${BG_COLOURS[$ELEM]}"
    gconftool-2 --type string --set /apps/gnome-terminal/profiles/Default/foreground_color "#${FG_COLOURS[$ELEM]}"
    
    # Start gnome-terminal
    exec /usr/bin/gnome-terminal.distrib "$@"

    And to install:
    Code:
    sudo dpkg-divert --local --rename --add /usr/bin/gnome-terminal
    sudo install script-name.sh /usr/bin/gnome-terminal
    And to uninstall:
    Code:
    sudo unlink /usr/bin/gnome-terminal
    sudo dpkg-divert --local --rename --remove /usr/bin/gnome-terminal
    Some playing will be needed, yes. But hopefully a step in the right direction.

  7. #7
    Join Date
    Apr 2006
    Location
    Bangalore
    Beans
    69
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Random terminal colors

    Many thanks for the script, but now I guess I've screwed up my terminal. It wouldn't open up at all anymore..

    How do I uninstall it now and come back to the previous state?

    EDIT:

    I managed to do the 'uninstall' part coz' luckily I had another Terminal window open somewhere else.
    So why did Terminal refuse to open ??
    Last edited by =CrAzYG33K=; July 2nd, 2010 at 02:47 AM.

  8. #8
    Join Date
    May 2010
    Location
    Here
    Beans
    1,297
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Thumbs down Re: Random terminal colors

    You could literally create a cheap terminal...
    Something with printf, and SH the command.
    I am not that good with Shell Scripts, but I hope that can lead you into the right direction.

    Just one other question, Why do you want to have random terminal colors?
    I guess it could be entertaining to open a terminal...
    Actually, I will do the same myself!

    EDIT:

    How do you receive user input in bash shell scripts?
    Last edited by lkjoel; July 2nd, 2010 at 03:07 AM.

  9. #9
    Join Date
    May 2010
    Beans
    283

    Re: Random terminal colors

    Like this.
    Code:
    echo -n "O HAI THUR > "
    read input
    echo "You said $input"
    Or for multiple words,
    Code:
    echo -n "Name three colors > "
    read color1 color2 color3
    echo "You said $color1 $color2 $color3"
    To actually do something with this, just use an "if" function. Makes life a lot easier. I'm assuming you know how to do this.

  10. #10
    Join Date
    May 2010
    Location
    Here
    Beans
    1,297
    Distro
    Ubuntu 12.10 Quantal Quetzal

    Wink Re: Random terminal colors

    Yes I do.
    But how do you get the current location? (such as /home/user/test or /root etc...)
    And for the if thing, it is IF, ELIF, and ELSE?

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •