1
0

install.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #! /usr/bin/env python
  2. import os
  3. # Configuration
  4. files = [
  5. 'vimrc',
  6. 'vim/UltiSnips',
  7. 'vim/after/ftplugin'
  8. 'nvimrc',
  9. 'nvim',
  10. 'zshrc',
  11. 'zsh_local_example',
  12. 'ctags',
  13. ]
  14. backup = False
  15. def link_to_home(filename, target_directory='~', hidden=True):
  16. """ Links filename (could be directory) into users home at '~'.
  17. If the file exists, it is backed up first to a file named '*.bak'.
  18. """
  19. source = os.path.join(os.path.dirname(os.path.abspath(__file__)), filename)
  20. target = os.path.expanduser(
  21. os.path.join(target_directory, ('.' if hidden else '') + filename)
  22. )
  23. if os.path.exists(target):
  24. print('{} exists'.format(target))
  25. if backup:
  26. os.rename(target, target + '.bak')
  27. elif os.path.islink(target):
  28. 'target is link'
  29. os.unlink(target)
  30. else:
  31. os.remove(target)
  32. # TODO: Check whether target is composed of directories
  33. # (os.path.commonprefix)
  34. #
  35. # elif os.path.isdir(source):
  36. # os.mkdir(source)
  37. os.symlink(source, target)
  38. for f in files:
  39. link_to_home(f, target_directory='~/test/')