Created
November 8, 2018 08:30
-
-
Save rondreas/16ced384a160ab1cf5c3fc0d603e5acc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Script to create symbolic links for vimfiles, allowing user download dotfiles | |
to any location. | |
$ python ~/Downloads/foo/makelinks.py | |
Symlink Created for: '/home/user/GitHub/foo/vim/.vim' -> '/home/user/.vim' | |
Symlink Created for: '/home/user/GitHub/foo/vim/.vimrc' -> '/home/user/.vimrc' | |
Symlink Created for: '/home/user/GitHub/foo/vim/.gvimrc' -> '/home/user/.gvimrc' | |
""" | |
import os | |
import sys | |
def get_targets(): | |
""" Get paths for files in subfolder 'vim'. """ | |
# The path to current script | |
base = os.path.dirname(sys.argv[0]) | |
# Join base with subfolder vim | |
vim = os.path.join(base, 'vim') | |
# Return all absolute filepaths for files inside vim folder | |
return [os.path.abspath(os.path.join(vim, f)) for f in os.listdir(vim)] | |
def symlink(targets): | |
""" Create a symlink for each file in vimfolder at user home. """ | |
user_home = os.path.expanduser('~') | |
for t in targets: | |
# Get filename at path t, and join user home with file. | |
dst = os.path.abspath(os.path.join(user_home, os.path.split(t)[1])) | |
src = os.path.abspath(t) | |
try: | |
os.symlink(src, dst) | |
print("Symlink Created for: '{}' -> '{}'".format(src, dst)) | |
except Exception as e: | |
print("Failed to create symlink: '{}' -> '{}'".format(src, dst)) | |
raise | |
if __name__ == "__main__": | |
targets = get_targets() | |
symlink(targets) |
Author
rondreas
commented
Nov 8, 2018
- Replace dot with underscores for windows
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment