GNU Astronomy Utilities - Tasks: task #15799, Add the autocomplete feature to...
You are not allowed to post comments on this tracker with your current authentication level.
task #15799: Add the autocomplete feature to gnuastro
Submitter: | Pedram Ashofteh-Ardakani <pedram> | ||
Submitted: | Sun 25 Oct 2020 04:00:53 PM UTC | ||
Should Start On: | Sun 25 Oct 2020 12:00:00 AM UTC | Should be Finished on: | Sun 25 Oct 2020 12:00:00 AM UTC |
Category: | Development | Priority: | 5 - Normal |
Item Group: | New feature | Status: | None |
Privacy: | Public | Percent Complete: | 90% |
Assigned to: | pedram | Open/Closed: | Open |
Effort: | 0.00 |
Jump to the original submission
Sun 30 May 2021 04:34:45 PM UTC, comment #33: |
Mohammad Akhlaghi <makhlaghi>![]() |
Fri 14 May 2021 11:51:46 AM UTC, comment #32: As a small progress report, I am happy to say that the TAB completion has matured nicely and has already been fully implemented in 8 programs so far (12 more programs and scripts to go)!
|
Mohammad Akhlaghi <makhlaghi>![]() |
Mon 03 May 2021 12:14:04 PM UTC, comment #31: Indeed, modularity is the key to doing any type of project (if you later want to allow the potential for growing and scaling up).
|
Mohammad Akhlaghi <makhlaghi>![]() |
Mon 03 May 2021 06:03:18 AM UTC, comment #30: Great! You made my day Mohammad :)
|
Pedram Ashofteh-Ardakani <pedram>![]() ![]() |
Sun 02 May 2021 11:41:06 PM UTC, comment #29: I am happy to say that I was finally able to open up some time this weekend and do a complete review of your great work Pedram!
|
Mohammad Akhlaghi <makhlaghi>![]() |
Sun 28 Mar 2021 07:33:20 PM UTC, comment #28: Thanks for the encouragement Mohammad :)
|
Pedram Ashofteh-Ardakani <pedram>![]() ![]() |
Sat 27 Mar 2021 05:21:02 PM UTC, comment #27: Great! Its a really good point to discuss formattting issues independently of the actual job! Thanks for defining task #15924 for this.
|
Mohammad Akhlaghi <makhlaghi>![]() |
Sat 27 Mar 2021 05:08:05 PM UTC, comment #26: Hi again :)
|
Pedram Ashofteh-Ardakani <pedram>![]() ![]() |
Thu 04 Mar 2021 09:57:49 PM UTC, comment #25: Hi Mohammad!
Auto-completion: Refactor ..._is_table function With this commit, I replaced 'return 0' (or 1) with 'break' as it used to be. Because we are not using the function as a boolean query. However, we can se if there is a valid FITS or plaintext file withing the command line by checking if the $last_table is populated: [ x$last_table != x ] Also, I replaced an indented 'if' with 'elif' for better code readablity. Auto-completion: Call ..._last_table where needed Until now, the '..._last_table' function ran everytime. This function is responsible for populating the $last_table variable. Which means there has been a valid FITS or plaintext table file called in the commandline. Since we do not need to check for this everytime the script runs, I have moved it to more specific places where we need to check the $last_table variable. This might help reduce overhead. Also, I noticed and removed the extra space between the command prompt and the user commands. Auto-completion: Debug -i, improve performance Until now, autocompletion checked if there is a valid FITS file or a plaintext table available while also the '-i' or '--information' option is called. In this case, it would print a warning message that it is safe to press ENTER since all other options will be disabled by the 'table' program. However, this behavior broke in previous commits. This commit fixes the problem. Also, previously the 'awk' command in the '..._last_table' function would print all the words in the command line -- named as 'token'. This includes the short and long options. The problem is that bash is later instructed to check if each 'token' is a valid file -- [ -f $token]. As Mohammad pointed out before, this is a computationaly exhaustive process. So, we would only need to check tokens that we already know are not the program options! These tokens would start with a dash '-'. Hence, I have added a regex condition check in the 'awk' program to take care of that. Now, it will only print tokens NOT starting with a '-' sign. |
Pedram Ashofteh-Ardakani <pedram>![]() ![]() |
Tue 02 Mar 2021 09:08:12 PM UTC, comment #24: Hello again Mohammad :) I have pushed 6 new atomic commits, so you can cherry pick if need be. I will try to work on your previous suggestions soon :)
P.S.Commit Message Auto-completion: Refactor FITS related functions Until now, each function that had something to do with fits file had a different approach of making sure the input file is actually a fits file. However, Mohammad wrote a special function that checks if an input file is an actual existing FITS file, regardless of its extension. With this commit, I moved those functions below the '..._is_fits' function. From now on, we should be careful to feed only valid FITS file to fits accepting functions, or there will be confusing errors. Also, I revised some comments on different functions and replaced some variables with their human-readable substitutes. Auto-completion: return value from last table Until now, the _gnuastro_autocomplete_last_table function would not return anything. It would just set a global variable. However, it might be a better idea to use return values instead of breaking the loops. Because later we can use the return value as a signal if need be. Auto-completion: Rename boolean query functions Until now, functions that validated if a file is FITS or a plaintext table were named like: _gnuastro_autocomplete_x_is_extension However, it might be a better naming style as if we were asking the functions whether the input file is the extension we want or not as: _gnuastro_autocomplete_is_x_extension (?) and we'd expect a 0 or 1 as return. With this commit, I have renamed two functions accordingly. Auto-completion: Human readable arguments Until now, some functions just used the raw '$1', '$2', etc. to refer to given arguments. With this commit, some of these arguments are given more specific names to improve and maintain code readability. Also, I moved some comment blocks out of functions to respect the coding standards as Mohammad mentioned previously. Auto-completion: Suggest plaintext tables too Until now, autocomplete only suggested FITS files as input. With this commit, plaintext files will be shown too. Also, I have added the _gnuastro_autocomplete_list_all_valid_files function to prevent redundant iteration over a list of files to check for all acceptable file types. Auto-completion: Call astfits/asttable consistently With this commit, the auto-completion script calls for astfits and asttable only using their stored name in the script beginning. They are '$_gnuastro_astfits' and '$_gnuastro_asttable'. |
Pedram Ashofteh-Ardakani <pedram>![]() ![]() |
Mon 01 Mar 2021 09:55:12 PM UTC, comment #23: My pleasure Mohammad! I sure learned some useful tricks coding with you :) I pushed two commits, latest commit b001e7c272.
I guess there is no need for that. I just use the 'astfits' return value as a reference. Is this OK?
Nice idea! I will see what I can do ASAP :) It is fun to play around with formatting options that make the outputs easier on the eye.
Same here! Thank you for the fast response and helpful tweaks!
P.S. Commit Message: Auto-completion: Faster fits parse, use 'local' With this commit, I added the '-q' option to 'astfits' program so it will print less information, hence, it looks might be a bit faster. Since we can use the 'local' declaration, I removed the 'unset' at the end of functions and declared their variables as 'local' instead. Also, there was a misleading typo in comments about return value of the _gnuastro_autocomplete_plaintext_is_table function. It said the function would return '1' if the given file is a table, on the contrary, it returns '0', as it should by the conventions. Auto-completion: Smart list fits files, fix var Until now, the function responsible for listing the fits files only checked if the file extension ended with 'fits'. This is not a rebust test, because other fits files -- that might have different extensions or no extensions at all -- would be left out. With this commit, I used 'astfits' program return value to check their validity regardless of their name or extension. However, this has a bit of overhead and slows response. We can ignore it if it is not that significant, and will not ruin user experience. Also, I replaced a hard-coded value with intended $inputfile variable. |
Pedram Ashofteh-Ardakani <pedram>![]() ![]() |
Mon 01 Mar 2021 01:18:46 AM UTC, comment #22: Thanks a lot Pedram, I made some modifications in Commit 2f43d29151f (message in P.S., this was a good idea!)
|
Mohammad Akhlaghi <makhlaghi>![]() |
Sun 28 Feb 2021 09:38:11 PM UTC, comment #21: Hi Mohammad! OK, I pushed the commit 968bb7c07b and changed the syntax a bit. Now it should be more clear :)
It should have printed the prompt in a new line :/ I used the command below to print the prompt:
|
Pedram Ashofteh-Ardakani <pedram>![]() ![]() |
Sun 28 Feb 2021 07:34:23 PM UTC, comment #20: Thanks Pedram, I just pulled the changes and tried it. The problem is that in this mode, the user's prompt is no longer printed and the command stars at the beginning of the line! This is not what people expect.
|
Mohammad Akhlaghi <makhlaghi>![]() |
Sun 28 Feb 2021 05:39:49 AM UTC, comment #19: Oh I got caught up in replying comment #17 and forgot about comment #16. Sure! I will do it in a separate task soon :-) |
Pedram Ashofteh-Ardakani <pedram>![]() ![]() |
Sun 28 Feb 2021 05:35:59 AM UTC, comment #18: Hi Mohammad, thank you for the swift response and code check!
|
Pedram Ashofteh-Ardakani <pedram>![]() ![]() |
Sun 28 Feb 2021 03:29:40 AM UTC, comment #17: Hi again Pedram, I made some good progress with the script, but I a problem that didn't let me progress fast and I didn't have time to figure out its solution :-(!
|
Mohammad Akhlaghi <makhlaghi>![]() |
Sat 27 Feb 2021 04:08:59 PM UTC, comment #16: I am happy you enjoyed the comments, a good work will have good feedback ;-).
|
Mohammad Akhlaghi <makhlaghi>![]() |
Sat 27 Feb 2021 06:59:45 AM UTC, comment #15: You made my day Mohammad! Thank you for the wise and informative feedback :) Mentioning the references points enthusiastic people - your truly ;-) - to the right direction. I am having a good time reading them. Thank you so much.
|
Pedram Ashofteh-Ardakani <pedram>![]() ![]() |
Sat 27 Feb 2021 03:13:25 AM UTC, comment #14: I just went through the newly added section in the book and REALLY ENJOYED IT! Wonderful work Pedram. I really recommend the tutorial that Pedram has written to anyone using the shell and would like to customize their shell completions (even outside of Gnuastro!).
|
Mohammad Akhlaghi <makhlaghi>![]() |
Sat 20 Feb 2021 08:25:31 PM UTC, comment #13: Hi Mohammad!
|
Pedram Ashofteh-Ardakani <pedram>![]() ![]() |
Mon 08 Feb 2021 12:41:50 AM UTC, comment #12: Great work Pedram.
No problem, the completion we are designing is only for Bash anyway. Things like Dash don't have completion (as far as I know), and really have no idea how other shells (like zsh) treat completion. So you just have to assume that the feature exists in a certain version of Bash.
|
Mohammad Akhlaghi <makhlaghi>![]() |
Sun 07 Feb 2021 07:26:35 PM UTC, comment #11: Great news! check commit f8425b57..75b02a5d. I can not access gitlab right now, so please help yourself with the last commit on 'dev-auto-complete'. Try it out and let me know Mohammad :) Just download the 'completion.sh' file, and call 'source completion.sh'. Let me know if you have any tweaks in mind :) |
Pedram Ashofteh-Ardakani <pedram>![]() ![]() |
Sun 07 Feb 2021 09:09:06 AM UTC, comment #10: I read a few articles about portability to Mac and previous versions. Keeping them here might be helpful.
|
Pedram Ashofteh-Ardakani <pedram>![]() ![]() |
Sun 07 Feb 2021 08:32:28 AM UTC, comment #9: Hi Mohammad. Speaking of portability, I stumbled upon the program: shellcheck. This program shows warnings in case of any error or POSIX incompatibility. It looks like arrays are not supported in POSIX. Is it OK if I use them in autocompletion or should I find a replacement? E.g. using awk, known shell workarounds, etc.
|
Pedram Ashofteh-Ardakani <pedram>![]() ![]() |
Fri 05 Feb 2021 02:39:12 PM UTC, comment #8: As Mohammad pointed out, it is better to submit a new task for using the autocompletion in emacs. Now things are simpler, and we can focus on tasks one at a time.
|
Pedram Ashofteh-Ardakani <pedram>![]() ![]() |
Thu 04 Feb 2021 03:39:26 PM UTC, comment #7: As Samaeh pointed out, some Gnuastro users write their scripts in emacs. So it would be nice if the completions could work there too. Fortunately, that is possible already: https://github.com/szermatt/emacs-bash-completion |
Pedram Ashofteh-Ardakani <pedram>![]() ![]() |
Thu 04 Feb 2021 12:56:40 PM UTC, comment #6: This is very good progress, thanks Pedram ;-)!
|
Mohammad Akhlaghi <makhlaghi>![]() |
Thu 04 Feb 2021 12:45:54 PM UTC, comment #5: I had some progress with the completion script in this commit. As we are thinking of more complicated output and helpers, this article might be useful: https://brbsix.github.io/2015/11/29/accessing-tab-completion-programmatically-in-bash/ |
Pedram Ashofteh-Ardakani <pedram>![]() ![]() |
Wed 03 Feb 2021 02:06:59 AM UTC, comment #4: I just came across this project: https://github.com/scop/bash-completion
|
Mohammad Akhlaghi <makhlaghi>![]() |
Thu 28 Jan 2021 03:55:00 PM UTC, comment #3: Hi Mohammad, Thanks for the commit c826434952!
|
Pedram Ashofteh-Ardakani <pedram>![]() ![]() |
Wed 27 Jan 2021 10:09:46 PM UTC, comment #2: As one step towards this, in Commit c826434952 the options that accept FITS (or FITS or TXT) are now marked as 'FITS' or 'FITS/TXT'.
|
Mohammad Akhlaghi <makhlaghi>![]() |
Sun 25 Oct 2020 09:39:05 PM UTC, comment #1: This is indeed a very useful feature! Thanks a lot Pedram for suggesting it.
|
Mohammad Akhlaghi <makhlaghi>![]() |
Sun 25 Oct 2020 04:00:53 PM UTC, original submission:
Using autocomplete (using the <TAB> key) not only helps write commands faster, but also reduces the chance of making typing mistakes, and helps users explore all the options available.
|
Pedram Ashofteh-Ardakani <pedram>![]() ![]() |
No files currently attached
Depends on the following items: None found
Items that depend on this one: None found
There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.
Follow 5 latest changes.
Date | Changed by | Updated Field | Previous Value | => | Replaced by |
---|---|---|---|---|---|
2021-05-02 | makhlaghi | Percent Complete | 30% | ![]() |
90% |
2021-02-28 | makhlaghi | Assigned to | None | ![]() |
pedram |
2021-02-27 | makhlaghi | Percent Complete | 0% | ![]() |
30% |
2020-11-27 | pedram | Carbon-Copy | Removed makhlaghi | ![]() |
- |
2020-10-25 | pedram | Carbon-Copy | - | ![]() |
Added makhlaghi |
Due to bug #60618, in Commit 4c01082f8, I added notices above the relevant parts of the documentation. In the notices, we highlight that TAB completion is still under development and not yet complete. I also cite this task for interested people to see the progress on this.
Just for the record, as mentioned in the commit message, TAB completion is currently only available for these programs:
We'll continue with the rest once we find a solution to bug #60618.