Skip to content

Commit

Permalink
see
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek committed May 13, 2019
1 parent 07b221a commit 8a77ce8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ deps =
pytest
commands =
python setup.py --quiet clean develop
pytest
pytest -s
11 changes: 8 additions & 3 deletions userpath/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def __init__(self, shells=None, all_shells=False, home=None):
shells = DEFAULT_SHELLS

# De-dup and retain order
print(shells)
deduplicated_shells = set()
selected_shells = []
for shell in shells:
Expand All @@ -96,16 +97,19 @@ def detect_shell(cls):
# First, try to see what spawned this process
shell = get_parent_process_name().lower()
if shell in SHELLS:
print('proc')
return shell

# Then, search for environment variables that are known to be set by certain shells
# NOTE: This likely does not work when not directly in the shell
if 'BASH_VERSION' in os.environ:
print('env')
return 'bash'

# Finally, try global environment
shell = os.path.basename(os.environ.get('SHELL', '')).lower()
if shell in SHELLS:
print('global')
return shell

def location_in_new_path(self, location):
Expand All @@ -132,15 +136,16 @@ def put(self, location, front=True, app_name=None):
lines = []

lines.append(
'\n{} Created by `{}` on {}\n'.format(
u'\n{} Created by `{}` on {}\n'.format(
shell.comment_starter, app_name, datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S')
)
)
lines.append('{}\n'.format(contents))
lines.append(u'{}\n'.format(contents))

with open(file, 'w', encoding='utf-8') as f:
f.writelines(lines)
except Exception:
except Exception as e:
print(e)
continue

return self.location_in_new_path(location)
Expand Down

0 comments on commit 8a77ce8

Please sign in to comment.