| 
									
										
										
										
											2017-04-06 12:30:28 +00:00
										 |  |  | # test if git completion is missing, but loader exists, attempt to load | 
					
						
							| 
									
										
										
										
											2025-03-03 20:36:36 +00:00
										 |  |  | if ! declare -F _git >/dev/null && ! declare -F __git_wrap__git_main >/dev/null; then | 
					
						
							|  |  |  |   if declare -F _completion_loader >/dev/null; then | 
					
						
							| 
									
										
										
										
											2021-02-07 22:30:27 +00:00
										 |  |  |     _completion_loader git | 
					
						
							|  |  |  |   fi | 
					
						
							| 
									
										
										
										
											2017-04-06 12:30:28 +00:00
										 |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # only operate if git completion is present | 
					
						
							| 
									
										
										
										
											2025-03-03 20:36:36 +00:00
										 |  |  | if declare -F _git >/dev/null || declare -F __git_wrap__git_main >/dev/null; then | 
					
						
							| 
									
										
										
										
											2017-04-06 12:30:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   _yadm() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     local current=${COMP_WORDS[COMP_CWORD]} | 
					
						
							| 
									
										
										
										
											2017-05-07 20:43:10 +00:00
										 |  |  |     local penultimate | 
					
						
							| 
									
										
										
										
											2025-03-03 20:36:36 +00:00
										 |  |  |     if ((COMP_CWORD >= 1)); then | 
					
						
							|  |  |  |       penultimate=${COMP_WORDS[COMP_CWORD - 1]} | 
					
						
							| 
									
										
										
										
											2017-05-07 20:43:10 +00:00
										 |  |  |     fi | 
					
						
							|  |  |  |     local antepenultimate | 
					
						
							| 
									
										
										
										
											2025-03-03 20:36:36 +00:00
										 |  |  |     if ((COMP_CWORD >= 2)); then | 
					
						
							|  |  |  |       antepenultimate=${COMP_WORDS[COMP_CWORD - 2]} | 
					
						
							| 
									
										
										
										
											2017-05-07 20:43:10 +00:00
										 |  |  |     fi | 
					
						
							| 
									
										
										
										
											2017-04-06 12:30:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 02:26:47 +00:00
										 |  |  |     local -x GIT_DIR | 
					
						
							| 
									
										
										
										
											2017-04-06 12:30:28 +00:00
										 |  |  |     GIT_DIR="$(yadm introspect repo 2>/dev/null)" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     case "$penultimate" in | 
					
						
							|  |  |  |       bootstrap) | 
					
						
							|  |  |  |         COMPREPLY=() | 
					
						
							|  |  |  |         return 0 | 
					
						
							| 
									
										
										
										
											2025-03-03 20:36:36 +00:00
										 |  |  |         ;; | 
					
						
							| 
									
										
										
										
											2017-04-06 12:30:28 +00:00
										 |  |  |       config) | 
					
						
							| 
									
										
										
										
											2025-03-03 20:36:36 +00:00
										 |  |  |         COMPREPLY=($(compgen -W "$(yadm introspect configs 2>/dev/null)")) | 
					
						
							| 
									
										
										
										
											2017-04-06 12:30:28 +00:00
										 |  |  |         return 0 | 
					
						
							| 
									
										
										
										
											2025-03-03 20:36:36 +00:00
										 |  |  |         ;; | 
					
						
							| 
									
										
										
										
											2017-04-06 12:30:28 +00:00
										 |  |  |       decrypt) | 
					
						
							| 
									
										
										
										
											2025-03-03 20:36:36 +00:00
										 |  |  |         COMPREPLY=($(compgen -W "-l" -- "$current")) | 
					
						
							| 
									
										
										
										
											2017-04-06 12:30:28 +00:00
										 |  |  |         return 0 | 
					
						
							| 
									
										
										
										
											2025-03-03 20:36:36 +00:00
										 |  |  |         ;; | 
					
						
							| 
									
										
										
										
											2017-04-06 12:30:28 +00:00
										 |  |  |       init) | 
					
						
							| 
									
										
										
										
											2025-03-03 20:36:36 +00:00
										 |  |  |         COMPREPLY=($(compgen -W "-f -w" -- "$current")) | 
					
						
							| 
									
										
										
										
											2017-04-06 12:30:28 +00:00
										 |  |  |         return 0 | 
					
						
							| 
									
										
										
										
											2025-03-03 20:36:36 +00:00
										 |  |  |         ;; | 
					
						
							| 
									
										
										
										
											2017-04-06 12:30:28 +00:00
										 |  |  |       introspect) | 
					
						
							| 
									
										
										
										
											2025-03-03 20:36:36 +00:00
										 |  |  |         COMPREPLY=($(compgen -W "commands configs repo switches" -- "$current")) | 
					
						
							| 
									
										
										
										
											2017-04-06 12:30:28 +00:00
										 |  |  |         return 0 | 
					
						
							| 
									
										
										
										
											2025-03-03 20:36:36 +00:00
										 |  |  |         ;; | 
					
						
							| 
									
										
										
										
											2017-04-06 12:30:28 +00:00
										 |  |  |       help) | 
					
						
							|  |  |  |         COMPREPLY=() # no specific help yet | 
					
						
							|  |  |  |         return 0 | 
					
						
							| 
									
										
										
										
											2025-03-03 20:36:36 +00:00
										 |  |  |         ;; | 
					
						
							| 
									
										
										
										
											2017-04-06 12:30:28 +00:00
										 |  |  |       list) | 
					
						
							| 
									
										
										
										
											2025-03-03 20:36:36 +00:00
										 |  |  |         COMPREPLY=($(compgen -W "-a" -- "$current")) | 
					
						
							| 
									
										
										
										
											2017-04-06 12:30:28 +00:00
										 |  |  |         return 0 | 
					
						
							| 
									
										
										
										
											2025-03-03 20:36:36 +00:00
										 |  |  |         ;; | 
					
						
							| 
									
										
										
										
											2017-04-06 12:30:28 +00:00
										 |  |  |     esac | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     case "$antepenultimate" in | 
					
						
							|  |  |  |       clone) | 
					
						
							| 
									
										
										
										
											2025-03-03 20:36:36 +00:00
										 |  |  |         COMPREPLY=($(compgen -W "-f -w -b --bootstrap --no-bootstrap" -- "$current")) | 
					
						
							| 
									
										
										
										
											2017-04-06 12:30:28 +00:00
										 |  |  |         return 0 | 
					
						
							| 
									
										
										
										
											2025-03-03 20:36:36 +00:00
										 |  |  |         ;; | 
					
						
							| 
									
										
										
										
											2017-04-06 12:30:28 +00:00
										 |  |  |     esac | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-03 20:36:36 +00:00
										 |  |  |     local yadm_switches=($(yadm introspect switches 2>/dev/null)) | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-06 12:30:28 +00:00
										 |  |  |     # this condition is so files are completed properly for --yadm-xxx options | 
					
						
							| 
									
										
										
										
											2019-01-05 02:17:34 +00:00
										 |  |  |     if [[ " ${yadm_switches[*]} " != *" $penultimate "* ]]; then | 
					
						
							| 
									
										
										
										
											2017-04-06 12:30:28 +00:00
										 |  |  |       # TODO: somehow solve the problem with [--yadm-xxx option] being | 
					
						
							|  |  |  |       #       incompatible with what git expects, namely [--arg=option] | 
					
						
							| 
									
										
										
										
											2025-03-03 20:36:36 +00:00
										 |  |  |       if declare -F _git >/dev/null; then | 
					
						
							| 
									
										
										
										
											2021-02-07 22:30:27 +00:00
										 |  |  |         _git | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         __git_wrap__git_main | 
					
						
							|  |  |  |       fi | 
					
						
							| 
									
										
										
										
											2017-04-06 12:30:28 +00:00
										 |  |  |     fi | 
					
						
							|  |  |  |     if [[ "$current" =~ ^- ]]; then | 
					
						
							| 
									
										
										
										
											2025-03-03 20:36:36 +00:00
										 |  |  |       __gitcompappend "${yadm_switches[*]}" "" "$current" " " | 
					
						
							| 
									
										
										
										
											2017-04-06 12:30:28 +00:00
										 |  |  |     fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 02:44:49 +00:00
										 |  |  |     # Find the index of where the sub-command argument should go. | 
					
						
							|  |  |  |     local command_idx | 
					
						
							| 
									
										
										
										
											2025-03-03 20:36:36 +00:00
										 |  |  |     for ((command_idx = 1; command_idx < ${#COMP_WORDS[@]}; command_idx++)); do | 
					
						
							| 
									
										
										
										
											2019-01-05 02:44:49 +00:00
										 |  |  |       local command_idx_arg="${COMP_WORDS[$command_idx]}" | 
					
						
							|  |  |  |       if [[ " ${yadm_switches[*]} " = *" $command_idx_arg "* ]]; then | 
					
						
							|  |  |  |         let command_idx++ | 
					
						
							|  |  |  |       elif [[ "$command_idx_arg" = -* ]]; then | 
					
						
							|  |  |  |         : | 
					
						
							|  |  |  |       else | 
					
						
							|  |  |  |         break | 
					
						
							|  |  |  |       fi | 
					
						
							|  |  |  |     done | 
					
						
							|  |  |  |     if [[ "$COMP_CWORD" = "$command_idx" ]]; then | 
					
						
							| 
									
										
										
										
											2025-03-03 20:36:36 +00:00
										 |  |  |       __gitcompappend "$(yadm introspect commands 2>/dev/null)" "" "$current" " " | 
					
						
							| 
									
										
										
										
											2017-04-06 12:30:28 +00:00
										 |  |  |     fi | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-03-03 20:36:36 +00:00
										 |  |  |   complete -o bashdefault -o default -o nospace -F _yadm yadm 2>/dev/null || | 
					
						
							|  |  |  |     complete -o default -o nospace -F _yadm yadm | 
					
						
							| 
									
										
										
										
											2017-04-06 12:30:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | fi |