Coverage for gpaw/cli/complete.py: 21%
33 statements
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-14 00:18 +0000
« prev ^ index » next coverage.py v7.7.1, created at 2025-07-14 00:18 +0000
1#!/usr/bin/env python3
2"""Bash completion for ase.
4Put this in your .bashrc::
6 complete -o default -C /path/to/gpaw/cli/complete.py gpaw
8or run::
10 $ gpaw completion [-0] [<your-bash-file>]
12"""
14import os
15import sys
16from glob import glob
19def match(word, *suffixes):
20 return [w for w in glob(word + '*')
21 if any(w.endswith(suffix) for suffix in suffixes)]
24# Beginning of computer generated data:
25commands = {
26 'atom':
27 ['-f', '--xc-functional', '-a', '--add', '--spin-polarized', '-d',
28 '--dirac', '-p', '--plot', '-e', '--exponents', '-l',
29 '--logarithmic-derivatives', '-n', '--ngrid', '-R',
30 '--rcut', '-r', '--refine', '-s',
31 '--scalar-relativistic', '-S', '--non-relativistic',
32 '--no-ee-interaction'],
33 'basis':
34 ['--name', '-s', '--search', '-t', '--type', '-E',
35 '--energy-shift', '-T', '--tail-norm', '--rcut-max',
36 '--rcut-pol-rel', '--rchar-pol-rel',
37 '--vconf-amplitude', '--vconf-rstart-rel',
38 '--vconf-sharp-confinement', '--lpol', '--jvalues'],
39 'completion':
40 [],
41 'dataset':
42 ['-f', '--xc-functional', '-C', '--configuration', '-P',
43 '--projectors', '-r', '--radius', '-0',
44 '--zero-potential', '-c',
45 '--pseudo-core-density-radius', '-z', '--pseudize',
46 '-p', '--plot', '-S', '--separate-figures', '-l',
47 '--logarithmic-derivatives', '-w', '--write', '-s',
48 '--scalar-relativistic', '-n', '--no-check', '-t',
49 '--tag', '-a', '--alpha', '-g', '--gamma', '-b',
50 '--create-basis-set', '--nlcc', '--core-hole', '-e',
51 '--electrons', '--ecut', '--ri', '--omega'],
52 'diag':
53 ['-b', '--bands', '-s', '--scalapack'],
54 'dos':
55 ['-p', '--plot', '-i', '--integrated', '-w', '--width', '-a',
56 '--atom', '-t', '--total', '-r', '--range', '-n',
57 '--points', '--soc'],
58 'gpw':
59 ['-w', '--remove-wave-functions'],
60 'info':
61 [],
62 'install-data':
63 ['--version', '--list-all', '--tarball', '--gpaw', '--sg15',
64 '--basis', '--test', '--register', '--no-register'],
65 'plot-basis':
66 ['--write'],
67 'plot-dataset':
68 ['-p', '--potential-components', '-l',
69 '--logarithmic-derivatives', '-s', '--separate-figures',
70 '-S', '--search', '-o', '--outfile', '--write'],
71 'python':
72 ['--dry-run', '-z', '-d', '--debug', '--command', '-c',
73 '--module', '-m'],
74 'run':
75 ['-p', '--parameters', '-t', '--tag', '--properties', '-f',
76 '--maximum-force', '--constrain-tags', '-s',
77 '--maximum-stress', '-E', '--equation-of-state',
78 '--eos-type', '-o', '--output', '--modify', '--after',
79 '--dry-run', '-w', '--write', '-W', '--write-all'],
80 'sbatch':
81 ['-0', '--test'],
82 'symmetry':
83 ['-t', '--tolerance', '-k', '--k-points', '-v', '--verbose', '-s',
84 '--symmorphic'],
85 'test':
86 []}
87# End of computer generated data
90def complete(word, previous, line, point):
91 for w in line[:point - len(word)].strip().split()[1:]:
92 if w[0].isalpha():
93 if w in commands:
94 command = w
95 break
96 else:
97 if word[:1] == '-':
98 return ['-h', '--help', '--version', '-P', '--parallel']
99 return list(commands.keys()) + ['-h', '--help', '--version',
100 '-P', '--parallel']
102 if word[:1] == '-':
103 return commands[command]
105 words = []
107 if command == 'help':
108 words = commands
110 elif command == 'test':
111 from glob import glob
112 path = __file__.rsplit('/', 1)[0] + '/../test/**/*.py'
113 return (word.rsplit('/test/')[-1]
114 for word in glob(path, recursive=True))
116 return words
119if __name__ == '__main__':
120 word, previous = sys.argv[2:]
121 line = os.environ['COMP_LINE']
122 point = int(os.environ['COMP_POINT'])
123 words = complete(word, previous, line, point)
124 for w in words:
125 if w.startswith(word):
126 print(w)