| 
									
										
										
										
											2024-04-13 16:57:22 -06:00
										 |  |  | #!/bin/zsh | 
					
						
							|  |  |  | DEPENDENCIES+=(tmux scwrypts) | 
					
						
							|  |  |  | ##################################################################### | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | USAGE__description=" | 
					
						
							|  |  |  | 	A program which automatically connects to any available connections | 
					
						
							|  |  |  | 	described in the configuration file. | 
					
						
							|  |  |  | 	  (configure with 'scwrypts remote configure') | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	The omni-session is running it's own wrapper TMUX server with a special | 
					
						
							|  |  |  | 	config. In the wrapper session, 'M-s' is overwritten as the prefix. | 
					
						
							|  |  |  | 	Switch between connections by using 'M-s' followed by the session ID | 
					
						
							|  |  |  | 	number (or use any other default default tmux navigation command). Full | 
					
						
							|  |  |  | 	configuration can be found here: | 
					
						
							|  |  |  | 	  - $SCWRYPTS_ROOT__remote/omni/tmux.conf | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Shut-down the omni-session by pressing 'M-Q' (Q not q! ALT + SHIFT + Q) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	Disconnect (but leave the session running) with 'M-s, d' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	A background process periodically attempts to refresh lost connections. | 
					
						
							|  |  |  | 	Immediate retry can be forced with 'M-R'. | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	Running this command in an existing tmux session will likely result | 
					
						
							|  |  |  | 	in an infinite loop, so: | 
					
						
							|  |  |  | 	  - don't run the omni-session in a TMUX session | 
					
						
							|  |  |  | 	  - don't connect to the omni-session directly (always use this scwrypt) | 
					
						
							|  |  |  | " | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ##################################################################### | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MAIN() { | 
					
						
							|  |  |  | 	[[ $TERM =~ tmux ]] && ERROR "\n Cannot run tmux-omni within a tmux session!\n  " | 
					
						
							| 
									
										
										
										
											2024-08-16 09:41:26 -06:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	local BACKGROUND_LAUNCH=false | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	local _S | 
					
						
							|  |  |  | 	while [[ $# -gt 0 ]] | 
					
						
							|  |  |  | 	do | 
					
						
							|  |  |  | 		_S=1 | 
					
						
							|  |  |  | 		case $1 in | 
					
						
							|  |  |  | 			--background ) BACKGROUND_LAUNCH=true ;; | 
					
						
							|  |  |  | 		esac | 
					
						
							|  |  |  | 		[[ $_S -le $# ]] \ | 
					
						
							|  |  |  | 			&& shift $_S \ | 
					
						
							|  |  |  | 			|| ERROR "missing argument for '$1'" \ | 
					
						
							|  |  |  | 			|| shift $# \ | 
					
						
							|  |  |  | 			; | 
					
						
							|  |  |  | 	done | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-13 16:57:22 -06:00
										 |  |  | 	CHECK_ERRORS | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	local OMNI_SOCKET="omni.socket" | 
					
						
							|  |  |  | 	OMNI_TMUX() { tmux -L $OMNI_SOCKET $@; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	OMNI_TMUX list-sessions 2>/dev/null | grep -v omni-manager | grep -qi omni || { | 
					
						
							|  |  |  | 		STATUS "initializing omni server" | 
					
						
							|  |  |  | 		OMNI_TMUX kill-session -t=omni-manager >/dev/null 2>&1 | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 		OMNI_TMUX -f "$SCWRYPTS_ROOT__remote/tmux/tmux.conf" new -d -s omni \ | 
					
						
							|  |  |  | 			"echo searching for first connection...; sleep 30" \; \ | 
					
						
							|  |  |  | 			split-window "sleep 3; TMUX= tmux -L $OMNI_SOCKET a -t=omni-manager" \; \ | 
					
						
							|  |  |  | 			move-window -t 99 \; | 
					
						
							|  |  |  | 	 | 
					
						
							| 
									
										
										
										
											2024-04-13 17:57:56 -06:00
										 |  |  | 		OMNI_TMUX new -d -s omni-manager "$SCWRYPTS_ROOT__remote/tmux/manager" | 
					
						
							| 
									
										
										
										
											2024-04-13 16:57:22 -06:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-08-16 09:41:26 -06:00
										 |  |  | 	[[ $BACKGROUND_LAUNCH =~ true ]] && { | 
					
						
							|  |  |  | 		SUCCESS "omni server activated" | 
					
						
							|  |  |  | 		return 0 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-13 16:57:22 -06:00
										 |  |  | 	STATUS 'connecting to omni server' | 
					
						
							|  |  |  | 	OMNI_TMUX a -t=omni | 
					
						
							|  |  |  | } |