From 1e4ca4d67ede2e57f5c67de8b656002d42b5f058 Mon Sep 17 00:00:00 2001 From: William Ting Date: Tue, 17 Dec 2013 16:06:27 -0600 Subject: [PATCH] add quotes for bash output --- bin/autojump | 2 +- bin/utils.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/bin/autojump b/bin/autojump index a839e6a..9043a14 100755 --- a/bin/autojump +++ b/bin/autojump @@ -321,7 +321,7 @@ def main(): result = first(find_matches(entriefy(load(config)), args.directory)) if result: - print(encode_local(result.path)) + print(encode_local(surround_quotes(result.path))) else: # always return something so the calling shell function has an # argument to `cd` to diff --git a/bin/utils.py b/bin/utils.py index 5b37b82..6f88750 100644 --- a/bin/utils.py +++ b/bin/utils.py @@ -63,6 +63,10 @@ def has_uppercase(string): return any(unicodedata.category(c) == 'Lu' for c in unicode(string)) +def in_bash(): + return 'bash' in os.getenv('SHELL') + + def is_python2(): return sys.version_info[0] == 2 @@ -115,6 +119,12 @@ def second(xs): return None +def surround_quotes(string): + if in_bash(): + return '"{}"'.format(string) + return string + + def take(n, iterable): """Return first n items of an iterable.""" return islice(iterable, n)