-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdotfiles.py
More file actions
executable file
·37 lines (29 loc) · 983 Bytes
/
dotfiles.py
File metadata and controls
executable file
·37 lines (29 loc) · 983 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python3
import argparse
import os
from pathlib import Path
import sys
prog = 'dotfiles.py'
description = 'Links or unlinks dotfiles for an app using GNU Stow.'
def parse_args():
parser = argparse.ArgumentParser(prog=prog, description=description)
parser.add_argument('-D', '--delete')
parser.add_argument('command', choices=['link', 'unlink'])
parser.add_argument('app')
return parser.parse_args()
def target_directory(args):
home = Path.home()
if args.app == 'sublime-text':
if sys.platform == 'darwin':
return home / 'Library' / 'Application Support' / 'Sublime Text'
else:
return home / '.config' / 'sublime-text'
else:
return Path.home()
if __name__ == '__main__':
args = parse_args()
target = target_directory(args)
stow_args = ['stow', args.app, '-t', str(target)]
if args.command == 'unlink':
stow_args.append('-D')
os.execvp('stow', stow_args)