nu_scripts/custom-completions
David Danier e4dbec663b
Support whitespace before target name for make completions (#858)
TL;DR: The "simple" example from
https://www.gnu.org/software/make/manual/html_node/Simple-Makefile.html
is currently not compatible with the custom completion script found in
`custom-completions/make/make-completions.nu`. This PR tries to fix
that.

As I was working on `nur` (https://github.com/ddanier/nur) and the
`nurify` script to convert to `nur` from different task runners
(https://github.com/ddanier/nur/blob/main/scripts/nurify.nu) I wanted to
create a good way to convert from using `make`. So I thought the `make`
completion would for sure implement a good way to get a list of all
possible `make` targets. Hence I started looking at
`custom-completions/make/make-completions.nu`.

Then I searched for a good documentation for how `Makefile`s work, as
the last time I was using this myself is about 5 to 10 years ago. If you
for example look at the documentation on gnu.org you may find examples
of `Makefile`s not working with the current autocompletion. See
https://www.gnu.org/software/make/manual/html_node/Simple-Makefile.html
for example, the "simple" example they provide.

The reason for this not working is that the targets use some whitespace
after the target name. This is somehow allowed and thus valid. See
https://www.gnu.org/software/make/manual/html_node/Rule-Introduction.html
for a quick overview about how the `Makefile`s syntax works. I quickly
checked this to ensure `make` actually parses this correctly, it really
does.

This means that the current `make` completion does miss support for the
"simple" example provided my `make` itself. So I went on to fix this.

My suggested solution is:
* Filter all lines by regex `'^[\w\.-]+\s*:'` to ensure possible targets
  - start with some word (also allowing `.` and `-`)
  - may have some whitespaces after the word
  - has ":" after this
* Split by the ":"
* Use first column
* Trim the remaining target name to remove those nasty whitespaces
* Use result for completion

For me this did fix the issue with the "simple" `Makefile`, allowing me
to put this into my `nurify` script.

Would be nice to get this "backported" to nu scripts as well. Might help
others 😉
2024-05-30 14:37:43 -05:00
..
ack Fix non-exported completions (#815) 2024-04-11 18:56:18 -05:00
adb feat: add adb&fastboot completions (#834) 2024-05-10 11:05:44 -05:00
ani-cli fix(completions): clean-up (#484) 2023-05-11 06:08:36 -05:00
as Fix non-exported completions (#815) 2024-04-11 18:56:18 -05:00
auto-generate 🐛 fix more parser errors (#783) 2024-03-15 21:10:27 -05:00
bat add bat completions (#766) 2024-02-28 09:45:46 -06:00
bend feat: add bend completions (#842) 2024-05-22 12:41:01 -05:00
bitwarden-cli fix(completions): clean-up (#484) 2023-05-11 06:08:36 -05:00
btm use typos for corrections (#833) 2024-05-08 06:47:54 -05:00
cargo use typos for corrections (#833) 2024-05-08 06:47:54 -05:00
cargo-make add cargo-make completions (#769) 2024-02-29 14:23:17 -06:00
composer add composer completions (#817) 2024-04-12 21:09:00 -05:00
curl use typos for corrections (#833) 2024-05-08 06:47:54 -05:00
fastboot feat: add adb&fastboot completions (#834) 2024-05-10 11:05:44 -05:00
flutter add flutter completions (#792) 2024-03-15 06:30:31 -05:00
fsharpc 🐛 fix a couple of parser errors (#782) 2024-03-10 14:05:01 -05:00
fsharpi 🐛 fix a couple of parser errors (#782) 2024-03-10 14:05:01 -05:00
gh add gh gist and gh repo list and view (#794) 2024-03-17 07:15:15 -05:00
git feat: git clone completions (#856) 2024-05-28 06:35:27 -05:00
glow fix(completions): clean-up (#484) 2023-05-11 06:08:36 -05:00
godoc 🐛 fix a couple of parser errors (#782) 2024-03-10 14:05:01 -05:00
gradlew feat: add ./gradlew completions (#855) 2024-05-28 06:34:50 -05:00
just fix: update deprecated spread operator in just (#758) 2024-02-10 16:23:30 -06:00
less use typos for corrections (#833) 2024-05-08 06:47:54 -05:00
make Support whitespace before target name for make completions (#858) 2024-05-30 14:37:43 -05:00
man Fix: Completions Broken '-s' flag in man-completions (#619) 2023-09-24 11:05:37 +02:00
mask mask-completions (#631) 2023-10-07 12:26:58 +02:00
mix 🐛 fix more parser errors (#783) 2024-03-15 21:10:27 -05:00
mvn feat: add mvn completion (#819) 2024-04-17 06:38:45 -05:00
mysql 🐛 fix a couple of parser errors (#782) 2024-03-10 14:05:01 -05:00
nano the function to display bars of given percentage from given width (#478) 2023-05-12 09:11:20 -05:00
nix fix(completions): clean-up (#484) 2023-05-11 06:08:36 -05:00
npm fix(completions): clean-up (#484) 2023-05-11 06:08:36 -05:00
op use typos for corrections (#833) 2024-05-08 06:47:54 -05:00
pass use typos for corrections (#833) 2024-05-08 06:47:54 -05:00
pdm feat(completions): add PDM custom completions (#573) 2023-08-09 09:27:17 -05:00
pixi feat: add pixi completions (#755) 2024-02-07 07:21:36 -06:00
pnpm Add pnpm completions (#692) 2023-12-09 10:55:52 -06:00
poetry Add more detailed poetry completions (#838) 2024-05-15 08:35:02 -05:00
reflector use typos for corrections (#833) 2024-05-08 06:47:54 -05:00
rg add rg completions (#767) 2024-02-28 14:14:19 -06:00
rustup 🐛 fix (default) and (installed) on rustup completions (#721) 2023-12-29 08:35:15 -06:00
rye add rye completions (#802) 2024-03-27 18:36:51 -05:00
scoop use typos for corrections (#833) 2024-05-08 06:47:54 -05:00
tar Fix non-exported completions (#815) 2024-04-11 18:56:18 -05:00
tcpdump 🐛 fix more parser errors (#783) 2024-03-15 21:10:27 -05:00
tealdeer fix(completions): clean-up (#484) 2023-05-11 06:08:36 -05:00
toipe add completion for toipe (#508) 2023-05-24 13:02:00 -05:00
typst Fixed the completion of --flamegraph (#502) 2023-05-17 17:34:01 -05:00
virsh use typos for corrections (#833) 2024-05-08 06:47:54 -05:00
vscode code completions (#719) 2023-12-27 08:28:43 -06:00
winget Winget custom completions fixes (#823) 2024-04-23 06:35:10 -05:00
xgettext 🐛 fix a couple of parser errors (#782) 2024-03-10 14:05:01 -05:00
yarn feat(yarn): complete runnables(bin & scripts) (#841) 2024-05-22 06:30:50 -05:00
zef 🐛 fix more parser errors (#783) 2024-03-15 21:10:27 -05:00
zellij use typos for corrections (#833) 2024-05-08 06:47:54 -05:00
README.md 🐛 Fix rustup use completions and modify README (#696) 2023-12-13 16:43:19 -06:00

Custom completions

This current directory provides custom completions. They can be used by importing their exported commands via:

use path/to/<command>/<command>-completions.nu *
# or
source path/to/<command>/<command>-completions.nu
# without the `*` at the end

With path/to/<command> being either the relative path of the file to your current working directory or its absolute path.

Bear in mind that if you import the use <path> *, it is important that you don't name a function with the same name of the file

# file: rustup.nu 

export extern rustup [
    ...args
]

use ./rustup.nu * won't work here