Created
November 13, 2015 00:16
-
-
Save samchrisinger/f1c2f39726742a7ac23e to your computer and use it in GitHub Desktop.
bash autocomplete for OSF invoke tasks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def main(): | |
f = open('tasks.py', 'r') | |
tasks = [] | |
lines = f.read().split('\n') | |
f.close() | |
for i in range(len(lines)): | |
line = lines[i] | |
if '@task' in line: | |
opt = lines[i + 1].replace('def ', '').split('(')[0] | |
tasks.append(opt) | |
templ = open('.invoke_completion_template', 'r').read() | |
templ = templ.replace('__OPTS__', ' '.join(tasks)) | |
out = open('.invoke_completion.sh', 'wb') | |
out.write(templ) | |
out.close() | |
if __name__ == "__main__": | |
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
_invoke () | |
{ | |
local cur prev opts | |
cur="${COMP_WORDS[COMP_CWORD]}" | |
prev="${COMP_WORDS[COMP_CWORD-1]}" | |
opts="__OPTS__" | |
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) | |
return 0 | |
} | |
complete -F _invoke invoke | |
complete -F _invoke inv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This hook is sourced after this virtualenv is activated. | |
cd $OSF_HOME | |
python ./.generate_invoke_completion.py | |
source ./.invoke_completion.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment