# Colour in shell for scripts



## xy16644 (Jan 8, 2014)

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?


----------



## protocelt (Jan 8, 2014)

> 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.


----------



## usdmatt (Jan 8, 2014)

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.


```
setenv CLICOLOR
```


----------



## chrbr (Jan 8, 2014)

Dear @xy16644,

The command `ls -G` should provide what you expect.


----------



## SirDice (Jan 9, 2014)

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.


----------



## xy16644 (Jan 13, 2014)

Thanks for the replies!

My .cshrc file has the following:

```
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?


----------



## SirDice (Jan 13, 2014)

Add this:

```
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.


----------



## xy16644 (Jan 13, 2014)

Thanks @SirDice, I shall give this a try on the weekend!


----------



## xy16644 (Jan 16, 2014)

SirDice said:
			
		

> Add this:
> 
> ```
> setenv CLICOLOR
> ...



I have tried the following so far:


```
# echo $term
```

Which resulted in:

```
xterm
```

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

I already have:


```
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?


----------



## freethread (Jan 17, 2014)

Add also this to .cshrc


```
set color
```


----------



## JanJurkus (Jan 18, 2014)

I use this in my .cshrc file:


```
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.


----------



## xy16644 (Feb 1, 2014)

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!


----------

