This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
oeed's profile picture

Quick Shell - Advanced Tab Completion

Started by oeed, 28 March 2014 - 09:33 AM
oeed #1
Posted 28 March 2014 - 10:33 AM
As much as I resent using the shell sometimes you just have to. One of the things that I always thought should've been added was tab completion. Now, I am aware that this has been done once or twice before, but none of them really did it well enough and had a few extra things I didn't want. I often find myself wanting to reboot and having to either hold control + R for a second or type in 'reboot', now simply typing 'r', then pressing tab and enter will do it!

This adds tab completion for both program names and arguments. For example, if you type 'mon' then press tab, then type 'le' and press tab then type 'hel' and press tab it will enter: 'monitor left hello', as shown below (I've typed slower so it's obvious, but the speed increase is huge). All vanilla programs (both 1.5 and 1.6) are have their arguments included with a large number (paths, sides, directions, etc) having tab completion. The text that will be inserted is shown in grey, so you know whether you'll get your desired command.

(sorry about the image artefacts, not much I can do about that)


There's really not much more to it. You'll be amazed at how much quicker this makes your day to day use of the shell, I'll probably be including it in the OneOS shell next update too.

Try it out online!
To really experience how useful Quick Shell is you have to use it for yourself. Fortunately, GravityScore & 1lann's emulator allows you to do just that in a matter of seconds.
Simply click here to instantly try it out. (note: due to Mimic's handling of the tab key, sometimes it'll selected the address bar, etc.)

Installation
Now you've seen how quick and easy it is install it!
Simply run:

pastebin get wwVmBJax startup
Then reboot!


Let me know if you find any bugs or have a suggestion.
Edited on 28 March 2014 - 09:35 AM
theoriginalbit #2
Posted 28 March 2014 - 10:42 AM
Very awesome! I quite like the idea of the greyed out suggestions!

Have you considered inverting the black/white with normal computers?
Also have you considered dynamically searching/finding the usage info, that was it supports 3rd party programs as well as vanilla?
Edited on 28 March 2014 - 09:42 AM
oeed #3
Posted 28 March 2014 - 10:54 AM
Very awesome! I quite like the idea of the greyed out suggestions!

Have you considered inverting the black/white with normal computers?
Also have you considered dynamically searching/finding the usage info, that was it supports 3rd party programs as well as vanilla?
Thanks!

With normal computers, as greys don't work (which should IMO) suggestions are black (pretty much hidden). So pressing tab will still work but you can't see suggestions. I can't really think of another way.

I did think about dynamically fetching arguments, but I never got around to attempting. I might try it out later tonight.
Edited on 28 March 2014 - 09:54 AM
GravityScore #4
Posted 28 March 2014 - 11:08 AM
Wow this is epic! Amazing job! This is so freaking coooolll!

Do you mind if I add it to the rom in Mimic? I'd add it under the name quickshell, with the alias qs. I'll include your name under the About section too for credit of course.

EDIT: Feature request: can you make it so when pressing backspace to delete the space after the inserted argument it doesn't delete the argument? Only if you start deleting the text of the argument it will delete it. I encountered the situation where I had a file test and test2, and I typed "rm t", auto completing it to test, when I wanted to delete test2, so I wanted to delete the space to add the 2, but I couldn't.

EDIT EDIT: Love the Mimic try out link as well ;)/>
Edited on 28 March 2014 - 10:12 AM
Wojbie #5
Posted 28 March 2014 - 11:11 AM
I love both how you show tab result in gray and that you included vanilla programs arguments ;p As i am working on my own version of tab-completition for my shell i will shamelessly code my own take on both ideas.
Bomb Bloke #6
Posted 28 March 2014 - 11:15 AM
I've not tested outside of your online link (which appears not to handle non-advanced systems - will have to play with that some more…), and only sorta skimmed your source, but if I've got this correctly a non-advanced computer will currently write suggestions in black text on a black background.

In which case I guess BIT would be suggesting suggestions be written in black text on a white background.
Edited on 28 March 2014 - 10:16 AM
theoriginalbit #7
Posted 28 March 2014 - 11:16 AM
In which case I guess BIT would be suggesting suggestions be written in black text on a white background.
Indeed ;)/>
Wojbie #8
Posted 28 March 2014 - 12:32 PM
Did not test it in real CC but in Web-version you get crash when you type ls and then press tab :D/> 238:attempt to index local args - a nill value
theoriginalbit #9
Posted 28 March 2014 - 12:45 PM
Seems you're also missing aliases like `dir`
oeed #10
Posted 28 March 2014 - 10:16 PM
Wow this is epic! Amazing job! This is so freaking coooolll!

Do you mind if I add it to the rom in Mimic? I'd add it under the name quickshell, with the alias qs. I'll include your name under the About section too for credit of course.

EDIT: Feature request: can you make it so when pressing backspace to delete the space after the inserted argument it doesn't delete the argument? Only if you start deleting the text of the argument it will delete it. I encountered the situation where I had a file test and test2, and I typed "rm t", auto completing it to test, when I wanted to delete test2, so I wanted to delete the space to add the 2, but I couldn't.

EDIT EDIT: Love the Mimic try out link as well ;)/>
Yea, go ahead. Don't add it quite yet as I'm still fixing a few bugs, I'll let you know via PM when it should be good to go.
The backspace-remove entire argument thing is designed to improve speed, essentially if there is a space to the left of the cursor it'll delete the next word. So, I won't remove it, but, all you need to do is move the cursor one to the left so it's flashing where the space is. If you do that then you can remove characters.

I've not tested outside of your online link (which appears not to handle non-advanced systems - will have to play with that some more…), and only sorta skimmed your source, but if I've got this correctly a non-advanced computer will currently write suggestions in black text on a black background.

In which case I guess BIT would be suggesting suggestions be written in black text on a white background.
Oh, I see. Good idea, I'll test that out now.

Did not test it in real CC but in Web-version you get crash when you type ls and then press tab :D/> 238:attempt to index local args - a nill value
I found that bug when I was adding it to the OneOS shell, along with a few other issues. I'll be releasing a bug fix pretty soon to fix that.


Edit: Normal computer suggestions are now black on white, matches are no longer case sensitive, fixed tab on empty text crash and fixed aliases not appearing.
Edited on 28 March 2014 - 09:47 PM
theoriginalbit #11
Posted 28 March 2014 - 11:30 PM
The backspace-remove entire argument thing is designed to improve speed, essentially if there is a space to the left of the cursor it'll delete the next word. So, I won't remove it, but, all you need to do is move the cursor one to the left so it's flashing where the space is. If you do that then you can remove characters.
This is pretty much the only feature I don't agree with, only for the simple fact of lets say I type a really long argument out, hit space and realised that I've made a typo on the last letter, my first instinct is going to be to hit backspace; now I've lost the entire argument and have to type it again!
oeed #12
Posted 28 March 2014 - 11:53 PM
The backspace-remove entire argument thing is designed to improve speed, essentially if there is a space to the left of the cursor it'll delete the next word. So, I won't remove it, but, all you need to do is move the cursor one to the left so it's flashing where the space is. If you do that then you can remove characters.
This is pretty much the only feature I don't agree with, only for the simple fact of lets say I type a really long argument out, hit space and realised that I've made a typo on the last letter, my first instinct is going to be to hit backspace; now I've lost the entire argument and have to type it again!

I know what you mean, I'll see if I can think of an alternative.
awsmazinggenius #13
Posted 29 March 2014 - 03:14 AM
Nice program, I like it. But don't hate the shell, it is very powerful. Of course, I do use (and love) Python scripts to do things such as being given a file and automatically deciding where to put it, but I also use lots of .command (or batch filed when I'm in my PC) files often, too. I also often use the shell in CC, even though I have OneOS installed. If you want to add this to your OS, I would recommend adding an option to turn it off.
McLeopold #14
Posted 29 March 2014 - 03:37 AM
I love for this to be something my programs could hook themselves into. If the program suggestions were read from files in a directory by program name, then my installer could put its own file in there with its suggestions. What do you think?
oeed #15
Posted 29 March 2014 - 04:29 AM
I love for this to be something my programs could hook themselves into. If the program suggestions were read from files in a directory by program name, then my installer could put its own file in there with its suggestions. What do you think?
The main issue is people won't hook their programs in to it. I'm better of searching the program for something like 'Usage:' and stripping it out. In an ideal world everyone would implement that, but they won't.
theoriginalbit #16
Posted 29 March 2014 - 04:30 AM
I'm better of searching the program for something like 'Usage:' and stripping it out.
'Usage: ', 'local usage = ', and 'local function printUsage' would be your best bet imho.
Geforce Fan #17
Posted 11 June 2014 - 08:26 PM
To be honest, I really don't like the autocompletes and all the wild stuff in quick shell. I'd rather just have my plain shell, giving me access to everything and not trying to complete my sentances.
see what I did there?
Edited on 11 June 2014 - 06:30 PM
Yevano #18
Posted 11 June 2014 - 11:12 PM
http://www.urbandictionary.com/define.php?term=sentance

This is neat, btw. Was surprised autocomplete wasn't added in 1.6 when dan added wildcards.
Geforce Fan #19
Posted 12 June 2014 - 07:44 PM
the reason why this would be annoying is let's say you did this: monitor left run programs then hit enter it'd run programs rather than "prog" that you might have wanted to run.
Wojbie #20
Posted 12 June 2014 - 08:22 PM
Thats why most auto-completes use magic key like "tab" as confirmation that you want it to autocomplete. So like "prog"+tab+enter=programs or "prog"+enter = prog. That way user gets extra functionality but looses nothing.

Yes i am talking about my auto-complete shell here ;p ink below.
Anavrins #21
Posted 12 June 2014 - 08:41 PM
I've got a little bug, I'm using CC 1.63.
When trying to tab complete something without a grayed suggestion, it errors with "startup:246: attempt to index ? (a nil value)"
The line in question is "sMatch = match(tWords[#tWords], args[#tWords-1])"
Yevano #22
Posted 13 June 2014 - 04:15 PM
the reason why this would be annoying is let's say you did this: monitor left run programs then hit enter it'd run programs rather than "prog" that you might have wanted to run.

I may be mistaken, but I don't think it autocompletes until you press tab, so pressing enter would just enter whatever is currently there, regardless of the autocomplete suggestion.
civilwargeeky #23
Posted 17 June 2014 - 03:07 AM
First, I am so glad I found this program, its awesome :)/>

However, I do agree that backspace shouldn't remove the last word. If you could make it so that backspace only removes the last character, that would be awesome.

Edit: Actually, I propose a system. When you hit tab for an autocomplete, it doesn't add a space in at the end, now, you can hit tab again to select another one of the options, or hit space to start with the arguments. So say I have files abc, abd, and abh. When I type "ab" and tab, it comes up with "abc", now if I hit tab again, it cycles to "abd" then "abh", and back to "abc". This is helpful if you have multiple files with similar starts.
Edited on 17 June 2014 - 01:12 AM