Update setup.sh to newer shell scripting standards; remove stale or broken dotfile symlinks from ~
This commit is contained in:
parent
ae71d58f19
commit
ceba39daf6
1 changed files with 59 additions and 24 deletions
81
setup.sh
81
setup.sh
|
@ -3,17 +3,18 @@
|
||||||
dfdir=$(cd "$(dirname "$0")" && pwd)
|
dfdir=$(cd "$(dirname "$0")" && pwd)
|
||||||
sys=`uname -s | tr A-Z a-z`
|
sys=`uname -s | tr A-Z a-z`
|
||||||
|
|
||||||
skipitems=(setup.sh README.md py bin Colors LaunchAgents)
|
skipitems=(setup.sh README.md py Colors LaunchAgents)
|
||||||
|
|
||||||
typeset -A vimbundles
|
typeset -A vimbundles
|
||||||
vimbundles=(Vundle.vim "https://github.com/gmarik/Vundle.vim.git")
|
vimbundles=(Vundle.vim "https://github.com/gmarik/Vundle.vim.git")
|
||||||
|
|
||||||
|
function link {
|
||||||
function link
|
local action
|
||||||
{
|
|
||||||
local dest
|
local dest
|
||||||
if [[ "$2" == '' ]]; then
|
|
||||||
dest="$HOME/.$dotfile"
|
if [[ -z $2 ]]; then
|
||||||
|
local dotfile_basename=`basename "$1"`
|
||||||
|
dest="$HOME/.$dotfile_basename"
|
||||||
else
|
else
|
||||||
dest="$2"
|
dest="$2"
|
||||||
fi
|
fi
|
||||||
|
@ -24,26 +25,67 @@ function link
|
||||||
else
|
else
|
||||||
action='Skipping'
|
action='Skipping'
|
||||||
fi
|
fi
|
||||||
printf " %8s: %s\n" $action $dest
|
|
||||||
|
printf " %8s: %s\n" $action "$dest"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print -P "%B Home:%b $HOME"
|
||||||
|
print -P "%BDotfiles:%b $dfdir\n"
|
||||||
|
|
||||||
print -P "%BSymlinking config files%b"
|
print -P "%BRemoving stray dotfile symlinks from $HOME%b"
|
||||||
for dotfile in `ls $dfdir`; do
|
local link_dest
|
||||||
[[ ${skipitems[(r)$dotfile]} == $dotfile ]] && continue
|
local link_dirname
|
||||||
link "$dfdir/$dotfile"
|
local did_remove_at_least_one_symlink=0
|
||||||
|
for file in ~/.?*; do
|
||||||
|
link_dest=`readlink "$file"`
|
||||||
|
if [[ $? -ne 0 ]]; then
|
||||||
|
# Not a symlink.
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
link_dirname=`dirname "$link_dest"`
|
||||||
|
if [[ "$link_dirname" != "$dfdir" ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -e "$link_dest" ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf " Removing: %s\n" "$file"
|
||||||
|
rm "$file"
|
||||||
|
did_remove_at_least_one_symlink=1
|
||||||
done
|
done
|
||||||
|
|
||||||
link "$dfdir/bin" "$HOME/bin"
|
if [[ $did_remove_at_least_one_symlink -ne 1 ]]; then
|
||||||
|
print " Nothing to remove"
|
||||||
|
fi
|
||||||
|
|
||||||
echo "touch $HOME/.hushlogin"
|
print -P "%BSymlinking config files%b"
|
||||||
touch "$HOME/.hushlogin"
|
local dotfile
|
||||||
|
local did_link_at_least_one_dotfile=0
|
||||||
|
for dotfile in $dfdir/*; do
|
||||||
|
if [[ ${skipitems[(r)$dotfile]} == $dotfile ]]; then
|
||||||
|
continue
|
||||||
|
fi
|
||||||
|
link "$dotfile"
|
||||||
|
did_link_at_least_one_dotfile=1
|
||||||
|
done
|
||||||
|
|
||||||
|
if [[ -f "$HOME/.hushlogin" ]]; then
|
||||||
|
print " touch $HOME/.hushlogin"
|
||||||
|
touch "$HOME/.hushlogin"
|
||||||
|
did_link_at_least_one_dotfile=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ $did_link_at_least_one_dotfile -ne 1 ]]; then
|
||||||
|
print " Nothing to link"
|
||||||
|
fi
|
||||||
|
|
||||||
# Initialize submodules
|
|
||||||
print -P "%BFetching Vim modules%b"
|
print -P "%BFetching Vim modules%b"
|
||||||
cd "$dfdir/vim/bundle"
|
cd "$dfdir/vim/bundle"
|
||||||
for module in ${(k)vimbundles}; do
|
for module in ${(k)vimbundles}; do
|
||||||
echo -n " $module"
|
print -n " $module"
|
||||||
|
|
||||||
if [[ -d $module ]]; then
|
if [[ -d $module ]]; then
|
||||||
# result='skipped'
|
# result='skipped'
|
||||||
|
@ -71,11 +113,4 @@ done
|
||||||
|
|
||||||
vim +PluginInstall +qall
|
vim +PluginInstall +qall
|
||||||
|
|
||||||
#if [[ -d "$dfdir/vim/bundle/command-t/ruby/command-t" ]]; then
|
|
||||||
# print -P "%BSetting up command-t%b"
|
|
||||||
# cd "$dfdir/vim/bundle/command-t/ruby/command-t"
|
|
||||||
# ruby extconf.rb
|
|
||||||
# make
|
|
||||||
#fi
|
|
||||||
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue