[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 1c1fe3d 01/62: New feature: Auto Complete (WIP
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master 1c1fe3d 01/62: New feature: Auto Complete (WIP) |
Date: |
Thu, 13 May 2021 22:20:44 -0400 (EDT) |
branch: master
commit 1c1fe3d006a5257b31f2a44ea75c99d6f84355b8
Author: Pedram Ashofteh Ardakani <pedramardakani@pm.me>
Commit: Mohammad Akhlaghi <mohammad@akhlaghi.org>
New feature: Auto Complete (WIP)
Until now, the user did not have the convenience of using auto
completion in Gnuastro. With this commit, user can push the <TAB>
character in the middle of typing and select the appropriate option
or command.
This commit is a work in progress (hence the WIP in the subject). For
now, the feature is only available in `astcosmiccal`. But we are
planning to expand it to all Gnuastro subprograms in near future.
---
bin/cosmiccal/astcosmiccal-completion.bash | 42 ++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/bin/cosmiccal/astcosmiccal-completion.bash
b/bin/cosmiccal/astcosmiccal-completion.bash
new file mode 100644
index 0000000..8e81306
--- /dev/null
+++ b/bin/cosmiccal/astcosmiccal-completion.bash
@@ -0,0 +1,42 @@
+#/usr/bin/env bash
+
+# TIP: Run the command below to initialize the bash completion feature for
+# this specific program (i.e. astcosmiccal):
+# $ source astcosmiccal-completion.bash
+
+_astcosmiccal_completions(){
+
+ # PATH_TO_COMMAND_BIN, i.e. the directory which the astcosmiccal
+ # command sits in.
+ local PATH_TO_COMMAND_BIN=".";
+
+ # Use "args.h" file to filter out all valid options of the command and
+ # put them all in the variable "commandoptions".
+
+ local commandoptions=$(sed -n -E '/^\s+\"[a-z]+/p' \
+ "$PATH_TO_COMMAND_BIN/args.h" | \
+ # remove newline and space characters
+ tr -d '\n" ' | \
+ # replace commas with spaces
+ tr ',' ' ');
+
+ # Initialize the completion response with null
+ COMPREPLY=();
+
+ # Variable "word", is the current word being completed
+ local word="${COMP_WORDS[COMP_CWORD]}";
+
+ # Variable "prev" is the word just before the current word
+ local prev="${COMP_WORDS[COMP_CWORD-1]}";
+
+ if [ $prev = "lineatz" ]; then
+ # Show options related to "lineatz"
+ COMPREPLY=($(compgen -W "$(astcosmiccal --listlines | \
+ awk '!/^#/ {print $2}') " \
+ -- "$word"));
+ else
+ COMPREPLY=($(compgen -W "$commandoptions" -- "$word"));
+ fi;
+}
+
+complete -F _astcosmiccal_completions astcosmiccal
- [gnuastro-commits] master updated (ffc7608 -> b947f79), Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 1c1fe3d 01/62: New feature: Auto Complete (WIP),
Mohammad Akhlaghi <=
- [gnuastro-commits] master c02ae2c 02/62: Completion: feed options from `help`, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master b06fbce 03/62: Completion: Fix indentations, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master a829b24 05/62: Completion: Suggest FITS files in relevant options, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 3da00c3 07/62: Table: Prepare initial completion script, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 477d23d 06/62: Rename completion files, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 39efeea 08/62: Table: First working completion, general commands, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master 32cbe32 13/62: Table: Completion, better formatting, add function, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master d631f5b 15/62: Table: Completion, remove global variables, etc, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master f4cf33d 17/62: Tabel: Completion, examine for fits availability, Mohammad Akhlaghi, 2021/05/13
- [gnuastro-commits] master e1c1a4b 18/62: Table: Completion, fix 'wcshdu', Mohammad Akhlaghi, 2021/05/13