There are a few ways to go about this, but first, it's important to understand that "completion" is a feature of your Linux shell not of WSL. If you haven't changed it, bash
is most likely your shell, as it is the default in most distributions. Some common alternatives include zsh
and fish
.
While I generally don't "advertise" for my favorite shell in answers, I think it's appropriate in this case since one of the big features in the fish shell is its great out-of-the-box completion, suggestion, and abbreviation system.
As omajid mentioned in the comments, most shells can accomplish what you want to some degree through history search. But regardless of what shell you choose, I'd recommend adding fzf and setting up its shell integration. It can turbo-charge that Ctrl+R history search with an extremely fast pattern search.
You can type npx seq
, hit Ctrl+R, and then filter based on flags that you'd used before. npx seed
with Ctrl+R would show all your commands with npx
and seed
, regardless of where they appear in the commandline.
Even something as simple as seqseed
Ctrl+R would find those lines.
That could handle your "multiple boilerplate" scenario. Again, this can be set up to work in Bash, Zsh, or fish.
But fish also has an out-of-the-box Autosuggestions feature that can help with this. As you type each command, fish will "suggest" a previously typed commandline that you can accept with → or Ctrl+F. Or you can just accept one argument at a time from that previous commandline with Alt+→.
Finally, fish has built-in Abbreviation support that could be used for this workflow:
abbr --add seqgen npx sequelize-cli model:generate --name SingularModelNameHere --attributes attribute1Name:datatype, attribute2Name:dataType
abbr --add seqseed npx sequelize-cli seed:generate --name
Then, typing seqseed
followed by the Spacebar will replace the seqseed
with npx sequelize-cli seed:generate --name
, leaving the cursor at the end where you can add the <descriptiveName>
.
A few other commandline editing tips for this type of work. Some of these are found in other shells:
Key |
Function |
Ctrl+W |
Deletes previous token. Fish is smart enough to use things like / and : as token separators by default, so if you use Ctrl+W after attribute2Name:dataType , it will only remove dataType . |
Ctrl+← and Ctrl+→ |
Skip backward and forward over tokens |
Alt+E or Alt+V |
Edit the current commandline in your preferred $EDITOR . |