Skip to content

Instantly share code, notes, and snippets.

@samchrisinger
Created November 13, 2015 00:16
Show Gist options
  • Save samchrisinger/f1c2f39726742a7ac23e to your computer and use it in GitHub Desktop.
Save samchrisinger/f1c2f39726742a7ac23e to your computer and use it in GitHub Desktop.
bash autocomplete for OSF invoke tasks
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()
#!/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
#!/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