-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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
Support bash style alias's to support tab completion in command string aliases #12962
Comments
and if someone add gb alias it shadow your gb function. dont work as expected. |
This is pretty much the first thing people (including myself) try to do with aliases. I've seen countless threads/discord conversations with a ton of folks tripping on this. I'm tempted to say that
|
Really? The first thing you do is to do complex aliasing? An alias is a short cut to a command name only and has been since V1. And in all the years I have moderated the PowerShell forum on Spiceworks this is not a highly requested feature. There have been requests but certainly not many. I'd say this might be a nice to have - but only if the implementation does not break things. |
If we pull on this string a bit:
Basically, I'd like to understand where the breakdown lies between PowerShell's parser/AST design vs bash's expand and execute approach. Once we have a better understanding of that, we'll be better placed to evaluate whether this feature is achievable. |
@rjmholt I don't think the parser would need to change. Just the parameter binder and possibly a new For native command argument completers, it might be fine to just expand the text and reparse before invoking them. Kinda dirty, but maybe doable just for completions. |
Yes. People who came from bash/zsh/fish will do this. Take a look at this guide: every single example is complex in the sense that it's a command string and not a particular command.
|
I'm pretty sure the first alias I tried to make way back when was to
Haven't heard of Spiceworks, but I see it a lot on reddit/discord. It's up there with
That's fair, luckily I'm pretty sure breaks won't be needed for it. |
Perhaps a more PowerShelly way to implement this would be to add a parameter like set-alias gc git -parameters commit, "--a"
# OR maybe -Parameters allows a single string with all parameters?
set-alias gc git -parameters "commit --a" |
That would work for many cases, but doesn't handle 'weird' syntax, so you probably still need to have --% for those any way. I like the & --% idea as it reuses the existing operator. |
It would handle it just the same way as you'd need to handle it even if there wasn't a separate You'd probably have to wrap everything in quotes there; you can't directly use |
Another approach is Fish abbreviations. Implementing them might be simpler in terms of auto completion because they work by expanding the alias at the prompt itself. |
Quote from PowerShell/PSReadLine#1753 (comment):
We may consider supporting this in PSReadLine instead of PowerShell engine, so that it stays as an interactive feature only and won't be supported in a script execution. |
@daxian-dbw this means that intellisense in vscode won't get this feature. |
@TylerLeonhardt True, but then PSSA will just turn around and tell you that you shouldn't be using aliases in scripts. 😉 |
I'd like to add, this difference in mindsets comes from the fact that commands in UNIX land (unlike PowerShell) are usually already short enough that you won't need to alias them. So the primary use case indeed is for stacking up some commonly used arguments. This one might as well be my favorite one: alias glola="git log --graph --pretty='%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --all" |
Just want to add a pressing scenario that can't easily implement without aliasing - Ttrying to implement a 'Take top one' function and following would only work functionally but have bad perf.
This brings a performance penalty in the case of pipeline input - if I run More in #15855 on the technical challenge to get parity in function |
"filter" function works more fast. :-) |
reopening as I think there is value in having this in future irrespective of however it gets implemented |
Let me try a summary of sorts: Supporting Bash-style alias definitions would provide the following benefits:
The tab-completion aspect is really an independent one, and for current aliases, which are merely name mappings, already works for PowerShell target commands, but not for external (native) programs.
Given that the proposal at hand also requires the enhanced aliases to know the external executable name, fixing the above asymmetry could also provide tab-completion support for enhanced aliases. |
Summary of the new feature/enhancement
In bash, you can do alias's like so:
which is really useful for typing less.
In PowerShell we can do:
But here's why bash's are so much better:
tab completion still works. Where as for PowerShell they don't.
By not supporting this in some way, it means that alias's to native executables are better in bash because the experience is more fluid.
Also, the function approach that we have means we lose out on the work @rjmholt did in UnixCompleters.
Proposed technical implementation details (optional)
Perhaps a new kind of alias that will funnel tab completion all the way down to the alias'd command string?
The text was updated successfully, but these errors were encountered: