Colour in shell for scripts

On my old server when I run ls on my scripts directory it appears as follows:

-r-x------ 1 root wheel 1105 Nov 22 17:53 restart*
(Mods: I left the code tags out as it removes the colour coding for some reason.)

So if its a script it shows as green and the red star at the end of the filename is red. (What does the red star mean by the way?)

I think I set this in a bash file in my profile on the old server but I would like to use the C shell only on my new server (for now). How can I set the colour coding in my .cshrc so its the same as it was in bash?

Can anyone assist with this please?
 
So if its a script it shows as green and the red star at the end of the filename is red. (what does the red star mean by the way?)

The star(asterisk) means the file has the executable bit set.

How can I set the colour coding in my .cshrc so its the same as it was in bash?

The C Shell uses the LS_COLORS environment variable to set filetype colors for the ls command. Please see tcsh(1) for further information.
 
Adding the following to .cshrc changes the colours for files/directories/executables in ls output (green/blue/red respectively); At least it works for me over SSH with default shell settings otherwise. I've no idea if it's possible to control the colours used.

Code:
setenv CLICOLOR
 
usdmatt said:
I've no idea if it's possible to control the colours used.
You can by setting LSCOLORS as explained in ls(1). You'll also find the explanation for CLICOLOR there.
 
Thanks for the replies!

My .cshrc file has the following:
Code:
alias ls        ls -FGalh
alias h         history 25
alias j         jobs -l
alias la        ls -aF
alias lf        ls -FA
alias ll        ls -lAF

# A righteous umask
umask 22

set path = (/sbin /bin /usr/sbin /usr/bin /usr/games /usr/local/sbin /usr/local/bin $HOME/bin)

setenv  EDITOR  ee
setenv  PAGER   more
setenv  BLOCKSIZE       K


setenv CLICOLOR


    if ( $?prompt ) then
        # screen(1) title-string escape sequence
        if ( $term != dumb ) then
            set title_esc='\ek\e\\'
        else
            set title_esc
        endif

        set tc_bold       = `echotc md`
        set tc_red        = `echotc AF 1`
        set tc_green      = `echotc AF 2`
        set tc_yellow     = `echotc AF 3`
        set tc_reset_attr = `echotc me`

        set promptchars = '.$'
        set prompt = "%{$tc_bold%}%{$tc_red%}(%{$tc_yellow%}%~%{$tc_red%})%{$tc_green$title_esc%}%#%{$tc_reset_attr%} "
    endif

But it's still not showing the executable files in green. What am I doing wrong?
 
Add this:
Code:
setenv CLICOLOR
And do source ~/.cshrc or simply log off and back in again.

Also make sure you are using a terminal that's capable of showing colors. If you use PuTTY set the TERM variable to xterm.
 
SirDice said:
Add this:
Code:
setenv CLICOLOR
And do source ~/.cshrc or simply log off and back in again.

Also make sure you are using a terminal that's capable of showing colors. If you use PuTTY set the TERM variable to xterm.

I have tried the following so far:

Code:
# echo $term

Which resulted in:
Code:
xterm

I also tried ls- G but this didn't make any difference.

I already have:

Code:
setenv CLICOLOR

set in my source ~/.cshrc.

Any other suggestions or things I can try? I currently have the red star next to the executable file but still no colour for executable files. I was expecting them to be listed in the green colour?
 
I use this in my .cshrc file:

Code:
alias ls        ls -halFG
setenv  LSCOLORS "ExGxFxdxCxDxDxhbadExEx"

This site explains something about the LSCOLORS environment variable: http://www.cyberciti.biz/tips/freebsd-h ... utput.html
Without the G in the ls -halFG, you will not get coloured output.

LS_COLORS, with underscore, is what is used in Linux, and has a different syntax. I am using the tcsh shell, and couldn't be bothered to install a different shell.

I did not have to set any $term value in FreeBSD. The one change I did make, was in PuTTY, to set the terminal-type string to putty. New Connection -> Connection -> Data. This is because the file with all the terminal definitions in FreeBSD has a special type for PuTTY, it's a bit of a liar, and not entirely xterm compatible.

Previously I had a lot of trouble finding the correct settings, and you first have to make your console work, with the colours you want. Then set your SSH client to work the same way. The other way around gave me an headache ;)

edit: Seems like LS_COLORS (with underscore) also should work, because of the tcsh shell. I haven't been successful with that, so if you find out how to do it, let it know.
 
I changed the following in my .cshrc
alias ls ls -halFG
setenv LSCOLORS "ExGxFxdxCxDxDxhbadExEx"

and this has done the trick. After logging off and back in again I could see my scripts show up in green with the red start next to them.

Many thanks!
 
Back
Top