Harmonizing the bash startup scripts

If you have any suggestions or ideas about improving Salix, here's the place to post them.
User avatar
lmello
Posts: 218
Joined: 4. Aug 2010, 17:38
Location: Brazil
Contact:

Harmonizing the bash startup scripts

Post by lmello »

I noticed certain things about Salix (the coloring scheme in the boot sequence, for example) that I'd learned from Darrell Anderson's Slackware guide. The most useful part is, IMHO, the part about bash startup scripts and how you can 'harmonize' your shell environment. Why not include a similar set of scripts in /etc/skel for the next Salix release?

I added a few useful statements from Debian to make these:

Code: Select all

# /etc/bashrc
#
#####################################################################
#
# Basic bash startup files explanation:
#
# /etc/profile    ==> System-wide initialization file containing 
#                     global/system environment variables and 
#                     startup programs
#
# /etc/bashrc     ==> System-wide aliases and functions, and some 
#                     modifications to /etc/profile (to help 
#                     maintain /etc/profile as original as possible)
#
# ~/.bash_profile ==> Local/Personal environment variables and 
#                     startup programs called only during login
#
# ~/.bashrc       ==> Anything local/personal and peculiar to the 
#                     user
#
# Login command programmatically sources /etc/profile and then ONLY
# ~/.bash_profile OR ~/.bash_login OR ~/.profile, in that search 
# order
#
# Logout command programmatically sources ~/.bash_logout
#
# Non-login consoles such as xterm/konsole programmatically sources 
# ~/.bashrc
#
# /etc/bashrc is not sourced programmatically and must be sourced 
# manually
#
# Local setup: 
#
# ~/.bash_profile sources ~./bashrc and executes bash_login
# ~/.bashrc sources /etc/bashrc
# ~/.bash_logout executes bash_logout
#
#####################################################################

PS1='[\u@\h \W]\$ '

. /etc/profile.d/bash_completion.sh
. /etc/profile.d/coreutils-dircolors.sh

# Needed to get "man" to work properly in Unicode locales:
alias man='LC_ALL=C man'

# Some more alias to avoid making mistakes:
alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Evaluate terminal size and dynamically resize screen
shopt -s checkwinsize

# Don't put duplicate lines in the history:
export HISTCONTROL=ignoredups

# Colorized grep output and man pages:
export PAGER='most'
export GREP_OPTIONS='--color=auto'
export GREP_COLOR='1;31'

# Set Vi IMproved as the default editor:
export EDITOR='vim'

Code: Select all

# ~/.bashrc
#
# see /etc/bashrc for a complete description how all bash source files
# are related and used on this box

# Source system-wide aliases and functions
if [ -f /etc/bashrc ]; then
	source /etc/bashrc
fi

# --- Local/Personal environment variables ---
# define bash prompts, non-X text editors, etc.
unset MAILCHECK

# --- Local aliases ---

# --- Local functions ---

Code: Select all

# ~/.bash_login
#
# see /etc/bashrc for a complete description how all bash source files
# are related and used on this box

# Source Local/Personal aliases and functions
if [ -f $HOME/.bashrc ]; then
	source $HOME/.bashrc
fi

# Source /usr/local/bin/bash_login
if [ -x /usr/local/bin/bash_login ]; then
	/usr/local/bin/bash_login
fi

# --- Local/Personal startup programs ---

Code: Select all

# ~/.bash_logout
#
# see /etc/bashrc for a complete description how all bash source files
# are related and used on this box

# Source /usr/local/bin/bash_logout
if [ -x /usr/local/bin/bash_logout ]; then
	/usr/local/bin/bash_logout
fi

clear
Small things that make the difference - colorized grep output, vim and most as default pager and editor, all very well commented to make life easier for the terminal newbie ;)
User avatar
Akuna
Salix Wizard
Posts: 1038
Joined: 14. Jun 2009, 12:25

Re: Harmonizing the bash startup scripts

Post by Akuna »

Nice :)
Image
What really matters is where you are going, not where you come from.
User avatar
JRD
Salix Warrior
Posts: 950
Joined: 7. Jun 2009, 22:52
Location: Lyon, France

Re: Harmonizing the bash startup scripts

Post by JRD »

Seems a good idea. I will test them at home.
In fact I already use something like this, but not written as general/good as this.
Image
User avatar
maximus
Posts: 141
Joined: 2. Sep 2009, 01:41

Re: Harmonizing the bash startup scripts

Post by maximus »

When using the /etc/bashrc template provided above I get a message regarding the file /etc/profile.d/bash_completion.sh that doesn't exist. I just commented out the offending line.
User avatar
lmello
Posts: 218
Joined: 4. Aug 2010, 17:38
Location: Brazil
Contact:

Re: Harmonizing the bash startup scripts

Post by lmello »

maximus wrote:When using the /etc/bashrc template provided above I get a message regarding the file /etc/profile.d/bash_completion.sh that doesn't exist. I just commented out the offending line.
W-What, you don't have bash-completion from /extra? That's a serious offence!

:roll:
User avatar
maximus
Posts: 141
Joined: 2. Sep 2009, 01:41

Re: Harmonizing the bash startup scripts

Post by maximus »

Yep, that was it! Cheers 8-)
User avatar
lmello
Posts: 218
Joined: 4. Aug 2010, 17:38
Location: Brazil
Contact:

Re: Harmonizing the bash startup scripts

Post by lmello »

You can grab my configuration files directly from here.
User avatar
damNageHack
Posts: 663
Joined: 24. Sep 2009, 17:07

Re: Harmonizing the bash startup scripts

Post by damNageHack »

Akuna wrote:Nice :)
+1
User avatar
lmello
Posts: 218
Joined: 4. Aug 2010, 17:38
Location: Brazil
Contact:

Re: Harmonizing the bash startup scripts

Post by lmello »

damNageHack wrote:
Akuna wrote:Nice :)
+1
Well, should I apply for a ticket in the bugtracker?
User avatar
thenktor
Salix Wizard
Posts: 2426
Joined: 6. Jun 2009, 14:47
Location: Franconia
Contact:

Re: Harmonizing the bash startup scripts

Post by thenktor »

These lines:
. /etc/profile.d/bash_completion.sh
. /etc/profile.d/coreutils-dircolors.sh

need a check if file exists.

And for non vim experienced users probably nano or mcedit is a much simpler to use editor.

EDIT: I'd also prefer the more standard looking PS1='\u@\h:\W\$ '

EDIT2: SuSE uses a red root prompt. Done by this:

Code: Select all

        # Colored root prompt (see bugzilla #144620)
        if test "$UID" -eq 0 -a -t ; then
            _bred="$(path tput bold 2> /dev/null; path tput setaf 1 2> /dev/null)"
            _sgr0="$(path tput sgr0 2> /dev/null)"
            PS1="\[$_bred\]$PS1\[$_sgr0\]"
            unset _bred _sgr0
        fi
Image
burnCDDA (burns audio CDs)
geBIERt (German beer blog)
Post Reply