Files
dotfiles/install_files.py

46 lines
1.2 KiB
Python
Raw Normal View History

2015-12-04 04:31:17 +01:00
#! /usr/bin/env python3
import os
import sys
from pathlib import Path
from subprocess import check_call
import shutil
2015-12-04 12:16:49 +01:00
2015-12-04 04:31:17 +01:00
def install_vim(pdotfiles, force=False):
phome = Path(os.path.expanduser("~")).resolve()
phome_vimrc = phome / Path(".vimrc")
2015-12-04 12:16:49 +01:00
2015-12-04 10:34:12 +01:00
prelvimrc = Path("vim/vimrc")
2015-12-04 12:16:49 +01:00
2015-12-04 04:31:17 +01:00
try:
2015-12-04 10:34:12 +01:00
pdotfiles_vimrc = pdotfiles.resolve().relative_to(phome.resolve()) / prelvimrc
2015-12-04 04:31:17 +01:00
except ValueError:
2015-12-04 10:34:12 +01:00
pdotfiles_vimrc = pdotfiles / prelvimrc
2015-12-04 04:31:17 +01:00
2015-12-04 10:34:12 +01:00
if force and phome_vimrc.is_symlink():
2015-12-04 12:16:49 +01:00
phome_vimrc.unlink() # only kill symlinks
2015-12-04 04:31:17 +01:00
if phome_vimrc.exists():
2015-12-04 10:34:12 +01:00
print('.vimrc already there!')
2015-12-04 04:31:17 +01:00
else:
print("Symlinking {} to {}".format(phome_vimrc, pdotfiles_vimrc))
phome_vimrc.symlink_to(pdotfiles_vimrc)
2015-12-04 12:16:49 +01:00
# vundle
2015-12-04 04:31:17 +01:00
pvundle = phome / Path(".vim/bundle/Vundle.vim")
2015-12-04 12:16:49 +01:00
2015-12-04 04:31:17 +01:00
if not force and pvundle.exists():
print("Vundle already installed?")
else:
if force and pvundle.exists():
2015-12-04 12:16:49 +01:00
shutil.rmtree(pvundle.as_posix())
2015-12-04 04:31:17 +01:00
print("Install Vundle")
2015-12-04 12:16:49 +01:00
check_call(
["git", "clone", "https://github.com/VundleVim/Vundle.vim.git",
pvundle.as_posix()])
2015-12-04 04:31:17 +01:00
if __name__ == "__main__":
if len(sys.argv) == 2:
install_vim(Path(sys.argv[1]))