![]() |
ubuntu.com - launchpad.net - ubuntu help
|
|
|||||||
Ubuntu 9.10 is out!!!
When downloading Ubuntu 9.10 please consider using bittorrent to get your copy of Ubuntu. The Ubuntu Developers Summit for Lucid Lynx will be held the week of 16-Nov-2009 till 20-Nov-2009 in Dallas, TX USA. Visit the the Ubuntu wiki for more information about UDS and how to participate remotely. |
|
Tutorials & Tips The place to find Ubuntu related Tips & Tricks. |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Grande Half-n-Half Cinnamon Ubuntu
![]() Join Date: Apr 2005
Location: Frequent Flyer Underworld
Beans: 792
|
You ever fire up an xterm and perform an "ls" command? Sure you have! If so, did you ever wish that:
NOTE: All commands to be entered in a terminal shell or changes made to a file are hilighted in red. You only need to cut/paste those items which are hilighted, the surrounding text is left for illustration purposes. 1. Edit the '.bashrc' file. You need to make a few small changes to the existing bash script.
Code:
skoal@morpheus:///tmp $ cd && dircolors -p > .dircolors NOTE: Lines 34-41 within this file give you the color codes for three specific keys: attribute, text, and background. You can choose to use all three keys, or simply pick and choose only those keys you wish to apply. Look at some of the pre-defined ones you may already recognize as a good example to follow.
Code:
skoal@morpheus:///tmp $ cd && . .bashrc and, just to see your handy work, look at these two environmental variables: Code:
skoal@morpheus://~ $ set | grep 'DIR_COLORS\|LS_COLORS' DIR_COLORS=/home/skoal/.dircolors LS_COLORS='no=00:fi=00:di=00;34:ln=01;36:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.gz=01;31:*.bz2=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.avi=01;35:*.fli=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.ogg=01;35:*.mp3=01;35:*.wav=01;35:*.c=00;32:*.cc=00;32:*.cpp=00;32:*.h=00;33:' Code:
skoal@morpheus:///tmp $ rm -f ~/.dircolors \\//_ Last edited by skoal; June 13th, 2005 at 09:28 PM.. |
|
|
|
|
|
#2 |
|
Just Give Me the Beans!
![]() Join Date: Nov 2005
Location: Lisbon, Portugal
Beans: 75
Ubuntu 8.10 Intrepid Ibex
|
Thanx for the nice HOWTO!
By the way, to get syntax highlight on VI you can edit the "filetype.vim" file, located in /usr/share/vim/"vim version"/. Just change the line: au BufNewFile,BufRead .dir_colors,/etc/DIR_COLORS setf dircolorsto au BufNewFile,BufRead .dir_colors,.dircolors,/etc/DIR_COLORS setf dircolorsAlternatively you can name the file ".dir_colors" insted of ".dircolors". VI rules! |
|
|
|
|
|
#3 |
|
5 Cups of Ubuntu
![]() Join Date: May 2007
Beans: 21
Ubuntu 7.10 Gutsy Gibbon
|
Re: Howto: Add custom color to directory listings.
Hi, I've tried applying the instructions from this somewhat dated Howto creating a .dircolors file in my home directory, modifing the ~$ .bashrc file and then sourcing it.
~$ . .bashrc Errors occurred on two attempts after editing and then sourcing the bashrc file. One was something like unescaped fi the other was unexpected end of file at line 75. Here is the original feisty bashrc code: # enable color support of ls and also add handy aliases if [ "$TERM" != "dumb" ]; then eval "`dircolors -b`" alias ls='ls --color=auto' #alias dir='ls --color=auto --format=vertical' #alias vdir='ls --color=auto --format=long' fi Here is the modified code I inserted: # enable color support of ls and also add handy aliases if [ "$TERM" != "dumb" ]; then [ -e "$HOME/.dircolors" ] && DIR_COLORS="$HOME/.dircolors" [ -e "$DIR_COLORS" ] || DIR_COLORS="" eval "`dircolors -b $DIR_COLORS`" alias ls='ls --color=auto' #alias dir='ls --color=auto --format=vertical' #alias vdir='ls --color=auto --format=long' fi I don't know if it's something I'm doing wrong or changes to Ubunutu Feisty making the code unworkable. |
|
|
|
|
|
#4 |
|
First Cup of Ubuntu
![]() Join Date: Mar 2008
Beans: 6
|
Re: Howto: Add custom color to directory listings.
Unfortunately this tutorial didn't work for me (ubuntu gutsy gibbon), too. here is my .bashrc
perhaps someone knows the issue? p.s. the last line I dropped in by myself. thanx in advance! ---------------------------/.bashrc-------------------------------- # ~/.bashrc: executed by bash(1) for non-login shells. # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) # for examples # If not running interactively, don't do anything [ -z "$PS1" ] && return # don't put duplicate lines in the history. See bash(1) for more options export HISTCONTROL=ignoredups # ... and ignore same sucessive entries. export HISTCONTROL=ignoreboth # check the window size after each command and, if necessary, # update the values of LINES and COLUMNS. shopt -s checkwinsize # make less more friendly for non-text input files, see lesspipe(1) [ -x /usr/bin/lesspipe ] && eval "$(lesspipe)" # set variable identifying the chroot you work in (used in the prompt below) if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then debian_chroot=$(cat /etc/debian_chroot) fi # set a fancy prompt (non-color, unless we know we "want" color) case "$TERM" in xterm-color) PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' ;; *) PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' ;; esac # Comment in the above and uncomment this below for a color prompt #PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' # If this is an xterm set the title to user@host:dir case "$TERM" in xterm*|rxvt*) PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"' ;; *) ;; esac # Alias definitions. # You may want to put all your additions into a separate file like # ~/.bash_aliases, instead of adding them here directly. # See /usr/share/doc/bash-doc/examples in the bash-doc package. #if [ -f ~/.bash_aliases ]; then # . ~/.bash_aliases #fi # enable color support of ls and also add handy aliases if [ "$TERM" != "dumb" ]; then [ -e "$HOME/.dircolors" ] && DIR_COLORS="$HOME/.dircolors" [ -e "$DIR_COLORS" ] || DIR_COLORS="" eval "`dircolors -b $DIR_COLORS`" alias ls='ls --color=auto' #alias dir='ls --color=auto --format=vertical' #alias vdir='ls --color=auto --format=long' fi # some more ls aliases #alias ll='ls -l' #alias la='ls -A' #alias l='ls -CF' # enable programmable completion features (you don't need to enable # this, if it's already enabled in /etc/bash.bashrc and /etc/profile # sources /etc/bash.bashrc). if [ -f /etc/bash_completion ]; then . /etc/bash_completion fi PS1='\[\e[1;33m\]\n[\A]\[\e[0;34m\]\u@\h > \W\$\[\e[m\] ' ----------------------------------------------------------------------------------------- |
|
|
|
|
|
#5 |
|
5 Cups of Ubuntu
![]() Join Date: Oct 2007
Location: South Africa
Beans: 15
|
Re: Howto: Add custom color to directory listings.
For anybody battling with dircolors here is a great little shell-script that displays every available colour combination for you to select from.
To execute type bash ttycolors.sh Last edited by dmgExP; May 2nd, 2008 at 02:31 PM.. |
|
|
|
|
|
#6 |
|
First Cup of Ubuntu
![]() Join Date: Feb 2007
Beans: 1
|
Re: Howto: Add custom color to directory listings.
dmgExP - That script is excellent, thank you! It saved me quite a bit of time in setting up dircolors for my various terminals, each of which has a different solid color background. No more guessing, just fired up that script and was able to see what would work instantly!
Last edited by pdxvampire; December 26th, 2008 at 12:23 PM.. |
|
|
|
|
|
#7 | |
|
First Cup of Ubuntu
![]() Join Date: Jun 2009
Beans: 1
|
Re: Howto: Add custom color to directory listings.
I know its been over 4 years after this post was made, but am trying my luck. Can you help me with the attachment you are talking about.
Thanks CoolToddy! Quote:
|
|
|
|
|
|
|
#8 |
|
First Cup of Ubuntu
![]() Join Date: Jun 2009
Beans: 2
|
Re: Howto: Add custom color to directory listings.
Help, I followed the instructions from skoal (Thank You skoal).
All my suffixes are changing to the correct color except for my ( .java, .c and .cpp ) suffixes. These suffixes are staying bright green. I set .java to green 00;32 .c to brown 00;36 and .cpp to cyan 00;36 So when I type the ls command I would like to see: $ls foo.c foo.cpp foo.java however what I see is: $ls foo.c foo.cpp foo.java Is there anyway to be able to change these suffixes to the correct color? Below is my .dircolors file and .bashrc file: .dircolor file # Configuration file for dircolors, a utility to help you set the # LS_COLORS environment variable used by GNU ls with the --color option. # Copyright (C) 1996, 1999-2008 # Free Software Foundation, Inc. # Copying and distribution of this file, with or without modification, # are permitted provided the copyright notice and this notice are preserved. # The keywords COLOR, OPTIONS, and EIGHTBIT (honored by the # slackware version of dircolors) are recognized but ignored. # Below, there should be one TERM entry for each termtype that is colorizable TERM Eterm TERM ansi TERM color-xterm TERM con132x25 TERM con132x30 TERM con132x43 TERM con132x60 TERM con80x25 TERM con80x28 TERM con80x30 TERM con80x43 TERM con80x50 TERM con80x60 TERM cons25 TERM console TERM cygwin TERM dtterm TERM eterm-color TERM gnome TERM gnome-256color TERM konsole TERM kterm TERM linux TERM linux-c TERM mach-color TERM mlterm TERM putty TERM rxvt TERM rxvt-cygwin TERM rxvt-cygwin-native TERM rxvt-unicode TERM screen TERM screen-256color TERM screen-bce TERM screen-w TERM screen.linux TERM vt100 TERM xterm TERM xterm-16color TERM xterm-256color TERM xterm-88color TERM xterm-color TERM xterm-debian # Below are the color init strings for the basic file types. A color init # string consists of one or more of the following numeric codes: # Attribute codes: # 00 none 01 bold 04 underscore 05 blink 07 reverse 08 concealed # Text color codes: # 30 black 31 red 32 green 33 yellow 34 blue 35 magenta 36 cyan 37 white # Background color codes: # 40 black 41 red 42 green 43 yellow 44 blue 45 magenta 46 cyan 47 white NORMAL 00 # global default, although everything should be something. FILE 00 # normal file DIR 01;34 # directory LINK 01;36 # symbolic link. (If you set this to 'target' instead of a # numerical value, the color is as for the file pointed to.) FIFO 40;33 # pipe SOCK 01;35 # socket DOOR 01;35 # door BLK 40;33;01 # block device driver CHR 40;33;01 # character device driver ORPHAN 40;31;01 # symlink to nonexistent file, or non-stat'able file SETUID 37;41 # file that is setuid (u+s) SETGID 30;43 # file that is setgid (g+s) STICKY_OTHER_WRITABLE 30;42 # dir that is sticky and other-writable (+t,o+w) OTHER_WRITABLE 34;42 # dir that is other-writable (o+w) and not sticky STICKY 37;44 # dir with the sticky bit set (+t) and not other-writable # This is for files with execute permission: EXEC 01;32 # List any file extensions like '.gz' or '.tar' that you would like ls # to colorize below. Put the extension, a space, and the color init string. # (and any comments you want to add after a '#') # If you use DOS-style suffixes, you may want to uncomment the following: #.cmd 01;32 # executables (bright green) #.exe 01;32 #.com 01;32 #.btm 01;32 #.bat 01;32 # Or if you want to colorize scripts even if they do not have the # executable bit actually set. #.sh 01;32 #.csh 01;32 # archives or compressed (bright red) .tar 01;31 .tgz 01;31 .svgz 01;31 .arj 01;31 .taz 01;31 .lzh 01;31 .lzma 01;31 .zip 01;31 .z 01;31 .Z 01;31 .dz 01;31 .gz 01;31 .bz2 01;31 .bz 01;31 .tbz2 01;31 .tz 01;31 .deb 01;31 .rpm 01;31 .jar 01;31 .rar 01;31 .ace 01;31 .zoo 01;31 .cpio 01;31 .7z 01;31 .rz 01;31 # image formats .jpg 01;35 .jpeg 01;35 .gif 01;35 .bmp 01;35 .pbm 01;35 .pgm 01;35 .ppm 01;35 .tga 01;35 .xbm 01;35 .xpm 01;35 .tif 01;35 .tiff 01;35 .png 01;35 .svg 01;35 .mng 01;35 .pcx 01;35 .mov 01;35 .mpg 01;35 .mpeg 01;35 .m2v 01;35 .mkv 01;35 .ogm 01;35 .mp4 01;35 .m4v 01;35 .mp4v 01;35 .vob 01;35 .qt 01;35 .nuv 01;35 .wmv 01;35 .asf 01;35 .rm 01;35 .rmvb 01;35 .flc 01;35 .avi 01;35 .fli 01;35 .gl 01;35 .dl 01;35 .xcf 01;35 .xwd 01;35 .yuv 01;35 # audio formats .aac 00;36 .au 00;36 .flac 00;36 .mid 00;36 .midi 00;36 .mka 00;36 .mp3 00;36 .mpc 00;36 .ogg 00;36 .ra 00;36 .wav 00;36 .red 00;31 .green 00;32 .yellow 00;33 .blue 00;34 .magenta 00;35 .cyan 00;36 .blueb 01;34 .blueu 04;34 .bluebi 05;34 .bluer 07;34 .brown 00;33 .blackb 01;30 .redb 01;31 .yellow 01;33 .magentab 01;35 .cyanb 01;36 .gray 00;37 .greenb 01;32 .java 00;32 .c 00;33 .cpp 00;36 ------------------------- end of .dcolors file ------------------------------------------ .bashrc file # ~/.bashrc: executed by bash(1) for non-login shells. # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc) # for examples # If not running interactively, don't do anything [ -z "$PS1" ] && return # don't put duplicate lines in the history. See bash(1) for more options # don't overwrite GNU Midnight Commander's setting of `ignorespace'. export HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups # ... or force ignoredups and ignorespace export HISTCONTROL=ignoreboth # append to the history file, don't overwrite it shopt -s histappend # for setting history length see HISTSIZE and HISTFILESIZE in bash(1) # check the window size after each command and, if necessary, # update the values of LINES and COLUMNS. shopt -s checkwinsize # make less more friendly for non-text input files, see lesspipe(1) [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" # set variable identifying the chroot you work in (used in the prompt below) if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then debian_chroot=$(cat /etc/debian_chroot) fi # set a fancy prompt (non-color, unless we know we "want" color) case "$TERM" in xterm-color) color_prompt=yes;; esac # uncomment for a colored prompt, if the terminal has the capability; turned # off by default to not distract the user: the focus in a terminal window # should be on the output of commands, not on the prompt #force_color_prompt=yes if [ -n "$force_color_prompt" ]; then if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then # We have color support; assume it's compliant with Ecma-48 # (ISO/IEC-6429). (Lack of such support is extremely rare, and such # a case would tend to support setf rather than setaf.) color_prompt=yes else color_prompt= fi fi if [ "$color_prompt" = yes ]; then PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' else PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' fi unset color_prompt force_color_prompt # If this is an xterm set the title to user@host:dir case "$TERM" in xterm*|rxvt*) PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1" ;; *) ;; esac # Alias definitions. # You may want to put all your additions into a separate file like # ~/.bash_aliases, instead of adding them here directly. # See /usr/share/doc/bash-doc/examples in the bash-doc package. #if [ -f ~/.bash_aliases ]; then # . ~/.bash_aliases #fi # enable color support of ls and also add handy aliases if [ -x /usr/bin/dircolors ] ; then [ -e "$HOME/.dircolors" ] && DIR_COLORS="$HOME/.dircolors" [ -e "$DIR_COLORS" ] || DIR_COLORS="" eval "`dircolors -b $DIR_COLORS`" #eval "`dircolors -b`" alias ls='ls --color=auto' #alias dir='dir --color=auto' #alias vdir='vdir --color=auto' #alias grep='grep --color=auto' #alias fgrep='fgrep --color=auto' #alias egrep='egrep --color=auto' fi # some more ls aliases #alias ll='ls -l' #alias la='ls -A' #alias l='ls -CF' # enable programmable completion features (you don't need to enable # this, if it's already enabled in /etc/bash.bashrc and /etc/profile # sources /etc/bash.bashrc). if [ -f /etc/bash_completion ]; then . /etc/bash_completion fi #MY STUFF BELOW HERE. #------------------------ export PS1="\e[0;31m\! \d \t \u \w\$ \e[m\n" export CLASSPATH=/home/my/java/myclass; ---------------------------- end of .bashrc file -------------------------------- Any help would be greatly appreciated. Thank You, tmllvs |
|
|
|
|
|
#9 |
|
First Cup of Ubuntu
![]() Join Date: Jun 2009
Beans: 2
|
Re: Howto: Add custom color to directory listings.
OOPS. I found the problem.
All excutables are bright-green . Some how the .java , .cpp, and .c files had executable permissions. When I took away the executable permissions by typing ( chmod ugo -x *.java etc.. ) the colors to my suffixes were the I wanted them. Thanks again to skoal for the great instructions . tmllvs |
|
|
|
|
|
#10 |
|
5 Cups of Ubuntu
![]() Join Date: Apr 2009
Location: not where I want to...
Beans: 38
Ubuntu 9.04 Jaunty Jackalope
|
Re: Howto: Add custom color to directory listings.
Excellent!! Thank you skoal ![]() ![]() ![]()
__________________
(\__/) (='.'=) The Senator, while claiming he was not intoxicated, (")_(") could not explain his nudity. |
|
|
|
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|