-
Notifications
You must be signed in to change notification settings - Fork 149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sub sub commands #37
base: master
Are you sure you want to change the base?
Sub sub commands #37
Conversation
+1 |
3 similar comments
+1 |
👍 |
👍 |
Fixed minor typo in auto-completion file |
I'm running this as several levels of subcommands are an essential feature for me, so thanks! However I have noticed that the sub-sh-* commands do not work beyond the first level. It seems like the init script has to support that somehow, I just don't know how. Any ideas? |
It seems that replacing _cl_wrapper with this makes the sh-commands work in lower levels: _cl_wrapper() {
local pb=$_CL_ROOT/libexec
local cb
local cmd=""
for c in \$@
do
if [[ -d \$pb/cl-\$c ]]; then
pb=\$pb/cl-\$c
cb="\$cb \$c"
shift
elif [[ -f \$pb/cl-sh-\$c ]]; then
cmd="\$cb sh-\$c"
shift
else
echo command cl \$cb "\$@"
command cl \$cb "\$@"
return \$?
fi
if [[ -n \$cmd ]]; then
eval \`cl \$cmd "\$@"\`
return \$?
fi
done
} However it's barely tested. I have forked the repo and will apply your changes to play a bit with them. |
I also noticed that because the loop that build the command stops when it sees -*, if you pass a positional parameter to an inner scripts, it gets swallowed by the sub.
Here cl-case-select only gets |
Hey, Awesome stuff, I will take a look at all of this over the weekend =D |
I also wonder about the rationale for moving completions to sub-command. |
fi | ||
elif [ -n "$nosh" ]; then | ||
if [ ${command:0:3} != "sh-" ]; then | ||
elif [ "$command" == "commands" ] && [ "$command" == "$_SUB_COMMAND_FILE" ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[ "$command" == "commands" ]
That condition can now never be true, since $command is always going to be a path with "/sub-" in it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good call =]
Just for fun, I gave this a go and used a different implementation to support multi level sub commands. My conclusion is that a) it's a mess b) It gets complex enough that it warrants using a more suitable language. So I'm thinking of writing this in python before adding some of the ideas I've had while developing. I won't open a pull request because it makes no sense to me since there is this one already, but you can take a look at it here: https://github.com/jdevera/sub/tree/subsub |
I ended up rewriting the whole thing in python because it got too big for shell scripting. Here it is: https://github.com/jdevera/sub/tree/python in case someone wants to give it a go. I implemented all the default commands internally so I could reuse code and the sub script itself no longer needs to have its guts changed by sed, since it will pick up the sub name from the name of the file itself. I also changed the shell wrapper so that the script itself is responsible for determining if certain command is an 'sh' command or not. I added a ton of logging that can be enabled by running with the SUBDEBUG variable set to something. The direction I'm headed now is to implement what I call "thin subs". The idea is that the sub core lives in one place, and the user's subs live in another, so you can keep the core updated and get the benefits in all your subs, and you don't have to check the core in with your scripts if you don't want to. If anybody wants to give it a go, you are very welcome, remember I haven't yet merged it to master, so you'll need to checkout the "python" branch after cloning. |
Let me know if there is anything I can do, add, remove, etc..
It's solid, give it a test drive, it rocks
Fixes #7
Fixes #12
Fixes #16
Fixes #22
Fixes #27
Example Multi-level autocompletion for --complete: Fixes #7
Nested "sub-sub-commands": Fixes #22
Example Directory and File Structure: Fixes #22
Example For Directory Help Helper File: Fixes #22
Example Help Helper File: Fixes #22
Example Help Display With sub-sub-commands: Fixes #22
Example Multiple Command w/ Completion: Fixes #22 & Fixes #12
Example Multiple Commands and Flags: Fixes #22
Example File Completion: Fixes #16 & Fixes #27