From 09b20d3a0ae067fb24f88db5984d573734d10557 Mon Sep 17 00:00:00 2001 From: nirenjan Date: Thu, 27 Sep 2018 13:48:57 -0700 Subject: [PATCH] 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 --- scripts/smartwd | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/scripts/smartwd b/scripts/smartwd index 47c148b..e60271b 100755 --- a/scripts/smartwd +++ b/scripts/smartwd @@ -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())