From 0d9fcf8df448db25e8b805b9812f44314ea89936 Mon Sep 17 00:00:00 2001 From: Maciej Sobkowski Date: Thu, 2 Jul 2015 13:52:25 +0200 Subject: Added Bash configuration --- bash/.bash/aliases/generic.bash | 5 + bash/.bash/aliases/ls.bash | 2 + bash/.bash/color_codes | 17 +++ bash/.bash/shenv.example | 4 + bash/.bash_profile | 6 + bash/.bashrc | 247 ++++++++++++++++++++++++++++++++++++++++ 6 files changed, 281 insertions(+) create mode 100644 bash/.bash/aliases/generic.bash create mode 100644 bash/.bash/aliases/ls.bash create mode 100644 bash/.bash/color_codes create mode 100644 bash/.bash/shenv.example create mode 100644 bash/.bash_profile create mode 100644 bash/.bashrc diff --git a/bash/.bash/aliases/generic.bash b/bash/.bash/aliases/generic.bash new file mode 100644 index 0000000..ea98e25 --- /dev/null +++ b/bash/.bash/aliases/generic.bash @@ -0,0 +1,5 @@ +alias clr="clear" +alias cls="clear" +alias c="clear" +alias v="vim" +alias ..="cd .." diff --git a/bash/.bash/aliases/ls.bash b/bash/.bash/aliases/ls.bash new file mode 100644 index 0000000..4e7fb97 --- /dev/null +++ b/bash/.bash/aliases/ls.bash @@ -0,0 +1,2 @@ +alias l="ls -l" +alias ll="ls -l" diff --git a/bash/.bash/color_codes b/bash/.bash/color_codes new file mode 100644 index 0000000..922574b --- /dev/null +++ b/bash/.bash/color_codes @@ -0,0 +1,17 @@ +BLACK="\[\033[0;30m\]" +RED="\[\033[0;31m\]" +GREEN="\[\033[0;32m\]" +BROWN="\[\033[0;33m\]" +BLUE="\[\033[0;34m\]" +PURPLE="\[\033[0;35m\]" +CYAN="\[\033[0;36m\]" +LIGHT_GRAY="\[\033[0;37m\]" +DARK_GRAY="\[\033[1;30m\]" +LIGHT_RED="\[\033[1;31m\]" +LIGHT_GREEN="\[\033[1;32m\]" +YELLOW="\[\033[1;33m\]" +LIGHT_BLUE="\[\033[1;34m\]" +LIGHT_PURPLE="\[\033[1;35m\]" +LIGHT_CYAN="\[\033[1;36m\]" +WHITE="\[\033[1;37m\]" +PS_CLEAR="\[\033[0m\]" diff --git a/bash/.bash/shenv.example b/bash/.bash/shenv.example new file mode 100644 index 0000000..84cc953 --- /dev/null +++ b/bash/.bash/shenv.example @@ -0,0 +1,4 @@ +proxy=http://10.144.1.10:8080 +#proxy=plwrprx-fiesprx.glb.nsn-net.net:8081 + +prompt_color diff --git a/bash/.bash_profile b/bash/.bash_profile new file mode 100644 index 0000000..b45e64f --- /dev/null +++ b/bash/.bash_profile @@ -0,0 +1,6 @@ +# .bash_profile + +# Get the aliases and functions +if [ -f ~/.bashrc ]; then + . ~/.bashrc +fi diff --git a/bash/.bashrc b/bash/.bashrc new file mode 100644 index 0000000..f8968c7 --- /dev/null +++ b/bash/.bashrc @@ -0,0 +1,247 @@ +# Basic variables +: ${HOME=~} +: ${LOGNAME=$(id -un)} +: ${UNAME=$(uname)} + +# SSH known hosts +: ${HOSTFILE=~/.ssh/known_hosts} + +# Config for readline +: ${INPUTRC=~/.inputrc} + +# ----------------------------------------------------------------------------- +# Options for shell +# ----------------------------------------------------------------------------- + +# If system-wide bashrc exists, bring it in +test -r /etc/bash.bashrc && + . /etc/bash.bashrc + +# notify of background job completion immediately +set -o notify + +# Explanation of used shell options: +# cdspell - autocorrect minor errors in cd path +# extglob - enable extended pattern matching +# histappend - append to HISTFILE insteead of overriding +# hostcomplete - if readline used, bash will attempt to complete hostnames +# interactive_comments - if line in prompt begins with #, treat as comment +# mailwarn - warning when mail file accessed +# no_empty_cmd_completion - don't attempt to search path for completion if +# empty line +shopt -s cdspell >/dev/null 2>&1 +shopt -s extglob >/dev/null 2>&1 +shopt -s histappend >/dev/null 2>&1 +shopt -s hostcomplete >/dev/null 2>&1 +shopt -s interactive_comments >/dev/null 2>&1 +shopt -u mailwarn >/dev/null 2>&1 +shopt -s no_empty_cmd_completion >/dev/null 2>&1 + +# disable core dumps +ulimit -S -c 0 + +# set umask +umask 0022 + +# ----------------------------------------------------------------------------- +# Environment configuration +# ----------------------------------------------------------------------------- + +# detect interactive shell +case "$~" in + *i*) INTERACTIVE=yes ;; + *) unset INTERACTIVE ;; +esac + +# detect login shell +case "$0" in + -*) LOGIN=yes ;; + *) unset LOGIN ;; +esac + +# set en_US locale with utf-8 +: ${LANG:="en_US.UTF-8"} +: ${LANGUAGE:="en"} +: ${LC_CTYPE:="en_US.UTF-8"} +: ${LC_ALL:="en_US.UTF-8"} +export LANG LANGUAGE LC_CTYPE LC_ALL + +# use PASSIVE ftp mode +: ${FTP_PASSIVE:=1} +export FTP_PASSIVE + +# ignore python bytecode, vim swap files +FIGNORE=".pyc:.swp:.swa:.swo" + +# history related variables +export HISTCONTROL=ignoreboth +export HISTFILESIZE=50000 +export HISTSIZE=50000 +export HISTIGNORE='ls:bg:fg:history' +export PROMPT_COMMAND='history -a' + +# ----------------------------------------------------------------------------- +# Pager/editor settings +# ----------------------------------------------------------------------------- + +HAVE_GVIM=$(command -v gvim) +HAVE_VIM=$(command -v vim) + +# editor +test -n "$HAVE_VIM" && +EDITOR=vim || +EDITOR=vi +export EDITOR + +# pager +if test -n "$(command -v less)"; then + PAGER="less -FirSwX" + MANPAGER="less -FirSwX" +else + PAGER=more + MANPAGER=more +fi + +if test -n "$HAVE_VIM"; then + export MANPAGER="/bin/sh -c \"col -b | vim -c 'set ft=man ts=8 nomod nolist nonu noma' -\"" +fi + +# ----------------------------------------------------------------------------- +# Prompt +# ----------------------------------------------------------------------------- + +# Base16 Shell +BASE16_SHELL="$HOME/.config/base16-shell/base16-default.dark.sh" +[[ -s $BASE16_SHELL ]] && source $BASE16_SHELL + +# load color codes +test -r ~/.bash/color_codes && + . ~/.bash/color_codes + +# set colors according to username +if [ "$LOGNAME" = "root" ]; then + COLOR1="${RED}" + COLOR2="${BROWN}" + P="#" +else + COLOR1="${LIGHT_GREEN}" + COLOR2="${BROWN}" + P="\$" +fi + +prompt_simple() { + + unset PROMPT_COMMAND + PS1="[\u@\h:\w] ${P} " + PS2="${P} " + +} + +jobscount() { + local stopped='$(jobs -s | wc -l | tr -d " ")' + local running='$(jobs -r | wc -l | tr -d " ")' + echo -n "${running}r/${stopped}s" + } + +prompt_color() { + + PS1="${BLUE}[${GREEN}\T${BLUE}][${YELLOW}\u${GREY}@${PURPLE}\h${GREY}:${CYAN}\W${BLUE}][${RED}\j${BLUE}]${BROWN}$P${PS_CLEAR} " + PS2="${P} " + +} + + +# ----------------------------------------------------------------------------- +# Ls and dircolors +# ----------------------------------------------------------------------------- + +# always passed to ls +LS_COMMON="-hBG" + +# if dircolors tool available, set it up +dircolors="$(type -P gdircolors dircolors | head -1)" + +# ----------------------------------------------------------------------------- +# Bash completion +# ----------------------------------------------------------------------------- + +for f in /usr/local/etc/bash_completion/* \ + /etc/bash_completion/* \ + ~/.bash/completion/* +do + + if [ -f $f ]; then + . $f + fi +done + +# override and disable tilde expansion +_expand() { +return 0 +} + +# ----------------------------------------------------------------------------- +# Aliases +# ----------------------------------------------------------------------------- + +for f in ~/.bash/aliases/* +do + if [ -f $f ]; then + . $f + fi +done + +# ----------------------------------------------------------------------------- +# Proxy related functions +# ----------------------------------------------------------------------------- + +function proxy_on() { + + export http_proxy=$proxy + export https_proxy=$proxy + export ftp_proxy=$proxy + export rsync_proxy=$proxy + return 0 + +} + +function proxy_off() { + + unset http_proxy + unset https_proxy + unset ftp_proxy + unset rsync_proxy + +} + +# ----------------------------------------------------------------------------- +# Archive extracting function +# ----------------------------------------------------------------------------- + +extract () { + if [ -f $1 ] ; then + case $1 in + *.tar.bz2) tar xjf $1 ;; + *.tar.gz) tar xzf $1 ;; + *.bz2) bunzip2 $1 ;; + *.rar) rar x $1 ;; + *.gz) gunzip $1 ;; + *.tar) tar xf $1 ;; + *.tbz2) tar xjf $1 ;; + *.tgz) tar xzf $1 ;; + *.zip) unzip $1 ;; + *.Z) uncompress $1 ;; + *) echo "'$1' cannot be extracted via extract()" ;; + esac + else + echo "'$1' is not a valid file" + fi +} + +# ----------------------------------------------------------------------------- +# Personal configuration +# ----------------------------------------------------------------------------- + +# load shenv file - personal configuration +test -r ~/.bash/shenv && + . ~/.bash/shenv -- cgit v1.2.3-70-g09d2