Skip to content
Browse files

Merge branch 'master' of github.com:Knewton/bash_magic

  • Loading branch information...
2 parents 639fddb + 63d7748 commit 1b1884420a6836f4f630cda6e613392c47f913ed @devonjones devonjones committed
View
58 README
@@ -0,0 +1,58 @@
+structured bashrc to allow for much easier understanding and handling of what shell changes you have set up.
+
+
+DESIGN
+
+Instead of keeping my bashrc all in one file that becomes a giant mess, I've split the file out into a bunch of small shell scripts that the main bashrc automatically imports. This results in the followingdirectory setup:
+
+~/.bashrc
+~/.bash_aliases.d/
+~/.bash_completion.d/
+~/.bash_functions.d/
+
+The base .bashrc (or can be renamed .bash_profile for those of you that use .bash_profile instead) contains only 4 things:
+
+1) a break for non interactive shells that stops any of it loading
+2) The addition of ~/bin to the path
+3) definition of the include_d function
+4) imports of the 3 above directories.
+
+Inside each directory, only files with the .sh extension will be sourced. The directory names are obvious, but I'll detail what's contained just to be complete.
+
+
+BASH_ALIASES.D
+
+This directory is intended to hold a bunch of files setting up all of your aliases. It's preferred to keep only aliases that are closely related in the same file so that other people can easily pick up chucks of your alias behavior without having to import it all. Personally, I keep one for color terminals, my editor, filesystem commands and then a series of alias files for dealing with individual programs.
+
+
+BASH_COMPLETION.D
+
+Personally I find bash completion super useful, so I keep a whole directory for dealing with completions. Timple, one file per program is the expected usage.
+
+
+BASH_FUNCTIONS.D
+
+This directory is much more of a grab bag then the above two. It contains a seperate file for each discrete functional behavior I'm making to my shell. Some files contain only actual bash functions, some add functionality like eternal_bash_history.
+
+
+USAGE
+
+Until I get around to creating an install program, my suggestion is that you do the following to install this:
+
+1) Copy the contents of bashrc and append it onto the end of your .bashrc or .bash_profile
+ `cat bashrc >> ~/.bashrc`
+ -or-
+ `cat bashrc >> ~/.bash_profile
+
+2) Create your .d directories
+ `mkdir ~/.bash_aliases.d ~/.bash_completion.d ~/.bash_functions.d`
+
+3) Symlink any functionality you want from bash_magic into the appropriate directory
+ `cd ~/.bash_functions.d`
+ `ln -s <bash_magic project dir>/.bash_functions/eternal_history.sh`
+ <repeat as needed>
+
+4) Go through your existing .bashrc/.bash_profile and pull coherent chunks of functionality out and stuff it into new files in the appropriate directory
+
+5) Live a happier life knowing that your old messy bashrc is now a heck of a lot easier to understand.
+
View
2 bash_aliases.d/todo_aliases.sh
@@ -11,5 +11,5 @@ 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"
+alias gt="/usr/bin/gvim --servername GVIM --remote $HOME/Dropbox/todo/todo.txt"
View
0 bash_completion.d/todo → bash_completion.d/todo.sh
File renamed without changes.
View
2 bash_functions.d/add_alias.sh
@@ -2,7 +2,7 @@
# the ~/.bash_aliases file.
add_alias () {
local name=$1 value="$2"
- echo alias $name=\'$value\' >>~/.bash_aliases
+ echo alias $name=\'$value\' >> $HOME/.bash_aliases
eval alias $name=\'$value\'
alias $name
}
View
8 bash_functions.d/completion.sh
@@ -1,11 +1,3 @@
-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
View
2 bash_functions.d/eternal_history.sh
@@ -14,5 +14,5 @@ shopt -s histappend
shopt -s histverify
# Create ~/.bash_eternal_history
-PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND ; }"'echo $$ $USER "$(history 1)" >> ~/.bash_eternal_history'
+PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND ; }"'echo $$ $USER "$(history 1)" >> $HOME/.bash_eternal_history'
View
2 bash_functions.d/prompt.sh
@@ -32,7 +32,7 @@ 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"'
+ PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND ; }"'echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'
;;
*)
;;
View
5 bashrc
@@ -5,8 +5,8 @@ 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
+ if [ -d $HOME/.$dir.d -a -r $HOME/.$dir.d -a -x $HOME/.$dir.d ]; then
+ for i in $HOME/.$dir.d/*.sh; do
. $i
done
fi
@@ -14,3 +14,4 @@ function include_d {
include_d bash_functions
include_d bash_aliases
+include_d bash_completion

0 comments on commit 1b18844

Please sign in to comment.
Something went wrong with that request. Please try again.