mottosso / be

minimal directory and environment management system for collaborative creative projects
GNU Lesser General Public License v2.1
47 stars 4 forks source link

tab completion #14

Closed mottosso closed 9 years ago

mottosso commented 9 years ago

Goal

To enable bash-like tab-completion of topics.

$ be in s[TAB]
spiderman solaris sputnik
$ be in spi[TAB]
$ be in spiderman
$ be in spiderman [TAB]
peter harry greengoblin may maryjane
$ be in spiderman gree[TAB]
$ be in spiderman greengoblin
$ be in spiderman greengoblin [TAB]
rigging animation compositing modeling
$ be in spiderman greengoblin anim[TAB]
$ be in spiderman greengoblin animation[ENTER]

Implemenetion

For linux, bash-completion is a given. On Windows, possibly via clink and Lua.

BigRoy commented 9 years ago

Had a quick go with the basic tab-completion from 13b0d48bd2ecb43c0d06f0e47de5ba555150afb4


The implementation will also list files in the current directory when doing $ be in [TAB]. Since it's a requirement for the project to contain the templates.yaml I assume it wouldn't work with a file at any time. So might be best to only list possible folders?

I assume it's not filtering to only 'valid' folders for optimization, since checking for the required project yaml files would require a lot of disk accessing. Correct?


When tab completing a folder where it's the only folder it will autocomplete including the folder slash, eg:

$ be in th[TAB]
$ be in thedeal/

It's purely cosmetic but it might look nicer if it would complete without the slash. Thoughts?


I've also been wondering whether it would be convenient when tab completion finds a single match and fully completes it to automatically add a space at the end. This tells you it was a full match plus you can directly type the next parameter without pressing the space bar? It's a minimal change, but might feel more natural?

mottosso commented 9 years ago

Hey Roy, tab-completion only works with bash at the moment, and requires you to either source _autocomplete.sh yourself, or type be activate.

Once you've "activated", tab completion will have become enabled. What you're seeing before then is standard directory completion, which is why you're seeing the added slash to the end. With tab completion, you will also be able to continue traversing deeper items, according to the relevant template relative the arguments currently active.

Try be activate, you should get what you're referring to.

There's more about it here: https://gist.github.com/mottosso/275ce5bd69c74e966d6a

Closing the issue as it's complete, but feel free to keep the conversation going.

BigRoy commented 9 years ago

Ah, I missed the activate!

Testing be activate in bash (msys2) gives me an error:

$ be activate
Traceback (most recent call last):
  File "C:\Python27\Scripts\be-script.py", line 9, in <module>
    load_entry_point('be==0.3.4', 'console_scripts', 'be')()
  File "C:\Python27\lib\site-packages\be\vendor\click\core.py", line 664, in __call__
    return self.main(*args, **kwargs)
  File "C:\Python27\lib\site-packages\be\vendor\click\core.py", line 644, in main
    rv = self.invoke(ctx)
  File "C:\Python27\lib\site-packages\be\vendor\click\core.py", line 991, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "C:\Python27\lib\site-packages\be\vendor\click\core.py", line 837, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "C:\Python27\lib\site-packages\be\vendor\click\core.py", line 464, in invoke
    return callback(*args, **kwargs)
  File "C:\Python27\lib\site-packages\be\cli.py", line 517, in activate
    cmd = lib.cmd(parent)
  File "C:\Python27\lib\site-packages\be\lib.py", line 106, in cmd
    raise SystemError("Unsupported shell: %s" % shell_name)
SystemError: Unsupported shell: be
mottosso commented 9 years ago

Yes, the tab completion only works with Bash at the moment, on Windows, I recommend MSYS2. Should work on a clean install.

The error message is a bit unclear though, I'll have a look at that.

BigRoy commented 9 years ago

Some extra information regarding the error message:

mottosso commented 9 years ago

Thanks for this Roy, having a look now.

mottosso commented 9 years ago

Ok, got it. It's a bug in the pip installation logic.

Basically, be activate looks at the parent process of python.exe to determine which shell you are currently using. Typically, the parent is cmd.exe, or bash.exe.

But, because pip install generates a new executable for be, called be.exe, which in turn launches python.exe, then be.exe is deemed the parent process. That's why we're seeing this message.

The reason I'm not seeing it on my development machine is because I'm running python -m be directly, which bypasses the pip generated exe.

Having a look into a solution now.

mottosso commented 9 years ago

Ok, got it. Try updating be.

$ pip install be -U
BigRoy commented 9 years ago

Seems to be working great with MSYS2, sweet!

Though Git Bash (MSYS; Windows 7) is giving me this:

Roy@ROY-PC /e/dropbox/pyblish
$ be activate
C:/Python27/lib/site-packages/be/_shell.sh: line 5: mktemp: command not found
C:/Python27/lib/site-packages/be/_shell.sh: line 6: 1: ambiguous redirect
C:/Python27/lib/site-packages/be/_shell.sh: line 12: 1: ambiguous redirect
C:/Python27/lib/site-packages/be/_shell.sh: line 21: 1: ambiguous redirect
C:/Python27/lib/site-packages/be/_shell.sh: line 24: 1: ambiguous redirect
C:\Program Files (x86)\Git\bin\sh.exe: rcfile: option requires an argument

Roy@ROY-PC /e/dropbox/pyblish
$ be in thedeal ben modeling
C:/Python27/lib/site-packages/be/_shell.sh: line 5: mktemp: command not found
C:/Python27/lib/site-packages/be/_shell.sh: line 6: 1: ambiguous redirect
C:/Python27/lib/site-packages/be/_shell.sh: line 12: 1: ambiguous redirect
C:/Python27/lib/site-packages/be/_shell.sh: line 24: 1: ambiguous redirect
C:\Program Files (x86)\Git\bin\sh.exe: rcfile: option requires an argument
mottosso commented 9 years ago

Yeah, that's expected, MSYS1 isn't supported yet.