From b4e9c975a85dc2aae9f59ed2f1abbc34270af77f Mon Sep 17 00:00:00 2001 From: Devon Jones Date: Fri, 18 Mar 2011 19:37:52 -0400 Subject: [PATCH] initial commit --- bash_aliases.d/color.sh | 13 ++++++++++ bash_aliases.d/editor.sh | 6 +++++ bash_aliases.d/filesystem.sh | 10 ++++++++ bash_aliases.d/less.sh | 2 ++ bash_aliases.d/svn.sh | 2 ++ bash_aliases.d/todo_aliases.sh | 15 +++++++++++ bash_completion.d/todo | 35 ++++++++++++++++++++++++++ bash_functions.d/add_alias.sh | 9 +++++++ bash_functions.d/cgrep.sh | 9 +++++++ bash_functions.d/checkwinsize.sh | 3 +++ bash_functions.d/completion.sh | 13 ++++++++++ bash_functions.d/eternal_history.sh | 18 +++++++++++++ bash_functions.d/extract.sh | 22 ++++++++++++++++ bash_functions.d/glob_settings.sh | 1 + bash_functions.d/improve_grep.sh | 3 +++ bash_functions.d/improve_less.sh | 3 +++ bash_functions.d/lsbytes.sh | 8 ++++++ bash_functions.d/lsnew.sh | 5 ++++ bash_functions.d/prompt.sh | 39 +++++++++++++++++++++++++++++ bash_functions.d/queue_stack.sh | 25 ++++++++++++++++++ bash_functions.d/repeat.sh | 25 ++++++++++++++++++ bash_functions.d/vim.sh | 2 ++ bashrc | 17 +++++++++++++ 23 files changed, 285 insertions(+) create mode 100644 bash_aliases.d/color.sh create mode 100644 bash_aliases.d/editor.sh create mode 100644 bash_aliases.d/filesystem.sh create mode 100644 bash_aliases.d/less.sh create mode 100644 bash_aliases.d/svn.sh create mode 100644 bash_aliases.d/todo_aliases.sh create mode 100644 bash_completion.d/todo create mode 100644 bash_functions.d/add_alias.sh create mode 100644 bash_functions.d/cgrep.sh create mode 100644 bash_functions.d/checkwinsize.sh create mode 100644 bash_functions.d/completion.sh create mode 100644 bash_functions.d/eternal_history.sh create mode 100644 bash_functions.d/extract.sh create mode 100644 bash_functions.d/glob_settings.sh create mode 100644 bash_functions.d/improve_grep.sh create mode 100644 bash_functions.d/improve_less.sh create mode 100644 bash_functions.d/lsbytes.sh create mode 100644 bash_functions.d/lsnew.sh create mode 100644 bash_functions.d/prompt.sh create mode 100644 bash_functions.d/queue_stack.sh create mode 100644 bash_functions.d/repeat.sh create mode 100644 bash_functions.d/vim.sh create mode 100644 bashrc diff --git a/bash_aliases.d/color.sh b/bash_aliases.d/color.sh new file mode 100644 index 0000000..1577e6d --- /dev/null +++ b/bash_aliases.d/color.sh @@ -0,0 +1,13 @@ +# enable color support of ls and also add handy aliases +if [ "$TERM" != "dumb" ] && [ -x /usr/bin/dircolors ]; then + eval "`dircolors -b`" + alias ls='ls --color=auto' + alias la='ls -lAXh --color=always|less -R' + + alias grep='grep --color=auto' + alias fgrep='fgrep --color=auto' + alias egrep='egrep --color=auto' + + alias diff='colordiff' +fi + diff --git a/bash_aliases.d/editor.sh b/bash_aliases.d/editor.sh new file mode 100644 index 0000000..b92ec3f --- /dev/null +++ b/bash_aliases.d/editor.sh @@ -0,0 +1,6 @@ +alias ge='gedit' +alias gi="/usr/bin/gvim --servername GVIM --remote" + +# Open last modified file in vim +alias Vim="vim `ls -t | head -1`" + diff --git a/bash_aliases.d/filesystem.sh b/bash_aliases.d/filesystem.sh new file mode 100644 index 0000000..0198ea2 --- /dev/null +++ b/bash_aliases.d/filesystem.sh @@ -0,0 +1,10 @@ + +# Find top 5 big files +alias findbig="find . -type f -exec ls -s {} \; | sort -n -r | head -5" + +# Clear the screen and list file +alias cls='clear;ls' + +# To navigate to the different directories +alias ..='cd ..' +alias ...='cd ../..' diff --git a/bash_aliases.d/less.sh b/bash_aliases.d/less.sh new file mode 100644 index 0000000..20c0f8a --- /dev/null +++ b/bash_aliases.d/less.sh @@ -0,0 +1,2 @@ + +alias less='less -R' diff --git a/bash_aliases.d/svn.sh b/bash_aliases.d/svn.sh new file mode 100644 index 0000000..f94fbca --- /dev/null +++ b/bash_aliases.d/svn.sh @@ -0,0 +1,2 @@ + +alias sd='svn diff --diff-cmd /usr/bin/meld' diff --git a/bash_aliases.d/todo_aliases.sh b/bash_aliases.d/todo_aliases.sh new file mode 100644 index 0000000..0c20e4d --- /dev/null +++ b/bash_aliases.d/todo_aliases.sh @@ -0,0 +1,15 @@ +# todo.sh +alias t='todo.sh' +alias tls='todo.sh ls' +alias tpri='todo.sh pri' +alias tadd='todo.sh add' +alias tpv='todo.sh view project' +alias tcv='todo.sh view context' +alias tdv='todo.sh -x view date' +alias tv='todo.sh -x view' +alias trm='todo.sh rm' +alias tarc='todo.sh archive' +alias tdo='todo.sh do' +alias tsch='todo.sh schedule' +alias gt="/usr/bin/gvim --servername GVIM --remote ~/Dropbox/todo/todo.txt" + diff --git a/bash_completion.d/todo b/bash_completion.d/todo new file mode 100644 index 0000000..cfc0054 --- /dev/null +++ b/bash_completion.d/todo @@ -0,0 +1,35 @@ +_todo() +{ + local cur prev opts + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + + COMMANDS="add a addto addm append app archive command del \ + rm depri dp do help list ls listall lsa listcon \ + lsc listfile lf listpri lsp listproj lsproj move \ + mv prepend prep pri p replace report" + + # Add custom commands from add-ons, if installed. + COMMANDS="$COMMANDS $('ls' ${TODO_ACTIONS_DIR:-$HOME/.todo.actions.d}/ 2>/dev/null)" + + OPTS="-@ -@@ -+ -++ -d -f -h -p -P -PP -a -n -t -v -vv -V -x" + + if [ $COMP_CWORD -eq 1 ]; then + completions="$COMMANDS $OPTS" + else + case "${prev}" in + -*) completions="$COMMANDS $OPTS";; + *) return 0;; + esac + fi + + COMPREPLY=( $( compgen -W "$completions" -- $cur )) + return 0 +} + +complete -F _todo todo.sh +# If you define an alias (e.g. "t") to todo.sh, you need to explicitly enable +# completion for it, too: +complete -F _todo t + diff --git a/bash_functions.d/add_alias.sh b/bash_functions.d/add_alias.sh new file mode 100644 index 0000000..92a4a63 --- /dev/null +++ b/bash_functions.d/add_alias.sh @@ -0,0 +1,9 @@ +# Function which adds an alias to the current shell and to +# the ~/.bash_aliases file. +add_alias () { + local name=$1 value="$2" + echo alias $name=\'$value\' >>~/.bash_aliases + eval alias $name=\'$value\' + alias $name +} + diff --git a/bash_functions.d/cgrep.sh b/bash_functions.d/cgrep.sh new file mode 100644 index 0000000..7f9d613 --- /dev/null +++ b/bash_functions.d/cgrep.sh @@ -0,0 +1,9 @@ +# grep colorizer. Colorizes output (like from tail or cat) while still printing all lines +# Can only be used against stdin. +# usage: +# cgrep +function cgrep { + arr=("$@") + arr_pop + egrep --color -e "$" -e "$placeholder" ${arr[@]} +} diff --git a/bash_functions.d/checkwinsize.sh b/bash_functions.d/checkwinsize.sh new file mode 100644 index 0000000..0152ea4 --- /dev/null +++ b/bash_functions.d/checkwinsize.sh @@ -0,0 +1,3 @@ +# check the window size after each command and, if necessary, +# update the values of LINES and COLUMNS. +shopt -s checkwinsize diff --git a/bash_functions.d/completion.sh b/bash_functions.d/completion.sh new file mode 100644 index 0000000..b84f7a0 --- /dev/null +++ b/bash_functions.d/completion.sh @@ -0,0 +1,13 @@ +if [ -d ~/.bash_completion.d -a -r ~/.bash_completion.d -a \ + -x ~/.bash_completion.d ]; then + for i in ~/.bash_completion.d/*; do + [[ ${i##*/} != @(*~|*.bak|*.swp|\#*\#|*.dpkg*|*.rpm@(orig|new|save)) ]] && + [ \( -f $i -o -h $i \) -a -r $i ] && . $i + done +fi + +# auto-completion is not case sensitive anymore +set completion-ignore-case On + +# Tab completion for sudo +complete -cf sudo diff --git a/bash_functions.d/eternal_history.sh b/bash_functions.d/eternal_history.sh new file mode 100644 index 0000000..38d1b47 --- /dev/null +++ b/bash_functions.d/eternal_history.sh @@ -0,0 +1,18 @@ +# Sets up reasonable history for bash, storing times. Also creates a file +# .bash_eternal_history that permanently stores all commands from all open terminals + +# don't put duplicate lines in the history. See bash(1) for more options +# don't overwrite GNU Midnight Commander's setting of `ignorespace'. +export HISTCONTROL=$HISTCONTROL${HISTCONTROL+,}ignoredups +# ... or force ignoredups and ignorespace +export HISTCONTROL=ignoreboth +# Add unix timestamps to history +export HISTTIMEFORMAT="%s " + +# append to the history file, don't overwrite it +shopt -s histappend +shopt -s histverify + +# Create ~/.bash_eternal_history +PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND ; }"'echo $$ $USER "$(history 1)" >> ~/.bash_eternal_history' + diff --git a/bash_functions.d/extract.sh b/bash_functions.d/extract.sh new file mode 100644 index 0000000..72868aa --- /dev/null +++ b/bash_functions.d/extract.sh @@ -0,0 +1,22 @@ +## Archives +# Extract about anything +extract () { + if [ -f $1 ] ; then + case $1 in + *.tar.bz2) tar xvjf $1 ;; + *.tar.gz) tar xvzf $1 ;; + *.bz2) bunzip2 $1 ;; + *.rar) unrar x $1 ;; + *.gz) gunzip $1 ;; + *.tar) tar xvf $1 ;; + *.tbz2) tar xvjf $1 ;; + *.tgz) tar xvzf $1 ;; + *.zip) unzip $1 ;; + *.Z) uncompress $1 ;; + *.7z) 7z x $1 ;; + *) echo "'$1' cannot be extracted via >extract<" ;; + esac + else + echo "'$1' is not a valid file" + fi +} diff --git a/bash_functions.d/glob_settings.sh b/bash_functions.d/glob_settings.sh new file mode 100644 index 0000000..b6a09cf --- /dev/null +++ b/bash_functions.d/glob_settings.sh @@ -0,0 +1 @@ +shopt -s extglob diff --git a/bash_functions.d/improve_grep.sh b/bash_functions.d/improve_grep.sh new file mode 100644 index 0000000..6feb0f7 --- /dev/null +++ b/bash_functions.d/improve_grep.sh @@ -0,0 +1,3 @@ +GREP_OPTIONS="--exclude-dir=\.svn --exclude-dir=log --exclude-dir=\.git" +export GREP_OPTIONS + diff --git a/bash_functions.d/improve_less.sh b/bash_functions.d/improve_less.sh new file mode 100644 index 0000000..e3409b9 --- /dev/null +++ b/bash_functions.d/improve_less.sh @@ -0,0 +1,3 @@ +# make less more friendly for non-text input files, see lesspipe(1) +[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)" + diff --git a/bash_functions.d/lsbytes.sh b/bash_functions.d/lsbytes.sh new file mode 100644 index 0000000..b772410 --- /dev/null +++ b/bash_functions.d/lsbytes.sh @@ -0,0 +1,8 @@ +# inspired by http://tldp.org/HOWTO/Bash-Prompt-HOWTO/x279.html +# but I made it a single awk instead of an awk, forloop and a bc +# asumes we have awk available. but really, who doesnt have awk? +# let's get the size of the files in this dir +function lsbytes { + echo -n $(ls -l | awk '/^-/{total += $5} END{printf "%.2f", total/1048576}') +} + diff --git a/bash_functions.d/lsnew.sh b/bash_functions.d/lsnew.sh new file mode 100644 index 0000000..253f191 --- /dev/null +++ b/bash_functions.d/lsnew.sh @@ -0,0 +1,5 @@ +# List the most recent files in a directory +lsnew() +{ + ls -lt ${1+"$@"} | head -20; +} diff --git a/bash_functions.d/prompt.sh b/bash_functions.d/prompt.sh new file mode 100644 index 0000000..047947a --- /dev/null +++ b/bash_functions.d/prompt.sh @@ -0,0 +1,39 @@ +# set variable identifying the chroot you work in (used in the prompt below) +if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then + debian_chroot=$(cat /etc/debian_chroot) +fi + +# set a fancy prompt (non-color, unless we know we "want" color) +case "$TERM" in + xterm-color) color_prompt=yes;; + xterm) color_prompt=yes;; +esac + +#force_color_prompt=yes + +if [ -n "$force_color_prompt" ]; then + if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then + # We have color support; assume it's compliant with Ecma-48 + # (ISO/IEC-6429). (Lack of such support is extremely rare, and such + # a case would tend to support setf rather than setaf.) + color_prompt=yes + else + color_prompt= + fi +fi + +if [ "$color_prompt" = yes ]; then + PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\] \[\033[00;32m\]${?} \[\033[01;34m\]\w \$\[\033[00m\] ' +else + PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' +fi +unset color_prompt force_color_prompt + +# If this is an xterm set the title to user@host:dir +case "$TERM" in +xterm*|rxvt*) + PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"' + ;; +*) + ;; +esac diff --git a/bash_functions.d/queue_stack.sh b/bash_functions.d/queue_stack.sh new file mode 100644 index 0000000..ea2408f --- /dev/null +++ b/bash_functions.d/queue_stack.sh @@ -0,0 +1,25 @@ +# Queue and Stack functions (push, pop, shift, unshift) +# Sorta craptastic because the array /must/ be named $arr +# and output always ends up in the variable $placeholder +# +# Derived from: http://www.rootninja.com/how-to-push-pop-shift-and-unshift-arrays-in-bash/ +function arr_push() { + arr=("${arr[@]}" "$1") +} + +function arr_pop() { + local i=$(expr ${#arr[@]} - 1) + placeholder=${arr[$i]} + unset arr[$i] + arr=("${arr[@]}") +} + +function arr_shift() { + arr=("$1" "${arr[@]}") +} + +function arr_unshift() { + placeholder=${arr[0]} + unset arr[0] + arr=("${arr[@]}") +} diff --git a/bash_functions.d/repeat.sh b/bash_functions.d/repeat.sh new file mode 100644 index 0000000..83cc0df --- /dev/null +++ b/bash_functions.d/repeat.sh @@ -0,0 +1,25 @@ +# "repeat" command. Like: +# +# repeat 10 echo foo +repeat () { + local count="$1" i; + shift; + for i in $(seq 1 "$count"); + do + eval "$@"; + done +} + +# Subfunction needed by `repeat'. +seq () { + local lower upper output; + lower=$1 upper=$2; + while [ $lower -le $upper ]; + do + output="$output $lower"; + lower=$[ $lower + 1 ]; + done; + echo $output +} + + diff --git a/bash_functions.d/vim.sh b/bash_functions.d/vim.sh new file mode 100644 index 0000000..c365c6f --- /dev/null +++ b/bash_functions.d/vim.sh @@ -0,0 +1,2 @@ +export EDITOR=/usr/bin/vim +set -o vi diff --git a/bashrc b/bashrc new file mode 100644 index 0000000..89bb717 --- /dev/null +++ b/bashrc @@ -0,0 +1,17 @@ +# If not running interactively, don't do anything +[ -z "$PS1" ] && return + +export PATH=$PATH:$HOME/bin + +function include_d { + dir=$1 + if [ -d ~/.$dir.d -a -r ~/.$dir.d -a -x ~/.$dir.d ]; then + for i in ~/.$dir.d/*.sh; do + echo $i + . $i + done + fi +} + +include_d bash_functions +include_d bash_aliases