[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Pimp your shell - Debian developer tips?

Some notes from our defaults at $DAYJOB. I can't take credit for most of
this. These were ideas I've picked up from various people along the way.

# Prevent users from accidentally overwriting files with redirection.
set -o noclobber

Warning: While I'm the one that added it, sometimes I don't love

# Fix some spelling errors in tab-completions
shopt -s cdspell
shopt -s dirspell

# Allow ** to recurse
shopt -s globstar 2> /dev/null

# Make globs case-insensitive
shopt -s nocaseglob

# Tell less to not ring the bell (Q) and pass through color escape
# sequences (R).
export LESS="QR"

# Save and show timestamps in the command history.

We also colorize the hostname, which can act as a subtle hint as to
whether you are on the right system. (It's basically an subconscious
thing; it's not like we memorize which system is which color.) These
days, the per-host color is calculated with Jinja templating in Ansible.
The example below is the older code where bash calculates it. My email
client is going to word-wrap this, so you'll have to reverse that, but
it's straightforward.

# We use dircolors instead of tput to determine which types of terminals
# support colors.  Otherwise, we can end up with an inconsistency
# between bash and ls, et al.  For example: a vt100 on OpenIndiana.
if (LS_COLORS= ; eval $(dircolors 2> /dev/null) ; [ -n "$LS_COLORS" ])
    # Colorize based on hostname: green, yellow, blue, magenta, or cyan.
    ps_h='\[\e[1;'$((32 + $(hostname | cut -d. -f1 | cksum | cut -c1-3)
% 5))'m\]\h\[\e[0m\]'

    if [ "$(id -u)" = "0" ]
        # Make the username and # red when logged in as root.

        PS1='${debian_chroot:+($debian_chroot)}\u@'$ps_h':\w\$ '

    unset ps_h

    if [ -r ~/.dircolors ]
        eval "$(dircolors -b ~/.dircolors)"
        eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '

It's not shown in the example above, but we also use white text on a red
background for the hostname if it ends in -new. This is our convention
when a new system is being setup: we set the hostname (in Ansible in our
case) for a system replacing a host named "name" to "name-new". This
prompt helps you keep track of whether you are on the current production
system or the -new system you are configuring. It is functionally
equalivalent to:


Attachment: signature.asc
Description: OpenPGP digital signature

Reply to: