SWT: quick way of finding out whether a shell has child shells - swt

I could iterate over all shells reported by display.getShells() and check their parents. Is there an alternative to find out whether a shell has child shells (or get all child shells)?

Shell.getShells() should show you all descendant shells. Is it not working?

Related

Remove preset binding in fish shell

I am unable to remove the default binding in Fish shell for CTRL + p.
I want to activate separate "background" app outside of the terminal using the CTRL+P shortcut.
I have tried:
bind --erase \cp up-or-search
However the binding remains. How can I remove the preset bindings? The documentation does not mention it.
I want this shortcut to propagate up to the parent process rather than Fish swallowing it and reacting to it.
That's not how it works.
If by "parent process" you mean the terminal, that gets first dibs on every key. It gets to decide what is passed on and what isn't.
If by "parent process" you mean an in-terminal process that started fish: That typically stays in the background and doesn't read any keys at all.
And fish will (and has to) read all input it receives, even if it then decides to do nothing. Reading it is how it finds out what it has to do, and it cannot stuff the input back.
And the terminal has no idea what the processes running inside it have bound or not, so it also can't decide to send keys that it knows the shell will do something with and keep others for itself.
Your mental model is incorrect.
How can I remove the preset bindings?
To erase a preset binding, you could run
bind --erase --preset \cp
However, you would have to arrange for that to be run after the binding has actually been set up. You might want to store it in a function called fish_user_key_bindings. Fish runs that after it sets up the bindings, whenever it does it (e.g. if you switch to vi-mode it'll rerun it).
Typically to disable a binding you would rather make your own that does nothing, like
bind \cp true
Not that this would help what you want to do, see above.

Is there a way to count the number of times a command is called during zsh startup?

I was reading through the answer to a related question on SO here and the answer mentioned:
Nope, that's not what your script should be doing. Not your script, but the user should call compinit in their .zshrc file to enable Zsh's completion system. Additionally, it should be called only once for each shell instance.
I'm curious if it is possible to count the number of times that compinit or bashcompinit is being called during zsh startup?
Thanks.
Yes, the zprof module makes this pretty easy: add zmodload zsh/zprof to the top of ~/.zshenv and run zprof once the shell starts up (maybe pipe to grep compinit too). It will list all the functions that were called since the module was loaded, with the number of calls and time they took. See its section in zshmodules(1) for more details.
~/.zshenv will be read immediately after /etc/zshenv, and before anything else. There shouldn't be any compinit calls in /etc/zshenv, since it's also read for non-interactive invocations of zsh like zsh -c ....

How do you disable fish shell's guessing autocompletion feature?

In bash, if you type something like:
ls /etc/abc
and hit <tab>, it will beep, and do nothing, basically letting you know that it couldn't figure out how to complete it. In the case of that specific command, a file starting with /etc/abc didn't exist.
In fish, it will use some sophisticated algorithm to figure out what it thinks you may have meant, and can change what you typed completely, possible changing your ls /etc/abc to ls /etc/fstab, because at some point in the past, you may have typed ls /etc/fstab.
I'm sure it's not that arbitrary, but the fact is, it removed my /etc/abc arg, and replaced it with what it thought I meant. Sometimes, I made one mistake in one character, and instead of going back and fixing my mistake like I would in bash, hitting <tab> replaced the entire thing I wrote, forcing me to rewrite the entire arg.
I can see how some people might like this feature, but for me, it's insanely annoying. Maybe I'm just used to bash.
Is there a way to have fish turns this off, so it never replaces what I wrote? If I wrote /etc/abc, hit <tab>, and it can't figure out a completion that starts with that, leave it alone. Don't replace it with its best guess.
I don't even know what the feature is called. Does it even have a name, or is it just a nameless part of the autocompletion of fish?
Update:
A real example I just ran into.
I have a file in the current directory named lib.py. I type git difftool li and hit <tab>. It replaces what I wrote with git difftool templates/nxt_connect/dish_controls.html, immediately making me want to stab somebody as I have to delete the super long string it helpfully filled in for me, and try again. What's worse is that I assume I typed something in wrong, so I'll try exactly the same thing, and end up with exactly the same result, only to realize fish doesn't have a completion file built-in for git difftool, which is why it doesn't even check my current directory for files.
and can change what you typed completely, possible changing your ls /etc/abc to ls /etc/fstab,
Fish won't change /etc/abc to /etc/fstab
What it will do is fuzzy-match your command, so e.g. /etc/ft will match /etc/fstab, but that's only because both "f" and "t" are in "fstab" in that order, and only if it was the only possible match.
This won't happen with /etc/abc, because that doesn't match /etc/fstab.
because at some point in the past, you may have typed ls /etc/fstab.
It does not take history into account in this case. It really only uses history for the autosuggestion - the greyed-out continuation of what you typed, but that only does prefix matching.
Is there a way to have fish turns this off, so it never replaces what I wrote?
Fish provides no option to change this behavior.
The next fish release (version 3.2) will offer an "undo" function (bound to ctrl+z by default) so you can undo any match by pressing that.
is it just a nameless part of the autocompletion of fish?
fuzzy matching.

Enable returning multiple arguments as completion reply at once in fish shell

I am working on porting Google Cloud SDK command line auto completion feature to fish shell. When I have an unambiguous reply with multiple arguments:
A) Either the command is completed with all those arguments BUT spaces gets escaped (\ ) when I specify the function call in the complete command inside ''s or ""s, like: > complete ... -a '(__fun)'
B) or if I don't do that (just: -a (__fun)), then only the first argument of the reply gets into the completion and all the other arguments "get lost"
Is it possible to reply with multiple arguments at once in fish completion?
Could be done in a number of ways. You will have to hack it a bit, though, since as ridiculous_fish says it's not designed for this.
Easiest would be to ship your own wrapper function that can take the escaped output and pass it on in a way that works. Not very pretty, though, and would screw with autosuggestions unless you also go back and modify the history lines.
Here's something semi-hacky/semi-elegant I would propose:
If you have looked up a "sequence" of args you'd want to complete at once, at first invocation put the trailing args as the description to the first one. Once that one has been locked in, remove all other options but the first in this "description queue", keep going through it and it will simply be a matter of quickly pressing tab-tab-tab-tab.
Completions don't have to be perfect, they're mostly a lil help on the way until you have enough history lines that autosuggestions take over, imo.

Is there any way to use some "shortcut" for longer command lines?

I am using the same, longer command line with some arguments every day and it would be nice, if there were some possibility to make some shortcut for it. Is there any?
Learn aliases. Of course they depends of shell you're using. Doskey for cmd, alias for powershell or tcc, and so on.
Also. ConEmu has GuiMacro feature. You may set up user hotkeys with print function.