Skip to content

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 9 commits into from
May 19, 2025
Merged

Support bash tab completion #535

merged 9 commits into from
May 19, 2025

Conversation

pvdz
Copy link
Collaborator

@pvdz pvdz commented May 9, 2025

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 or sd 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

  • Need to verify how to export the .bash file properly and make sure it's working as epected

@pvdz pvdz marked this pull request as ready for review May 19, 2025 10:35
@pvdz pvdz requested a review from jdalton May 19, 2025 10:38
@jdalton jdalton changed the title Support bash tab completi Support bash tab completion May 19, 2025
Copy link
Collaborator

@jdalton jdalton left a 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.

@pvdz pvdz merged commit c3a1e17 into main May 19, 2025
14 checks passed
@pvdz pvdz deleted the bash_comple branch May 19, 2025 11:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants