Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
devonjones committed Mar 18, 2011
1 parent 2e1f6d9 commit b4e9c97
Show file tree
Hide file tree
Showing 23 changed files with 285 additions and 0 deletions.
13 changes: 13 additions & 0 deletions 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

6 changes: 6 additions & 0 deletions 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`"

10 changes: 10 additions & 0 deletions 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 ../..'
2 changes: 2 additions & 0 deletions bash_aliases.d/less.sh
@@ -0,0 +1,2 @@

alias less='less -R'
2 changes: 2 additions & 0 deletions bash_aliases.d/svn.sh
@@ -0,0 +1,2 @@

alias sd='svn diff --diff-cmd /usr/bin/meld'
15 changes: 15 additions & 0 deletions 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"

35 changes: 35 additions & 0 deletions 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

9 changes: 9 additions & 0 deletions 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
}

9 changes: 9 additions & 0 deletions 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 <standard egrep args> <pattern>
function cgrep {
arr=("$@")
arr_pop
egrep --color -e "$" -e "$placeholder" ${arr[@]}
}
3 changes: 3 additions & 0 deletions 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
13 changes: 13 additions & 0 deletions 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
18 changes: 18 additions & 0 deletions 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'

22 changes: 22 additions & 0 deletions 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
}
1 change: 1 addition & 0 deletions bash_functions.d/glob_settings.sh
@@ -0,0 +1 @@
shopt -s extglob
3 changes: 3 additions & 0 deletions bash_functions.d/improve_grep.sh
@@ -0,0 +1,3 @@
GREP_OPTIONS="--exclude-dir=\.svn --exclude-dir=log --exclude-dir=\.git"
export GREP_OPTIONS

3 changes: 3 additions & 0 deletions 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)"

8 changes: 8 additions & 0 deletions 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}')
}

5 changes: 5 additions & 0 deletions bash_functions.d/lsnew.sh
@@ -0,0 +1,5 @@
# List the most recent files in a directory
lsnew()
{
ls -lt ${1+"$@"} | head -20;
}
39 changes: 39 additions & 0 deletions 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
25 changes: 25 additions & 0 deletions 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[@]}")
}
25 changes: 25 additions & 0 deletions 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
}


2 changes: 2 additions & 0 deletions bash_functions.d/vim.sh
@@ -0,0 +1,2 @@
export EDITOR=/usr/bin/vim
set -o vi
17 changes: 17 additions & 0 deletions 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

0 comments on commit b4e9c97

Please sign in to comment.