2015-05-14 19:25:38 -04:00
#!/usr/bin/env bash
2015-05-31 02:06:00 -04:00
echoerr( ) { echo " $@ " >& 2; }
2015-05-14 19:25:38 -04:00
2015-05-31 16:07:49 -04:00
testmode = 0;
case " $1 " in
test )
testmode = 1;
echoerr "Test mode enabled."
esac
2015-05-14 19:25:38 -04:00
paths = ( '~/.profile' '~/.bash_profile' '~/.bashrc' '~/.bash_logout' '~/.gitconfig' '~/.ssh/config' '~/.tmux.conf' '~/.vimrc' '~/.vim/vimrc' '~/.zprofile' '~/.zshenv' '~/.zshrc' '~/bin' '~/.Xmodmap' '~/.Xresources' '~/.Xdefaults' '~/.vimperatorrc' '~/.xinitrc' '~/.i3' '~/.i3status.conf' '~/.config/awesome' '~/.config/pianobar' '~/.config/vimprobable' '~/.config/redshift' '~/.config/openbox' '~/.config/tint2' )
2015-05-31 02:06:00 -04:00
setupshell = 'echo "Setting up DotBot. Please do not ^C." >&2'
2015-05-15 17:21:40 -04:00
dotclean = ''
dotlink = ''
dotshell = ''
2015-05-31 02:06:00 -04:00
echoerr "Welcome to the configuration generator for DotBot"
echoerr "Please be aware that if you have a complicated setup, you may need more customization than this script offers."
echoerr;
echoerr "At any time, press ^C to quit. No changes will be made until you confirm."
echoerr;
2015-05-15 17:21:40 -04:00
prefix = "~/.dotfiles"
prefixfull = " ${ prefix / \~ / ${ HOME } } "
if ! [ -d $prefixfull ] ; then
2015-05-31 02:06:00 -04:00
echoerr " ${ prefix } is not in use. "
2015-05-15 17:21:40 -04:00
else
2015-05-31 02:06:00 -04:00
echoerr " ${ prefix } exists and may have another purpose than ours. "
2015-05-15 17:21:40 -04:00
fi
moveon = 0;
2015-05-31 02:06:00 -04:00
until ( ( $moveon ) ) ; do
read -p " Where do you want your dotfiles repository to be? ( $prefix ) " answer
2015-05-15 17:21:40 -04:00
if echo " $answer " | grep -q " ^ $" ; then
moveon = 1
else
2015-05-31 02:06:00 -04:00
echoerr "FEATURE NOT YET SUPPORTED."
echoerr "Sorry for misleading you."
echoerr;
2015-05-15 17:21:40 -04:00
fi
done
2015-05-31 02:06:00 -04:00
setupshell = $setupshell '; mkdir -p ' $prefix '; cd ' $prefix '; git init'
2015-05-15 17:21:40 -04:00
moveon = 0;
2015-05-31 02:06:00 -04:00
until ( ( $moveon ) ) ; do
2015-05-15 17:21:40 -04:00
read -p "Shall we add DotBot as a submodule (a good idea)? (Y/n) " answer
if echo " $answer " | grep -iq "^y" || echo " $answer " | grep -q " ^ $" ; then
2015-05-31 02:06:00 -04:00
echoerr "Will do."
setupshell = $setupshell '; git submodule add https://github.com/anishathalye/dotbot; cp dotbot/tools/git-submodule/install .'
2015-05-15 17:21:40 -04:00
moveon = 1
elif echo " $answer " | grep -iq "^n" ; then
2015-05-31 02:06:00 -04:00
echoerr "Okay, I shall not. You will need to manually set up your install script."
2015-05-15 17:21:40 -04:00
moveon = 1
else
2015-05-31 02:06:00 -04:00
echoerr " Answer not understood: ${ answer } "
2015-05-15 17:21:40 -04:00
fi
done
2015-05-14 19:25:38 -04:00
2015-05-15 17:21:40 -04:00
moveon = 0;
2015-05-31 02:06:00 -04:00
until ( ( $moveon ) ) ; do
2015-05-15 17:21:40 -04:00
read -p "Do you want DotBot to clean ~/ of broken links added by DotBot? (recommended) (Y/n) " answer
if echo " $answer " | grep -iq "^y" || echo " $answer " | grep -q " ^ $" ; then
2015-05-31 02:06:00 -04:00
echoerr "I will ask DotBot to clean."
2015-05-15 17:21:40 -04:00
dotclean = "- clean: ['~']"
moveon = 1
elif echo " $answer " | grep -iq "^n" ; then
2015-05-31 02:06:00 -04:00
echoerr "Not asking DotBot to clean."
2015-05-15 17:21:40 -04:00
moveon = 1
else
2015-05-31 02:06:00 -04:00
echoerr " Answer not understood: ${ answer } "
2015-05-15 17:21:40 -04:00
fi
done
2015-05-31 02:06:00 -04:00
declare -a linksection;
declare -i i;
2015-05-15 17:21:40 -04:00
2015-05-31 02:06:00 -04:00
echoerr "Going to iterate items"
2015-05-14 19:25:38 -04:00
for item in ${ paths [*] }
do
fullname = " ${ item / \~ / $HOME } "
if [ -f $fullname ] || [ -d $fullname ] ; then
moveon = 0;
2015-05-31 02:06:00 -04:00
until ( ( $moveon ) ) ; do
read -p " I found ${ item } , do you want to DotBot it? (Y/n) " answer
2015-05-14 19:25:38 -04:00
if echo " $answer " | grep -iq "^y" || echo " $answer " | grep -q " ^ $" ; then
2015-05-31 02:06:00 -04:00
linksection[ $i ] = $item ;
2015-05-15 17:21:40 -04:00
i = $i +1
2015-05-31 02:06:00 -04:00
echoerr "DotBotted!"
2015-05-14 19:25:38 -04:00
moveon = 1
elif echo " $answer " | grep -iq "^n" ; then
2015-05-31 02:06:00 -04:00
echoerr "Not added to DotBot."
2015-05-14 19:25:38 -04:00
moveon = 1
else
2015-05-31 02:06:00 -04:00
echoerr " Answer not understood: ${ answer } "
2015-05-14 19:25:38 -04:00
fi
done
fi
done
2015-05-31 02:06:00 -04:00
dotlink = '- link:'
newline = '\n'
hspace = '\x20\x20\x20\x20'
2015-05-15 17:21:40 -04:00
for item in ${ linksection [*] }
do
2015-05-31 02:06:00 -04:00
fullname = " ${ item / \~ / $HOME } "
firstdot = ` expr index " $item " .`
firstslash = ` expr index " $item " /`
if [ -d $fullname ] ; then
itempath = $item '/'
else
itempath = $item
fi
if [ [ $firstdot -gt $firstslash ] ] ; then
itempath = ${ itempath : $firstdot } ;
else
itempath = ${ itempath : $firstslash } ;
fi
new_entry = $newline $hspace $item ':'
new_entry = $new_entry $newline $hspace $hspace 'path: ' $itempath
new_entry = $new_entry $newline $hspace $hspace 'create: true'
new_entry = $new_entry $newline $hspace $hspace 'relink: false'
new_entry = $new_entry $newline $hspace $hspace 'force: false'
setupshell = $setupshell '; mkdir -p ' $itempath '; rmdir ' $itempath '; mv ' $item ' ' $itempath
dotlink = " $dotlink $new_entry "
2015-05-15 17:21:40 -04:00
done
2015-05-31 02:06:00 -04:00
export installconfyaml = " $dotclean $newline $newline $dotlink $newline $newline $dotshell "
setupshell = $setupshell '; echo -e "' $installconfyaml '" > install.conf.yaml'
moveon = 0;
until ( ( $moveon ) ) ; do
read -p "Shall I make the initial commit? (Y/n) " answer
if echo " $answer " | grep -iq "^y" || echo " $answer " | grep -q " ^ $" ; then
echoerr "Will do."
setupshell = $setupshell '; git add -A; git commit -m "Initial commit"'
moveon = 1
elif echo " $answer " | grep -iq "^n" ; then
echoerr "Okay, I shall not. You will need to take care of that yourself."
moveon = 1
else
echoerr " Answer not understood: ${ answer } "
fi
done
2015-05-31 02:16:06 -04:00
echoerr;
2015-05-31 16:07:49 -04:00
if ! ( ( $testmode ) ) ; then
echo $dotlink
fi
2015-05-31 02:16:06 -04:00
echoerr
echoerr "The below are the actions that will be taken to setup DotBot."
2015-05-31 16:07:49 -04:00
if ( ( $testmode ) ) ; then
echoerr "Just kidding. They won't be."
fi
2015-05-31 02:06:00 -04:00
echoerr $setupshell
read -p "If you do not see a problem with the above commands, press enter. This is your last chance to press ^C before actions are taken that should not be interrupted. "
2015-05-31 16:07:49 -04:00
if ! ( ( $testmode ) ) ; then
eval $setupshell
fi