neperfepx / neper

Polycrystal generation and meshing
http://neper.info
GNU General Public License v3.0
205 stars 53 forks source link

Added bash completion support #378

Closed xshang93 closed 2 years ago

xshang93 commented 2 years ago

Hey Romain,

Sorry for the delay, but I have now finished cleaning my repo, and fixed some minor issues with the completion code. The new pull request should now work.

Best, Xiao

rquey commented 2 years ago

Thanks @xshang93. I've now integrated it in the CMakeLists.txt, see branch xshang93-main.

make install works on Linux, but could you confirm that it does on Mac?

First, run

sudo make install

which will copy the file to /usr/local/etc/bash_completion.d/ and rename it neper.

Then, open a new terminal, and type neper <tab>.

Does it autocomplete?

xshang93 commented 2 years ago

Does it autocomplete?

There seems to something wrong with the CMakeLists.txt. Specifically, elseif (compare MATCHES CMAKE_SYSTEM_NAME "Darwin" OR APPLE) gives:

CMake Error at CMakeLists.txt:213 (elseif):
  given arguments:

    "compare" "MATCHES" "CMAKE_SYSTEM_NAME" "Darwin" "OR" "APPLE"

  Unknown arguments specified

Seems like the way you use compare is not working? I changed it to elseif (CMAKE_SYSTEM_NAME MATCHES APPLE OR CMAKE_SYSTEM_NAME MATCHES "Darwin") and it works fine. After installation it autocompletes without a problem.

rquey commented 2 years ago

Thanks. Can you check that the simpler elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin") works?

xshang93 commented 2 years ago

Thanks. Can you check that the simpler elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin") works?

Yes this simple line works.

rquey commented 2 years ago

@xshang93, I've merged this morning. Thanks again!

I'm just noticing two things:

  1. the first -<tab> does not behave as the next ones. Specifically,

    • neper -T -<tab> completes to neper -T -loadtess
    • neper -M -<tab> completes to neper -T -load
    • neper -V -<tab> does not complete
    • neper -S -<tab> does not complete

    I'm guessing that it is considering that the first option should define an input data (hence the -load options), but, as Neper accepts options to be provided in any order, this should not be... Instead, it should show all possible options.

  2. when <tab> is hit at the end of a valid option, then nothing happens, which is also the case when <tab> is hit at the end of an invalid option (compare the valid neper -T -n<tab> and the invalid neper -T -nn<tab>). I find it confusing. In contrast, gcc -ansi<tab> completes to gcc -ansi (a space is added), which "validates" the option.

Would it be possible for you to change this?

PS. Version 4.3.0 is scheduled to be released on Wednesday morning (my time). If you can change this before, then great, otherwise, please inform me of your possibilities or we will fix it later.

xshang93 commented 2 years ago

@xshang93, I've merged this morning. Thanks again!

I'm just noticing two things:

  1. the first -<tab> does not behave as the next ones. Specifically,

    • neper -T -<tab> completes to neper -T -loadtess
    • neper -M -<tab> completes to neper -T -load
    • neper -V -<tab> does not complete
    • neper -S -<tab> does not complete

    I'm guessing that it is considering that the first option should define an input data (hence the -load options), but, as Neper accepts options to be provided in any order, this should not be... Instead, it should show all possible options.

Yes, you're right on this. This was done intentionally because of the reason you mention. I think a better approach would be, when the previous word is a command, i.e., -*, it shows the files/directories and the -load options. I will look into this.

  1. when <tab> is hit at the end of a valid option, then nothing happens, which is also the case when <tab> is hit at the end of an invalid option (compare the valid neper -T -n<tab> and the invalid neper -T -nn<tab>). I find it confusing. In contrast, gcc -ansi<tab> completes to gcc -ansi (a space is added), which "validates" the option.

Would it be possible for you to change this?

This happens because I disabled the "add a space" option in bash-completion for neper. The reason is that, neper takes ',' as separators for multiple file names. If a space is added to the end, completion will not work when there is a comma separator.

PS. Version 4.3.0 is scheduled to be released on Wednesday morning (my time). If you can change this before, then great, otherwise, please inform me of your possibilities or we will fix it later.

I'm glad to hear the new release is arriving! I might be unfortunately too busy for the week, but I will try my best to work on a fix for the first issue - hopefully.

xshang93 commented 2 years ago

Hey @rquey , sorry I didn't have time to work on this recently, thought I'd let you know so you don't need to wait on this. I'll try work on it later this week.

rquey commented 2 years ago

Thanks for letting me know, and no problem.