Skip to content

Commit

Permalink
Fix multiple command registration for non-bash shells (#293)
Browse files Browse the repository at this point in the history
  • Loading branch information
evanunderscore authored Mar 19, 2020
1 parent 2d5f767 commit e43a7b6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
11 changes: 7 additions & 4 deletions argcomplete/shell_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ def shellcode(executables, use_defaults=True, shell='bash', complete_arguments=N
:param str shell: Name of the shell to output code for (bash or tcsh)
:param complete_arguments: Arguments to call complete with
:type complete_arguments: list(str) or None
:param argcomplete_script: Script to call complete with
:param argcomplete_script: Script to call complete with, if not the executable to complete.
If supplied, will be used to complete *all* passed executables.
:type argcomplete_script: str or None
'''

Expand All @@ -92,8 +93,10 @@ def shellcode(executables, use_defaults=True, shell='bash', complete_arguments=N
else:
code = ""
for executable in executables:
if not argcomplete_script:
argcomplete_script = executable
code += shell_codes.get(shell, '') % dict(executable=executable, argcomplete_script=argcomplete_script)
script = argcomplete_script
# If no script was specified, default to the executable being completed.
if not script:
script = executable
code += shell_codes.get(shell, '') % dict(executable=executable, argcomplete_script=script)

return code
12 changes: 9 additions & 3 deletions test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1129,7 +1129,9 @@ class TestBash(_TestSh, unittest.TestCase):
# This requires compopt which is not available in 3.x.
expected_failures.append('test_quoted_exact')

install_cmd = 'eval "$(register-python-argcomplete prog)"'
# 'dummy' argument unused; checks multi-command registration works
# by passing 'prog' as the second argument.
install_cmd = 'eval "$(register-python-argcomplete dummy prog)"'

def setUp(self):
sh = pexpect.replwrap.bash()
Expand Down Expand Up @@ -1244,7 +1246,9 @@ def setUp(self):
path = ' '.join([os.path.join(BASE_DIR, 'scripts'), TEST_DIR, '$path'])
sh.run_command('set path = ({0})'.format(path))
sh.run_command('setenv PYTHONPATH {0}'.format(BASE_DIR))
output = sh.run_command('eval `register-python-argcomplete --shell tcsh prog`')
# 'dummy' argument unused; checks multi-command registration works
# by passing 'prog' as the second argument.
output = sh.run_command('eval `register-python-argcomplete --shell tcsh dummy prog`')
self.assertEqual(output, '')
self.sh = sh

Expand Down Expand Up @@ -1277,7 +1281,9 @@ def setUp(self):
path = ' '.join([os.path.join(BASE_DIR, 'scripts'), TEST_DIR, '$PATH'])
sh.run_command('set -x PATH {0}'.format(path))
sh.run_command('set -x PYTHONPATH {0}'.format(BASE_DIR))
output = sh.run_command('register-python-argcomplete --shell fish prog | .')
# 'dummy' argument unused; checks multi-command registration works
# by passing 'prog' as the second argument.
output = sh.run_command('register-python-argcomplete --shell fish dummy prog | .')
self.assertEqual(output, '')
self.sh = sh

Expand Down

0 comments on commit e43a7b6

Please sign in to comment.