Add script to get git status for all projects
This commit is contained in:
		
							parent
							
								
									90b64d8b50
								
							
						
					
					
						commit
						7b47fb4725
					
				
					 2 changed files with 72 additions and 0 deletions
				
			
		
							
								
								
									
										71
									
								
								.bin/projects-status
									
										
									
									
									
										Executable file
									
								
							
							
						
						
									
										71
									
								
								.bin/projects-status
									
										
									
									
									
										Executable file
									
								
							|  | @ -0,0 +1,71 @@ | |||
| #!/usr/bin/env bash | ||||
| 
 | ||||
| print_in_color() { | ||||
|   local color="$1" | ||||
|   shift | ||||
|   if [[ -z ${NO_COLOR+x} ]]; then | ||||
|     printf "$color%b\e[0m\n" "$*" | ||||
|   else | ||||
|     printf "%b\n" "$*" | ||||
|   fi | ||||
| } | ||||
| red() { print_in_color "\e[31m" "$*"; } | ||||
| green() { print_in_color "\e[32m" "$*"; } | ||||
| 
 | ||||
| projectsrc="$HOME/.config/projectsrc" | ||||
| 
 | ||||
| _print_project_status () { | ||||
|   project="$1" | ||||
|   cd "$HOME/$project" || return | ||||
| 
 | ||||
|   branch=$(git branch --show-current) | ||||
|   if [ -z "$branch" ]; then | ||||
|     return | ||||
|   fi | ||||
| 
 | ||||
|   remote="origin" | ||||
|   remotes=$(git remote) | ||||
|   if ! echo "$remotes" | grep -q "^$remote$"; then | ||||
|     remote=$(echo "$remotes" | head -n 1) | ||||
|   fi | ||||
| 
 | ||||
| 
 | ||||
|   ahead=$(git rev-list --count "$remote/$branch"..HEAD) | ||||
|   if [ "$ahead" -eq 0 ]; then | ||||
|     ahead=$(green "$ahead") | ||||
|   else | ||||
|     ahead=$(red "$ahead") | ||||
|     project=$(red "$project") | ||||
|   fi | ||||
| 
 | ||||
|   dirty=$(git status --porcelain | wc -l) | ||||
|   if [ "$dirty" -eq 0 ]; then | ||||
|     dirty=$(green "$dirty") | ||||
|   else | ||||
|     dirty=$(red "$dirty") | ||||
|     project=$(red "$project") | ||||
|   fi | ||||
| 
 | ||||
|   printf "%s\t%s\t%s\t%s\n" \ | ||||
|     "$project" \ | ||||
|     "$branch" \ | ||||
|     "$ahead" \ | ||||
|     "$dirty" | ||||
| } | ||||
| 
 | ||||
| _print_projects_status () { | ||||
|   while read -r next_project | ||||
|   do | ||||
|     if [ -z "$next_project" ]; then | ||||
|       continue | ||||
|     fi | ||||
| 
 | ||||
|     if [ ! -d "$HOME/$next_project" ]; then | ||||
|       continue | ||||
|     fi | ||||
| 
 | ||||
|     _print_project_status "$next_project" | ||||
|   done < "$projectsrc" | ||||
| } | ||||
| 
 | ||||
| _print_projects_status | column -t -s$'\t' --table-columns 'Project,Branch,Ahead,Dirty Files' | ||||
|  | @ -1,5 +1,6 @@ | |||
| .bin/host-backup-portalo | ||||
| .config/env.d/99-secrets | ||||
| .config/projectsrc | ||||
| .config/rclone/rclone.conf | ||||
| .local/share/atuin/key | ||||
| .ssh/config | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue