Skip to content

Instantly share code, notes, and snippets.

@romanofski
Created March 5, 2013 03:18
Show Gist options
  • Save romanofski/5087721 to your computer and use it in GitHub Desktop.
Save romanofski/5087721 to your computer and use it in GitHub Desktop.
link a project folder
#!/usr/bin/env python
# Manages links to a project directory
import optparse
import os.path
import sys
DEFAULTHOME = os.path.join(os.environ['HOME'], 'projects')
def main():
parser = optparse.OptionParser()
parser.add_option(
"-c", "--create", dest="create",
type='string',
help="Create a link")
(options, args) = parser.parse_args()
if not os.path.exists(DEFAULTHOME):
parser.error("Directory to create links does not exist: {}".format(
DEFAULTHOME))
if options.create:
path = os.path.join(DEFAULTHOME, options.create)
projectname = os.path.basename(options.create)
if projectname in os.listdir(DEFAULTHOME):
print("Provided path already exists: {}".format(path))
sys.exit(1)
linkname = os.path.join(os.getcwd(), projectname)
os.symlink(linkname, path)
print("{} created.".format(path))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment