Skip to content
This repository has been archived by the owner on Aug 11, 2023. It is now read-only.

Commit

Permalink
Add direnv config to .bashrc
Browse files Browse the repository at this point in the history
  • Loading branch information
constrict0r committed Nov 28, 2018
1 parent e88675e commit d3c7fb6
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions amanita/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

"""Creates customizable projects"""
import os
import pathlib
import sys
import subprocess

Expand Down Expand Up @@ -143,8 +144,32 @@ def direnv_setup(path, venv_path):
direnv_file.close()

click.echo('Created direnv configuration ' +
click.style('.venv', fg='green') + ' in ' +
click.style(path, fg='blue'))
click.style('.envrc', fg='green') + ' in ' +
click.style(path, fg='blue'))

# Configure ~/.bashrc if not already configured for direnv.
home = str(pathlib.Path.home())
bashrc = open(os.path.join(home, '.bashrc'), 'r')
bashrc_lines = bashrc.readlines()
bashrc.close()

found = False
for line in bashrc_lines:
if 'direnv' in line:
found = True

if not found:
bashrc = open(os.path.join(home, '.bashrc'), 'a')
bashrc.write('eval "$(direnv hook bash)"')
bashrc.close()

click.echo('Added direnv configuration to ' +
click.style('~/.bashrc', fg='green'))

click.echo('You must run: ' +
click.style('source ~/.bashrc ', fg='yellow') +
click.style('or restart session ', fg='green') +
'to activate it')

try:
assert subprocess.call('dpkg-query -l direnv',
Expand Down

0 comments on commit d3c7fb6

Please sign in to comment.