2012-07-03 17:21:48 +02:00
|
|
|
## -*- mode:sh -*- #
|
2012-06-15 16:54:02 +02:00
|
|
|
################################################################################
|
|
|
|
## Bash specific options
|
|
|
|
################################################################################
|
|
|
|
|
|
|
|
## 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).
|
2012-08-13 18:18:56 +02:00
|
|
|
[ -f /etc/bash_completion ] && . /etc/bash_completion
|
2012-06-15 16:54:02 +02:00
|
|
|
|
|
|
|
## Sudo completion
|
2012-08-13 18:18:56 +02:00
|
|
|
complete -cf sudo
|
2012-06-15 16:54:02 +02:00
|
|
|
|
2012-08-13 18:18:56 +02:00
|
|
|
set +o nounset # Otherwise some completions will fail
|
|
|
|
set completion-ignore-case on
|
|
|
|
set show-all-if-ambiguous on
|
2012-06-15 16:54:02 +02:00
|
|
|
|
|
|
|
## Use TAB to switch between completions instead of waiting for the next character.
|
|
|
|
#bind '"\t":menu-complete'
|
|
|
|
|
2012-08-13 18:18:56 +02:00
|
|
|
## A list of suffixes to ignore when performing filename completion
|
|
|
|
export FIGNORE=".o:~"
|
2012-06-15 16:54:02 +02:00
|
|
|
|
2012-08-13 18:18:56 +02:00
|
|
|
## To search and fill the complete name of a file (with <Esc>)
|
|
|
|
set filec
|
2012-06-15 16:54:02 +02:00
|
|
|
|
|
|
|
##======================================================================
|
|
|
|
## History management
|
|
|
|
##======================================================================
|
2012-08-13 18:18:56 +02:00
|
|
|
|
|
|
|
# Don't put duplicate lines in the history. See bash(1) for more options.
|
|
|
|
export HISTCONTROL=ignoredups
|
|
|
|
|
|
|
|
# Define number of previous commands stored.
|
|
|
|
export HISTFILESIZE=1000
|
|
|
|
|
|
|
|
export HISTIGNORE="&:bg:fg:ll:h:ls:la:la:lk:clear:exit:history"
|
|
|
|
export HISTTIMEFORMAT="%Y-%m-%d_%H:%M:%S_%a "
|
2012-06-15 16:54:02 +02:00
|
|
|
|
|
|
|
##======================================================================
|
|
|
|
## Various options
|
|
|
|
##======================================================================
|
2012-08-13 18:18:56 +02:00
|
|
|
set -o notify # Jobs notify shell about their states immediately.
|
|
|
|
#set ignoreeof # To avoid accidentally quitting the shell with <Ctrl-D>.
|
|
|
|
#shopt -u mailwarn # Disable the shell ability to warn about incoming mail.
|
|
|
|
shopt -s cdable_vars # If cd arg is not valid, assumes its a var defining a dir.
|
|
|
|
shopt -s cdspell # To correct minor error in the directory spelling (during cd).
|
|
|
|
shopt -s checkhash
|
|
|
|
shopt -s checkwinsize # Update the value of LINES and COLUMNS after each command if altered.
|
|
|
|
shopt -s cmdhist # Save multi-line commands in history as single line.
|
|
|
|
shopt -s dirspell
|
|
|
|
shopt -s dotglob # Include dotfiles in pathname expansion.
|
|
|
|
shopt -s expand_aliases # Expand aliases.
|
|
|
|
shopt -s extglob # Enable extended pattern-matching features.
|
|
|
|
shopt -s histappend # Append to (not overwrite) the history file.
|
|
|
|
shopt -s hostcomplete # Attempt hostname expansion when @ is at the beginning of a word.
|
|
|
|
shopt -s no_empty_cmd_completion # No completion on an empty line.
|
|
|
|
shopt -s nocaseglob # Pathname expansion will be treated as case-insensitive.
|
|
|
|
shopt -s progcomp # To enable the programmable completion.
|
2012-06-15 16:54:02 +02:00
|
|
|
|
|
|
|
##==============================================================================
|
|
|
|
## PS1 -- Full width bar with informations.
|
|
|
|
##==============================================================================
|
2012-08-13 18:18:56 +02:00
|
|
|
|
2012-06-15 16:54:02 +02:00
|
|
|
## An external function is needed to update $COLUMNS value, as well as path, time, and other variables.
|
2012-08-13 18:18:56 +02:00
|
|
|
_psbar ()
|
|
|
|
{
|
|
|
|
## Initialization.
|
|
|
|
BARCOLOR=$BBlue
|
|
|
|
OUTPUT="$BARCOLOR["
|
|
|
|
SYMBOLVAR='='
|
|
|
|
CENTERVAR=" $(date +%H:%M:%S) "
|
|
|
|
|
|
|
|
## Truncated path.
|
|
|
|
## '3' stands for '[ $SYMBOLVAR'.
|
|
|
|
local PWDMAXLEN=$(($COLUMNS/2-${#CENTERVAR}/2-3))
|
|
|
|
local TRUNC_SYMBOL="..."
|
|
|
|
if [[ $PWD == $HOME* ]]; then
|
|
|
|
newPWD="~${PWD#$HOME}"
|
|
|
|
else
|
|
|
|
newPWD=${PWD}
|
|
|
|
fi
|
|
|
|
if [ ${#newPWD} -gt $PWDMAXLEN ]; then
|
|
|
|
local PWDOFFSET=$(( ${#newPWD} - $PWDMAXLEN + ${#TRUNC_SYMBOL} ))
|
|
|
|
newPWD="${TRUNC_SYMBOL}${newPWD:$PWDOFFSET:$PWDMAXLEN}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
## Truncated login information.
|
|
|
|
local LOGINFO="$(whoami)@$HOSTNAME"
|
|
|
|
if [ ${#LOGINFO} -gt $(($COLUMNS/2-${#CENTERVAR}/2-3)) ]
|
|
|
|
then
|
|
|
|
LOGINFO=$USER
|
|
|
|
if [ ${#LOGINFO} -gt $(($COLUMNS/2-${#CENTERVAR}/2-3)) ]
|
|
|
|
then
|
|
|
|
unset LOGINFO
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
## Left and right side. Empty if terminal width is too small.
|
|
|
|
if [ $COLUMNS -gt 50 ]
|
|
|
|
then
|
|
|
|
LEFTSIDEVAR="$newPWD "
|
|
|
|
RIGHTSIDEVAR=" $LOGINFO"
|
|
|
|
fi
|
|
|
|
|
|
|
|
## Left side.
|
|
|
|
OUTPUT="$OUTPUT$BPurple$LEFTSIDEVAR"
|
|
|
|
|
|
|
|
|
|
|
|
## Reset bar color
|
|
|
|
OUTPUT="$OUTPUT$BARCOLOR"
|
|
|
|
|
|
|
|
## In case of odd values.
|
|
|
|
if [ $(($COLUMNS%2)) -eq 1 ]
|
|
|
|
then
|
|
|
|
OUTPUT="$OUTPUT$SYMBOLVAR"
|
|
|
|
fi
|
|
|
|
|
|
|
|
## Fill 'OUTPUT' variable with the desired chars.
|
|
|
|
## '1' stands for '['
|
|
|
|
for i in $( seq $(($COLUMNS/2-${#LEFTSIDEVAR}-${#CENTERVAR}/2-1)) )
|
|
|
|
do
|
|
|
|
OUTPUT="$OUTPUT$SYMBOLVAR"
|
|
|
|
done
|
|
|
|
|
|
|
|
## Center.
|
|
|
|
OUTPUT="$OUTPUT$Color_Off$CENTERVAR"
|
|
|
|
|
|
|
|
## Reset bar color
|
|
|
|
OUTPUT="$OUTPUT$BARCOLOR"
|
|
|
|
|
|
|
|
## Fill 'OUTPUT' variable with the desired chars.
|
|
|
|
for i in $( seq $(($COLUMNS/2-${#CENTERVAR}/2-${#RIGHTSIDEVAR}-1)) )
|
|
|
|
do
|
|
|
|
OUTPUT="$OUTPUT$SYMBOLVAR"
|
|
|
|
done
|
|
|
|
|
|
|
|
## Right side.
|
|
|
|
OUTPUT="$OUTPUT$BGreen$RIGHTSIDEVAR"
|
|
|
|
|
|
|
|
## Reset bar color
|
|
|
|
OUTPUT="$OUTPUT$BARCOLOR"
|
|
|
|
|
|
|
|
## Close bar
|
|
|
|
OUTPUT="$OUTPUT]\n"
|
|
|
|
|
|
|
|
## Prompt.
|
|
|
|
if [ $(id -u) -eq 0 ]
|
|
|
|
then
|
|
|
|
## Root access
|
|
|
|
OUTPUT="$OUTPUT$BRed# $Color_Off"
|
|
|
|
else
|
|
|
|
## Normal user
|
|
|
|
OUTPUT="$OUTPUT$BYellow$ $Color_Off"
|
|
|
|
fi
|
|
|
|
|
|
|
|
## Set result to PS1.
|
|
|
|
PS1="$OUTPUT"
|
|
|
|
}
|
2012-06-15 16:54:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
##==============================================================================
|
|
|
|
## Add informations to history.
|
|
|
|
##==============================================================================
|
|
|
|
#PROMPT_COMMAND='hpwd=$(history 1); hpwd="${hpwd# *[0-9]* }"; if [[ ${hpwd%% *} == "cd" ]]; then cwd=$OLDPWD; else cwd=$PWD; fi; hpwd="${hpwd% ### *} ### $cwd"; history -s "$hpwd;"'
|
|
|
|
|
|
|
|
##==============================================================================
|
|
|
|
## PS1
|
|
|
|
##==============================================================================
|
|
|
|
|
2012-08-13 18:18:56 +02:00
|
|
|
## PS1 using _psbar function.
|
|
|
|
#PROMPT_COMMAND='_psbar'
|
2012-06-15 16:54:02 +02:00
|
|
|
|
|
|
|
## Simple PS1
|
2012-08-13 18:18:56 +02:00
|
|
|
PS1='\[\e[0;32m\]\u\[\e[m\] \[\e[1;34m\]\w\[\e[m\] \[\e[1;32m\]\$\[\e[m\] '
|
2012-06-15 16:54:02 +02:00
|
|
|
|