-
Notifications
You must be signed in to change notification settings - Fork 25
Support bash tab completion #535
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
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… not set it up if it does not exist
Topher68chris
approved these changes
May 14, 2025
jdalton
reviewed
May 19, 2025
jdalton
reviewed
May 19, 2025
jdalton
approved these changes
May 19, 2025
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.
Minor nits but okay.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This enables tab completion for the socket CLI in bash.
Setting up tab completion involves registering a script with bash. This has to be done time and again every time bash starts (eg. when you open a new terminal).
The command is tightly bound so you have to specify it for
socket
but also for./sd
orsd
separately.We cannot apply it the current shell, meaning that after running
socket install completion
you still have to either restart the shell, source the bashrc, or run the install stuff manually. That's a limitation that I don't think we can feasibly overcome, unfortunately (seems there are ways but they are arcane and will severely hinder our development).This PR adds two new commands:
socket install completion
socket uninstall completion
They will attempt to setup tab completion for "socket", you can pass in an argument to have it apply the completion to a different name. For development, for example, we can
socket install ./sd
which will be very helpful for dev. It shares the same completion script as prod, though. But that should be ok.The install script will copy a bash script with the completion details to the config folder and it will modify the
.bashrc
file to source this script and actually enable the tab completion. Whenever you npm install socket, the completion script is updated with the one that shipped for that version.The tab completion script is not dynamically populated, this turned out to be a bit of a nightmare. For now we'll have to manually keep it in sync.
Tab completion will first try to complete to a full (sub) command as far as it can. When it reaches a leaf it will start to suggest flags. If you start typing a dash (
-
) then it will immediately suggest flags. It's a "dumb" script, just follows a hardcoded data structure.I did not auto-install this in our postinstall hook because I don't think it's cool to modify someone's bashrc on a whim. It will check if the .bash file exists in your config folder and update it if it exists. This should suffice because the actual alias being registered is handled through .bashrc and they point to the same script. This does not require any user facing modification so should be fine, even if not actually used.
For the time being the feature is hidden and during login only asked for in v1 testing mode.
We'll have to followup with fish and vsh later
TODO