2015-10-02 23:16:56 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								# Branch: displays the current Git or Mercurial branch fast.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								# Victor Torres <vpaivatorres@gmail.com>
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								# Oct 2, 2015
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								function branch_prompt_info() {
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  # Defines path as current directory
							 | 
						
					
						
							
								
									
										
										
										
											2015-12-14 17:39:26 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  local current_dir=$PWD
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-02 23:16:56 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  # While current path is not root path
							 | 
						
					
						
							
								
									
										
										
										
											2015-12-14 17:39:26 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								  while [[ $current_dir != '/' ]]
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-02 23:16:56 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  do
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    # Git repository
							 | 
						
					
						
							
								
									
										
										
										
											2015-12-14 17:39:26 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if [[ -d "${current_dir}/.git" ]]
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-02 23:16:56 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    then
							 | 
						
					
						
							
								
									
										
										
										
											2015-12-14 17:39:26 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      echo '±' ${"$(<"$current_dir/.git/HEAD")"##*/}
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-02 23:16:56 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      return;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    fi
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    # Mercurial repository
							 | 
						
					
						
							
								
									
										
										
										
											2015-12-14 17:39:26 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    if [[ -d "${current_dir}/.hg" ]]
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-02 23:16:56 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    then
							 | 
						
					
						
							
								
									
										
										
										
											2016-05-29 06:25:17 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								      if [[ -f "$current_dir/.hg/branch" ]]
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      then
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        echo '☿' $(<"$current_dir/.hg/branch")
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      else
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								        echo '☿ default'
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      fi
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-02 23:16:56 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								      return;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    fi
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    # Defines path as parent directory and keeps looking for :)
							 | 
						
					
						
							
								
									
										
										
										
											2015-12-14 17:39:26 -03:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    current_dir="${current_dir:h}"
							 | 
						
					
						
							
								
									
										
										
										
											2015-10-02 23:16:56 -03:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								  done
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |