Update smartwd to be compatible with Python 3

Prior to this change, running smartwd in a virtualenv with Python 3 gave
a syntax error due to the script treating `print` as a keyword, rather
than a function.

This change fixes the print to work as a function, and also cleans up
some of the comments and code to better comply with PEP8
master
nirenjan 2018-09-27 13:48:57 -07:00
parent 65fb291da3
commit 09b20d3a0a
1 changed files with 6 additions and 4 deletions

View File

@ -1,7 +1,8 @@
#!/usr/bin/env python
# Script to smartly chop off portions of the current working directory for
# use in the shell prompt
"""Script to smartly chop off portions of the current working directory for
use in the shell prompt"""
from __future__ import print_function
import os
# Constants used to decide when to start chopping
@ -11,6 +12,7 @@ DIR_R = 2
PWDLEN = 14
def smartwd():
"""Meat of the smartwd script"""
username = os.environ['USER']
homedir = os.environ['HOME']
pwd = os.environ['PWD']
@ -29,7 +31,7 @@ def smartwd():
if username_index is not None:
prefix = '/'.join(path[:username_index+1])
if prefix == homedir :
if prefix == homedir:
pre_path = '~'
else:
# The first element is always the empty string.
@ -53,5 +55,5 @@ def smartwd():
return pwd
if __name__ == "__main__":
print smartwd()
print(smartwd())