Adjust _bashrc to drop `screen.` from `screen.*` TERMs (for Ubuntu).
[dotfiles-framework.git] / disconnect.sh
1 #!/bin/bash
2 #
3 # You're about to give your sysadmin account to some newbie, and
4 # they'd just be confused by all this efficiency.  This script freezes
5 # your dotfiles in their current state and makes everthing look
6 # normal.  Note that this will delete your ~/.dotfiles directory, and
7 # strip the .dotfiles portion from your ~/.bashrc file.
8
9 # See if the bashrc file is involved with .dotfiles at all
10 if [ -e _bashrc ]; then
11     BASHRC="yes"
12 else
13     BASHRC="no"
14 fi
15
16 # For each file in this directory.
17 for file in _*; do
18     # Create .dotfile version.
19     dotfile=.${file/_/}
20     
21     # Replace symlinks with their target
22     if [ -h ~/$dotfile ]; then
23         echo "De-symlink ~/$dotfile"
24         rm -f ~/$dotfile
25         mv $file ~/$dotfile
26     fi
27 done
28
29 if [ $BASHRC == "yes" ]; then
30     # We may have a dotfiles section in ~/.bashrc.  Strip it out.
31     BC="### ---- begin .dotfiles section ---- (keep this magic comment)"
32     EC="### ---- end .dotfiles section ---- (keep this magic comment)"
33     AWKSCRIPT="BEGIN{copy=1}{"
34     AWKSCRIPT="$AWKSCRIPT if(\$0 == \"$BC\"){copy=0};"
35     AWKSCRIPT="$AWKSCRIPT if(\$0 == \"$EC\"){copy=1};"
36     AWKSCRIPT="$AWKSCRIPT if(copy==1 && \$0 != \"$EC\"){print \$0}"
37     AWKSCRIPT="$AWKSCRIPT}"
38     
39     echo "Strip dotfiles section from ~/.bashrc"
40     awk "$AWKSCRIPT" ~/.bashrc > bashrc_stripped
41     
42     # see if the stripped file is any different
43     DIFF=`diff ~/.bashrc bashrc_stripped`
44     if [ $? -ne 1 ]; then exit 1; fi   # diff failed, bail
45     if [ -n "$DIFF" ]; then
46         echo "Replace ~/.bashrc with stripped version"
47         rm -f ~/.bashrc
48         cp bashrc_stripped ~/.bashrc
49     else
50         echo "No dotfiles section in ~/.bashrc"
51     fi
52 fi
53
54 DOTFILES_DIR=`pwd`
55 cd
56 echo "Remove the dotfiles dir $DOTFILES_DIR"
57 rm -rf $DOTFILES_DIR