Skip to content

Instantly share code, notes, and snippets.

@hryk
Created September 4, 2010 18:54
Show Gist options
  • Select an option

  • Save hryk/565402 to your computer and use it in GitHub Desktop.

Select an option

Save hryk/565402 to your computer and use it in GitHub Desktop.
vim_setting.sh
#!/bin/sh
## FUNCTIONS
from_url_to_path(){
if [ $# -ne 1 ]; then echo "ArgumentError" && return 1; fi;
dirname=`echo $1 | sed 's/^git:\/\/github.com\/.*\///g' | sed 's/\.git$//g'`;
echo "$VIMSET_TMPDIR/$dirname";
return 0;
};
git_clone(){
if [ $# -ne 1 ]; then echo "ArgumentError" && return 1; fi;
echo "[clone] $1";
cd $VIMSET_TMPDIR && git clone $1;
if [ $? -ne 0 ]; then
echo "Fatal error" && return 1;
fi
return 0;
};
git_pull(){
if [ $# -ne 1 ]; then echo "ArgumentError" && return 1; fi;
echo "[pull] $1";
checkedout_dir=$(from_url_to_path $1);
cd $checkedout_dir && git pull origin master;
return 0;
};
git_export_to_vimdir(){
if [ $# -ne 1 ]; then echo "ArgumentError" && return 1; fi;
checkedout_dir=$(from_url_to_path $1);
if [ ! -d $checkedout_dir ] ; then
git_clone $1;
if [ $? -eq 1 ]; then echo "CheckoutError" && return 1; fi;
else
git_pull $1;
fi
if [ -d $checkedout_dir ] ; then
cd $checkedout_dir && cp -rf * $VIMSET_VIMDIR/;
# cd $VIMSET_VIMDIR && rm -rf .git;
return 0;
else
return 1;
fi
};
vim_dir_clone(){
git clone git://github.com/hryk/vim-dir.git $VIMSET_VIMDIR;
cd $VIMSET_VIMDIR && git submodule init && git submodule update;
if [ $? -ne 0 ]; then return 1; fi;
return 0;
};
vim_dir_init(){
# clone vim-dir
vim_dir_clone;
if [ $? -eq 1 ]; then echo "[error] Failed to clone" && cleanup && return 1; fi;
# Install pathogen
git_export_to_vimdir "git://github.com/tpope/vim-pathogen.git";
if [ $? -eq 1 ]; then echo "[error] Failed to export vimdir" && cleanup && return 1; fi;
# download vimrc
};
vim_dir_update(){
cd $VIMSET_VIMDIR && git pull origin master && git submodule init && git submodule update;
if [ $? -ne 0 ]; then return 1; fi;
return 0;
};
fetch_vimrc(){
curl -o $VIMSET_ROOT/.vimrc "https://gist.github.com/raw/565382/vimrc";
}
cleanup(){
# remove tmp
rm -rf $VIMSET_TMPDIR;
unset VIMSET_VIMDIR;
unset VIMSET_TMPDIR;
unset VIMSET_ROOT;
};
main(){
# ./vim_setting.sh (init|update) [TARGET_DIR]
if [ $# -eq 0 ]; then
echo "./vim_setting.sh (init|update) [TARGET_DIR]";
exit 1;
fi
if [ $1 = 'init' -o $1 = 'update' ];then
command=$1; shift 1;
if [ $# -eq 0 ]; then
export VIMSET_ROOT=$HOME;
else
# For testing purpose.
if [ -d $1 ];then
abs_path=`cd $1; pwd`;
export VIMSET_ROOT=$abs_path;
else
mkdir -p $1;
abs_path=`cd $1; pwd`;
export VIMSET_ROOT=$abs_path;
fi
fi
export VIMSET_VIMDIR="$VIMSET_ROOT/.vim";
export VIMSET_TMPDIR="$VIMSET_ROOT/tmp";
echo "\033[32mSetting up vim configs to $VIMSET_ROOT";
if [ ! -d $VIMSET_ROOT ]; then mkdir -p $VIMSET_ROOT; fi
if [ ! -d $VIMSET_VIMDIR ]; then mkdir -p $VIMSET_VIMDIR ; fi
if [ ! -d $VIMSET_TMPDIR ]; then mkdir -p $VIMSET_TMPDIR ; fi
cd $VIMSET_ROOT;
if [ $command = 'init' ];then
echo "\033[32mInitializing .vim directory...\033[0m";
vim_dir_init;
elif [ $command = 'update' ];then
echo "\033[32mUpdating .vim directory...\033[0m";
vim_dir_update;
fi
if [ $? -eq 0 ]; then
status=0;
echo "\033[32mFetching .vimrc file...\033[0m";
fetch_vimrc;
else
echo "\033[31mAn error occured. Set-up has'nt been completed.\033[0m";
status=1;
fi;
echo "\033[32mCleanup...\033[0m";
cleanup;
if [ $? -eq 0 ]; then
echo "\033[32mComplete!\033[0m";
status=0;
else
status=1;
fi
exit $status;
else
echo "\033[31mAvailable commands are init and update.\033[0m"
fi;
}
main $*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment