| 
									
										
										
										
											2022-10-03 17:46:49 +01:00
										 |  |  | #!/usr/bin/env bash | 
					
						
							| 
									
										
										
										
											2021-09-17 19:42:11 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Quickly navigate between different directories using fzf and tmux sessions | 
					
						
							|  |  |  | # (Thanks, ThePrimeagen!). | 
					
						
							|  |  |  | # | 
					
						
							|  |  |  | # https://github.com/ThePrimeagen/.dotfiles/blob/master/bin/.local/bin/tmux-sessionizer | 
					
						
							|  |  |  | # https://frontendmasters.com/workshops/dev-productivity | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if [[ $# -eq 1 ]]; then | 
					
						
							|  |  |  |   selected=$1 | 
					
						
							|  |  |  | else | 
					
						
							|  |  |  |   # Get the session name from fuzzy-finding list of directories and generating a | 
					
						
							|  |  |  |   # tmux-safe version. | 
					
						
							| 
									
										
										
										
											2023-06-13 19:57:25 +01:00
										 |  |  |   items=$(find ~/Code -mindepth 1 -maxdepth 2 -type d ! -name .git) | 
					
						
							|  |  |  |   items+="$HOME/Code/dotfiles" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   selected=$(echo "${items}" | sort | fzf --reverse) | 
					
						
							| 
									
										
										
										
											2021-09-17 19:42:11 +01:00
										 |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if [[ -z $selected ]]; then | 
					
						
							|  |  |  |   exit 0 | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-17 22:35:47 +01:00
										 |  |  | is_tmux_running=$(pgrep tmux) | 
					
						
							|  |  |  | selected_name=$(basename "$selected" | tr . -) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | if [[ -z $TMUX ]] && [[ -z $is_tmux_running ]]; then | 
					
						
							|  |  |  |     tmux new-session -s $selected_name -c $selected | 
					
						
							|  |  |  |     exit 0 | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-17 19:42:11 +01:00
										 |  |  | # Create a new session if tmux does not already have a session matching the | 
					
						
							|  |  |  | # selected session name. | 
					
						
							|  |  |  | if ! tmux has-session -t $selected_name 2> /dev/null; then | 
					
						
							|  |  |  |   tmux new-session -s $selected_name -c $selected -d | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-09-17 22:35:47 +01:00
										 |  |  | if [[ -z $TMUX ]]; then | 
					
						
							|  |  |  |   tmux attach-session -t $selected_name | 
					
						
							|  |  |  | else | 
					
						
							|  |  |  |   tmux switch-client -t $selected_name | 
					
						
							|  |  |  | fi |