Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

customizing dircolors doesn't take effect in emacs shell

62 views
Skip to first unread message

Yuan Luo

unread,
Jan 7, 2012, 4:28:48 PM1/7/12
to help-gn...@gnu.org
Hi,
So I have the following setting for dircolors in my ~/.bashrc. With my customized ~/.dircolors file, a regular terminal shows the desired colors upon ls in the shell. However, within the shell of emacs, it still shows the default colors upon ls. This happens in emacs23, what am I missing?

if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
fi

Thanks,
Yuan

Peter Dyballa

unread,
Jan 7, 2012, 7:12:23 PM1/7/12
to Yuan Luo, help-gn...@gnu.org

Am 7.1.2012 um 22:28 schrieb Yuan Luo:

> This happens in emacs23, what am I missing?

Put the useful shell aliases also in ~/.emacs_bash – this file is read in by the bash running in a *shell* buffer. (~/.emacs_bash can also be linked with ~/.bashrc. Maybe it's possible to customise the bash that it reads in ~/.bashrc.)

--
Greetings

Pete

The future will be much better tomorrow.
– George W. Bush


Yuan Luo

unread,
Jan 7, 2012, 7:36:00 PM1/7/12
to Peter Dyballa, help-gn...@gnu.org
Hi Pete,
Thanks for your quick reply, I linked ~/.emacs_bash to ~/.bashrc but the default color is still not changed. I read more about ~/.emacs_bash, it seems to me emacs sends the content from this file to the interactive shell upon starting. However, if I directly type "dircolors -b ~/.dircolors" in emacs interactive shell, I got the following result:

LS_COLORS='';
export LS_COLORS

where as the same command typed in a regular system shell would yield the desired LS_COLORS.

What could be the problem here?
Thanks,
Yuan

Peter Dyballa

unread,
Jan 8, 2012, 5:50:15 AM1/8/12
to Yuan Luo, help-gn...@gnu.org

Am 8.1.2012 um 01:36 schrieb Yuan Luo:

> What could be the problem here?

Are in GNU Emacs' *shell* buffer any shell aliases defined? Is particularly your ls alias set? Which "ls" is found first for execution: your recursive alias definition (alias ls='ls --color=auto' – which "ls" is which?) or the ls programme?

--
Greetings

Pete

Bake pizza not war!


Yuan Luo

unread,
Jan 8, 2012, 8:05:51 PM1/8/12
to Peter Dyballa, help-gn...@gnu.org
Below is the output from 'alias' in an emacs shell

alias alert='notify-send --urgency=low -i "$([ $? = 0 ] && echo terminal || echo error)" "$(history|tail -n1|sed -e '\''s/^\s*[0-9]\+\s*//;s/[;&|]\s*alert$//'\'')"'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'

Anything noticeable?

Best,
Yuan

Peter Dyballa

unread,
Jan 9, 2012, 4:53:01 AM1/9/12
to Yuan Luo, help-gn...@gnu.org

Am 9.1.2012 um 02:05 schrieb Yuan Luo:

> alias l='ls -CF'
> alias la='ls -A'
> alias ll='ls -alF'
> alias ls='ls --color=auto'
>
> Anything noticeable?

IMO it's not recommended to use the same symbol, "ls", left and right of the equals sign. I recommend to use the full pathname of the ls programme when this programme is meant.

Are all aliases from ~/.bashrc listed inside GNU Emacs?

Can you trace the execution of the ls alias?

Have you tried to use the more ANSI compliant "term" function/emulation?

It can be that you need to set up the *shell* buffer to actually show colours (*term* has it activated by default, by its more complete compliance to ANSI):

(add-hook 'shell-mode-hook (lambda ()
(ansi-color-for-comint-mode-on)))

Check your GNU Emacs documentation on this topic!

--
Greetings

Pete

The most exciting phrase to hear in science, the one that heralds new discoveries, is not "Eureka!" (I found it!) but "That's funny..."
– Isaac Asimov


Yuan Luo

unread,
Jan 9, 2012, 11:43:28 AM1/9/12
to Peter Dyballa, help-gn...@gnu.org
All aliases in ~/.bashrc are listed in emacs shells.
I already had have ansi-color-for-comint-mode-on set.
execution of ls traces to /bin/ls

Maybe i was not clear in the beginning, the emacs shell can show colors, but not to my customization, for example, I customized it to show executables in purple, it still show them in red. While a regular terminal shows the desirable purple color for executables (as in below, left is regular terminal, right is emacs shell).

Peter Dyballa

unread,
Jan 9, 2012, 3:56:14 PM1/9/12
to Yuan Luo, help-gn...@gnu.org

Am 9.1.2012 um 17:43 schrieb Yuan Luo:

> All aliases in ~/.bashrc are listed in emacs shells.
> I already had have ansi-color-for-comint-mode-on set.
> execution of ls traces to /bin/ls

Does it work when you use

/bin/ls --color=auto /bin
/bin/ls --color /bin

manually and directly?

My manual page explains:

With --color=auto, ls emits color codes only when standard output is connected to a terminal. The LS_COLORS environment variable can change the settings. Use the dircolors command to set it.

There is a chance that LS_COLORS hinders ls, it's also possible that in *shell* buffer standard output is not connected to a terminal. The latter seems to be true for me on Mac OS X (10.6.8, Snow Leopard). So by omitting the "=auto" should make your aliases work.

Yuan Luo

unread,
Jan 15, 2012, 5:34:35 PM1/15/12
to Peter Dyballa, help-gn...@gnu.org
I found the solution:
adding a line TERM=dumb in the ~/.dircolors file did the trick, as emacs inferior mode shell type is dumb.

Thanks for all the help getting me close to the answer!

Best,
Yuan
0 new messages