Debian Codegraph @

share/autocomplete_frama-c

raw
1 ##########################################################################
2 # #
3 # This file is part of Frama-C. #
4 # #
5 # Copyright (C) 2007-2022 #
6 # CEA (Commissariat à l'énergie atomique et aux énergies #
7 # alternatives) #
8 # #
9 # you can redistribute it and/or modify it under the terms of the GNU #
10 # Lesser General Public License as published by the Free Software #
11 # Foundation, version 2.1. #
12 # #
13 # It is distributed in the hope that it will be useful, #
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
16 # GNU Lesser General Public License for more details. #
17 # #
18 # See the GNU Lesser General Public License version 2.1 #
19 # for more details (enclosed in the file licenses/LGPLv2.1). #
20 # #
21 ##########################################################################
22
23 # file: autocomplete_frama-c
24 # bash completion for Frama-C
25 # ==========================
26 #
27 # Installation
28 # ============
29 #
30 # To enable system-wide completion, put this file in /etc/bash_completion.d
31 # If you want to enable Frama-C completion only for your account, append
32 # this file to ~/.bash_completion.
33 #
34 # For a less verbose completion for options with comma-separated values,
35 # put "set show-all-if-ambiguous on" in your "~/.inputrc".
36 #
37 # Assuming frama-c is in your PATH,
38 # you can also put the following line into your .bashrc:
39 #
40 # source $(frama-c -print-share-path)/autocomplete_frama-c || true
41 #
42 # -----------------------------------------------------------------------------
43
44 # Remove the colon from the list of completion word break characters
45 COMP_WORDBREAKS=${COMP_WORDBREAKS//:}
46
47 _frama-c ()
48 {
49 local cur
50
51 local basic_options
52 local sub_options
53 local advance_options
54
55 COMPREPLY=() # Array variable storing the possible completions.
56 local sub_comp_line="${COMP_LINE[@]:0:(${COMP_POINT})}"
57 local sub_comp_set=( $sub_comp_line )
58
59 compopt +o default
60
61 if [[ ${sub_comp_line: -1} == ' ' ]]
62 then
63 cur=""
64 else
65 cur="${sub_comp_set[@]: -1}"
66 fi
67
68
69 # Generate the completion matches for -wp-msg-key and load them into $COMPREPLY array.
70 # Generate the completion matches for -kernel-msg-key and load them into $COMPREPLY array.
71 if [[ "${COMP_WORDS[COMP_CWORD -1]}" == "-wp-msg-key" ]] || [[ "${COMP_WORDS[COMP_CWORD -1]}" == "-kernel-msg-key" ]]
72 then
73 # https://github.com/scop/bash-completion/issues/240
74 local prefix=; [[ $cur == *,* ]] && prefix="${cur%,*},"
75 advance_options="$(frama-c ${COMP_WORDS[COMP_CWORD -1]} help | grep -E -o " [^*]+" |sort |uniq)"
76
77 # Solution from: https://github.com/scop/bash-completion/commit/021058b38ad7279c33ffbaa36d73041d607385ba
78 # But, if show-all-if-ambiguous is set to off completion for options with comma-separated values loses its prefix:
79 # https://github.com/scop/bash-completion/issues/240.
80 # So we have two ways for completion, depending on the value of show-all-if-ambiguous
81 local ambigous="$(bind -v | grep show-all-if-ambiguous)"
82 ambigous="${ambigous##* }"
83 if [[ "$ambigous" == "on" ]]
84 then
85 COMPREPLY=( $( compgen -W "${advance_options}" -- "${cur##*,}" ) )
86 [[ ${#COMPREPLY[@]} -eq 1 ]] && COMPREPLY=( ${COMPREPLY/#/$prefix} )
87 else
88 COMPREPLY=( $( compgen -P "$prefix" -W "${advance_options}" -- "${cur##*,}" ) )
89 fi
90
91
92 # Generate the completion matches for -wp-prover and load them into $COMPREPLY array.
93 elif [[ "${COMP_WORDS[COMP_CWORD -1]}" == "-wp-prover" ]]
94 then
95 local prefix=; [[ $cur == *,* ]] && prefix="${cur%,*},"
96 advance_options="$(frama-c -wp-detect | grep -E -o " \[.*" | grep -E -o "[^][|]*")"
97 advance_options+=" none script tip"
98 local ambigous="$(bind -v | grep show-all-if-ambiguous)"
99 ambigous="${ambigous##* }"
100 if [[ "$ambigous" == "on" ]]
101 then
102 COMPREPLY=( $( compgen -W "${advance_options}" -- "${cur##*,}" ) )
103 [[ ${#COMPREPLY[@]} -eq 1 ]] && COMPREPLY=( ${COMPREPLY/#/$prefix} )
104 else
105 COMPREPLY=( $( compgen -P "$prefix" -W "${advance_options}" -- "${cur##*,}" ) )
106 fi
107
108
109 # Generate the completion matches for -kernel-warn-key and load them into $COMPREPLY array.
110 elif [[ "${COMP_WORDS[COMP_CWORD -1]}" == "-kernel-warn-key" ]]
111 then
112 local prefix=; [[ $cur == *,* ]] && prefix="${cur%,*},"
113 advance_options="$(frama-c -kernel-warn-key help | grep -E -o " [^*]+[^:] ")"
114
115 local ambigous="$(bind -v | grep show-all-if-ambiguous)"
116 ambigous="${ambigous##* }"
117 if [[ "$ambigous" == "on" ]]
118 then
119 COMPREPLY=( $( compgen -W "${advance_options}" -- "${cur##*,}" ) )
120 [[ ${#COMPREPLY[@]} -eq 1 ]] && COMPREPLY=( ${COMPREPLY/#/$prefix} )
121 else
122 COMPREPLY=( $( compgen -P "$prefix" -W "${advance_options}" -- "${cur##*,}" ) )
123 fi
124
125
126 # Generate the completion matches for -* and load them into $COMPREPLY array.
127 else
128 case "$cur" in
129 -*-*)
130 sub_option="$(frama-c -autocomplete @all | grep -E -o " $cur[^*]+" |sort |uniq)";
131 COMPREPLY=( $( compgen -W "${sub_option}" -- $cur ) );;
132
133 -*)
134 basic_options="$(frama-c -autocomplete @all | grep -E -o " \-[^-]+-?" |sort |uniq)"
135 COMPREPLY=( $( compgen -W "${basic_options}" -- $cur ) );;
136 *)
137 compopt -o default
138 COMPREPLY=();;
139 esac
140 fi
141
142 return 0
143 }
144
145 complete -o nospace -F _frama-c frama-c
146 complete -o nospace -F _frama-c frama-c-gui
147
148 # Local Variables:
149 # mode: sh
150 # sh-shell: bash
151 # End: