flacfix script, cpm completion update, newsboat urls, new install_clean patch
[dotfiles.git] / shell / .bash_completion.d / cpm
1 # bash completion for cpm
2 # Author: Mart Lubbers
3 # Date: 2018-07-17
4 #
5 # Todo
6 # - support --envs=filename
7 # - create completion for module
8 # - create completion for environment
9 # - test on non-linux
10 _set_opts="-generic_fusion -ngeneric_fusion -dynamics -ndynamics -descexl -ndescexl -b -nr -nc -sc"
11
12 _targets()
13 {
14 sed 's/EnvironmentName:[[:space:]]*//;t;d' | tr -d '\n'
15 }
16
17 _paths()
18 {
19 sed 's/\[\([[:digit:]]\)\].*/\1/;t;d' | tr -d '\n'
20 }
21
22 _cpm()
23 {
24 local arg cur prev words cword split
25
26 # Require bash completion
27 _init_completion || return
28 _get_first_arg
29 _get_comp_words_by_ref
30
31 # subcommand or project file
32 if [[ -z "${arg}" ]]
33 then
34 COMPREPLY=( $(compgen -W "environment project module make" -- ${cur}) )
35 _filedir prj
36 else
37 case "${arg}" in
38 *.prj)
39 COMPREPLY=( $(compgen -W "--force" -- ${cur}) )
40 ;;
41 make)
42 ;;
43 project)
44 # Not even a project file is selected
45 if [[ "$cword" = 2 ]]
46 then
47 _filedir prj
48 # A project file is selected
49 elif [[ "$cword" = 3 ]]
50 then
51 COMPREPLY=( $(compgen -W "create show build path root target exec set" -- ${cur}) )
52 # A project command is selected
53 elif [[ "$cword" -ge 4 ]]
54 then
55 case "${words[3]}" in
56 build)
57 COMPREPLY=( $(compgen -W "--force --envs" -- ${cur}) )
58 ;;
59 path)
60 # No path command set yet
61 if [[ "$cword" = 4 ]]
62 then
63 COMPREPLY=( $(compgen -W "add list remove move" -- ${cur}) )
64 # Path command is set
65 elif [[ "$cword" -ge 5 ]]
66 then
67 case "${words[4]}" in
68 add)
69 _filedir -d
70 ;;
71 list)
72 ;;
73 remove)
74 COMPREPLY=( $(compgen -W "$("${words[0]}" project "${words[2]}" path list | _paths)" -- ${cur}) )
75 ;;
76 move)
77 if [[ "$cword" = 5 ]]
78 then
79 COMPREPLY=( $(compgen -W "$("${words[0]}" project "${words[2]}" path list | _paths)" -- ${cur}) )
80 elif [[ "$cword" = 6 ]]
81 then
82 COMPREPLY=( $(compgen -W "up down top bottom" -- ${cur}) )
83 fi
84 ;;
85 esac
86 fi
87 ;;
88 root)
89 COMPREPLY=( $(compgen -W ". .. ... .... ....." -- ${cur}) )
90 ;;
91 target)
92 COMPREPLY=( $(compgen -W "$(_targets < "$CLEAN_HOME/etc/IDEEnvs")" -- ${cur}) )
93 ;;
94 set)
95 COMPREPLY=( $(compgen -W "$_set_opts" -- ${cur}) )
96 ;;
97 exec)
98 ;;
99 create)
100 _filedir prt
101 ;;
102 show)
103 ;;
104 main)
105 _filedir
106 ;;
107 esac
108 fi
109 ;;
110 module)
111 ;;
112 environment)
113 ;;
114 esac
115 fi
116 } && complete -F _cpm cpm