From 0cfdb493f045e7c533328617427a7416783c28b5 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Wed, 29 Oct 2008 03:50:18 +0100 Subject: added bashrc configdir added git config --- bashrc/common/alias.sh | 29 +++++++++++++++ bashrc/common/bashcomp.sh | 20 +++++++++++ bashrc/common/color.sh | 42 ++++++++++++++++++++++ bashrc/common/dircolors.sh | 4 +++ bashrc/common/env.sh | 5 +++ bashrc/common/locale.sh | 5 +++ bashrc/common/pager.sh | 13 +++++++ bashrc/common/shopt.sh | 23 ++++++++++++ bashrc/dist/init.sh | 13 +++++++ bashrc/main.sh | 90 ++++++++++++++++++++++++++++++++++++++++++++++ bashrc/node/init.sh | 3 ++ 11 files changed, 247 insertions(+) create mode 100644 bashrc/common/alias.sh create mode 100644 bashrc/common/bashcomp.sh create mode 100644 bashrc/common/color.sh create mode 100644 bashrc/common/dircolors.sh create mode 100644 bashrc/common/env.sh create mode 100644 bashrc/common/locale.sh create mode 100644 bashrc/common/pager.sh create mode 100644 bashrc/common/shopt.sh create mode 100644 bashrc/dist/init.sh create mode 100644 bashrc/main.sh create mode 100644 bashrc/node/init.sh (limited to 'bashrc') diff --git a/bashrc/common/alias.sh b/bashrc/common/alias.sh new file mode 100644 index 0000000..03df556 --- /dev/null +++ b/bashrc/common/alias.sh @@ -0,0 +1,29 @@ +# command aliases + +# ls helpers +alias ll="ls -l" +alias la="ls -la" +alias l="ls -lh" + +# cd helpers +alias ..="cd .." +alias ...="cd ../.." +alias ....="cd ../../.." + +# make default what should be default +alias sudo="sudo -H" + +# mkdir + chdir +mkcd() { + mkdir -p $1 && cd $1 +} + +# create tarball of one directory +mktar() { + [[ -z "$1" ]] && return 1 + tar cjvf "${1%%/}.tar.bz2" "${1%%/}/" +} + +# rar -> unrar +alias rar=unrar + diff --git a/bashrc/common/bashcomp.sh b/bashrc/common/bashcomp.sh new file mode 100644 index 0000000..48d83fa --- /dev/null +++ b/bashrc/common/bashcomp.sh @@ -0,0 +1,20 @@ +# bash completion + +bmajor=${BASH_VERSION%%.*} +bminor=${BASH_VERSION#*.} +bminor=${bminor//[^0-9]*} + +if [[ ${bmajor} -eq 2 && ${bminor} -gt 4 ]] || [[ ${bmajor} -gt 2 ]]; then + [[ -f /etc/bash_completion ]] && source /etc/bash_completion + + if [[ -d ~/.bash_completion.d ]]; then + for i in ~/.bash_completion.d/*; do + [[ -f ${i} ]] && source ${i} + done + fi +fi + +unset bmajor bminor + +export COMP_WORDBREAKS=${COMP_WORDBREAKS/:/} +export FIGNORE=".o:~" diff --git a/bashrc/common/color.sh b/bashrc/common/color.sh new file mode 100644 index 0000000..ca62988 --- /dev/null +++ b/bashrc/common/color.sh @@ -0,0 +1,42 @@ +# color code definitions + +# print ugly color codes +coco() { + [[ -z "$1" ]] && echo -ne "\033[0m" || echo -ne "\033[${1}m" +} + +# name all colors to get rid of hieroglyphics +color() { + case $1 in + black) coco '0;30' ;; + dgray) coco '1;30' ;; + red) coco '0;31' ;; + lred) coco '1;31' ;; + green) coco '0;32' ;; + lgreen) coco '1;32' ;; + brown) coco '0;33' ;; + yellow) coco '1;33' ;; + blue) coco '0;34' ;; + lblue) coco '1;34' ;; + purple) coco '0;35' ;; + lpurple) coco '1;35' ;; + cyan) coco '0;36' ;; + lcyan) coco '1;36' ;; + lgray) coco '0;37' ;; + white) coco '1;37' ;; + *) coco '0' ;; + esac +} + +pcolor() { + echo -ne "\[$(color $@)\]" +} + +colors() { + local l="black dgray red lred green lgreen brown yellow blue" + local l="${l} lblue purple lpurple cyan lcyan lgray white" + + for i in $l; do + echo "$i = $(color $i)$i$(color)" + done +} diff --git a/bashrc/common/dircolors.sh b/bashrc/common/dircolors.sh new file mode 100644 index 0000000..f26a163 --- /dev/null +++ b/bashrc/common/dircolors.sh @@ -0,0 +1,4 @@ +# colored output for ls +if hash dircolors; then + eval $(dircolors -b) +fi diff --git a/bashrc/common/env.sh b/bashrc/common/env.sh new file mode 100644 index 0000000..e02e6ad --- /dev/null +++ b/bashrc/common/env.sh @@ -0,0 +1,5 @@ +# force sane editor +export EDITOR=/usr/bin/nano + +# set timezone if needed +[[ -z "$TZ" ]] && export TZ=Europe/Berlin diff --git a/bashrc/common/locale.sh b/bashrc/common/locale.sh new file mode 100644 index 0000000..97c3f17 --- /dev/null +++ b/bashrc/common/locale.sh @@ -0,0 +1,5 @@ +# find a usuable locale + +eval unset ${!LC_*} LANG +export LANG="en_US.UTF-8" +export LC_COLLATE="C" diff --git a/bashrc/common/pager.sh b/bashrc/common/pager.sh new file mode 100644 index 0000000..a92031e --- /dev/null +++ b/bashrc/common/pager.sh @@ -0,0 +1,13 @@ +# pager options + +# use less by default ... +if hash less; then + export PAGER=less + export LESS="-R --ignore-case --long-prompt" +fi + +# but user most, if available +if hash most; then + export PAGER=most + export MANPAGER=most +fi diff --git a/bashrc/common/shopt.sh b/bashrc/common/shopt.sh new file mode 100644 index 0000000..07a796a --- /dev/null +++ b/bashrc/common/shopt.sh @@ -0,0 +1,23 @@ +# bash configuration + +# basic search path for chdir +export CDPATH=".:~" + +# keep size of history small ... +export HISTCONTROL="ignoreboth:erasedups" + +# ... but keep a lot of history +export HISTFILESIZE=5000 +export HISTSIZE=5000 + +# save timestamp in history +export HISTTIMEFORMAT="%+ " + +# check window size after each command +shopt -s checkwinsize + +# save multi-line command as one line +shopt -s cmdhist + +# append history +shopt -s histappend diff --git a/bashrc/dist/init.sh b/bashrc/dist/init.sh new file mode 100644 index 0000000..4dd4ed1 --- /dev/null +++ b/bashrc/dist/init.sh @@ -0,0 +1,13 @@ +# get distribution specific data + +_DISTNAME="unknown" + +if [[ -f /etc/gentoo-release ]]; then + _DISTNAME="gentoo" +elif [[ -f /etc/debian_version ]] ; then + _DISTNAME="debian" +fi + +declare -r _DISTNAME + +_load dist common diff --git a/bashrc/main.sh b/bashrc/main.sh new file mode 100644 index 0000000..649641c --- /dev/null +++ b/bashrc/main.sh @@ -0,0 +1,90 @@ +# this file is sourced by all bash shells on startup + +# test for interactive shell +[[ $- != *i* ]] && return + +declare -r _DOTFILES_DIR="${HOME}/.dotfiles" +declare -r _BASHRC_DIR="${_DOTFILES_DIR}/bashrc" + +# self update magic +_self_update() { + pushd ${_DOTFILES_DIR} &>/dev/null + + if [[ -n "$(git fetch 2>&1)" && $? -eq 0 ]]; then + echo -ne "\033[31m*\033[0m dotfile updates found, merge now? " + + if read; then + git merge origin/master + popd &>/dev/null + exec $SHELL + fi + fi + + popd &>/dev/null +} + +# module load magic +_load() { + local base path + local pedantic=0 + + [[ -z $1 || -z $2 ]] && return + + base=${_BASHRC_DIR}/${1} + + if [[ $1 == "common" || $2 == "init" ]]; then + path=${2}.sh + pedantic=1 + else + case $1 in + (dist) path=${_DISTNAME}/${2}.sh ;; + (node) path=${_NODENAME}/${2}.sh ;; + esac + fi + + if [[ -r ${base}/${path} ]]; then + source ${base}/${path} + elif [[ ${pedantic} -eq 1 ]]; then + echo "error: cannot find necessary startup file: ${base}/${path}" + fi +} + +# update first +_self_update + +# locale should be set first +_load common locale + +# now set a reasonable environment +_load common env + +# bash configuration +_load common shopt + +# load internals +_load dist init +_load node init + +# command aliases +_load common alias + +# pager options +_load common pager + +# color code definitions +_load common color + +# colored output for ls +_load common dircolors + +# command prompt +#_load common prompt + +# bash completion +_load common bashcomp + +# load common distribution settings +_load dist common + +# load distribution specific node settings +_load node ${_DISTNAME} diff --git a/bashrc/node/init.sh b/bashrc/node/init.sh new file mode 100644 index 0000000..6bf0924 --- /dev/null +++ b/bashrc/node/init.sh @@ -0,0 +1,3 @@ +# get node specific data + +declare -r _NODENAME=laptop -- cgit v1.2.3