Add docker exec + fzf function
This commit is contained in:
		
							parent
							
								
									0196f51b32
								
							
						
					
					
						commit
						e62370ffe8
					
				
							
								
								
									
										20
									
								
								zshrc
								
								
								
								
							
							
						
						
									
										20
									
								
								zshrc
								
								
								
								
							|  | @ -2372,6 +2372,26 @@ fopen() { | |||
| } | ||||
| # }}} | ||||
| 
 | ||||
| # dexec − Docker exec in a running container {{{ | ||||
| # Display Docker running containers | ||||
| # Allow to specify the shell (default to bash) | ||||
| dexec() { | ||||
| 	local images_name | ||||
| 	local container_name | ||||
| 	local container_id | ||||
| 
 | ||||
| 	images_name=$(docker container ls --format "table {{.Image}}\t {{.RunningFor}}\t {{.Ports}}\t {{.Names}}" | fzf --prompt='docker> ' --tac ) | ||||
| 
 | ||||
| 	## Extract container_name from the selected line | ||||
| 	container_name=$(printf '%b' "${images_name}" | awk '{ print $NF }') | ||||
| 	## Get container_id from the selected container_name | ||||
| 	container_id=$(docker container ls --quiet --filter=name="${container_name}") | ||||
| 
 | ||||
| 	printf "%b\n" "Try to enter to Docker container (named : ${container_name})" | ||||
| 	docker exec -it "${container_id:-/dev/null}" "${1:-bash}" | ||||
| } | ||||
| # }}} | ||||
| 
 | ||||
| # }}} | ||||
| # zsh-syntax-highlighting {{{ | ||||
| ## Activate if plugin is available | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue