Support custom fish prompt
Today I wrote myself a custom fish prompt. It's mostly what I'd like, but I'd like to finely tune it a bit. I'd like to create a separate repository to release this. In that repository, I'll explain why I wrote this.
This commit is contained in:
		
							parent
							
								
									549e56186b
								
							
						
					
					
						commit
						11d8336733
					
				
					 1 changed files with 66 additions and 15 deletions
				
			
		|  | @ -50,23 +50,74 @@ set fish_greeting "" | ||||||
| 
 | 
 | ||||||
| # Prompt | # Prompt | ||||||
| function fish_prompt | function fish_prompt | ||||||
|     set -l color_cwd |     # My custom prompt. | ||||||
|     set -l suffix |     # | ||||||
|     switch "$USER" |     # Design objectives: | ||||||
|         case root toor |     # - max-length <= 80 characters | ||||||
|             if set -q fish_color_cwd_root |     # - minimal | ||||||
|                 set color_cwd $fish_color_cwd_root |     # - no dependencies (well, you know what I mean) | ||||||
|             else |     # | ||||||
|                 set color_cwd $fish_color_cwd |     # Components | ||||||
|             end |     # - ssh connection | ||||||
|             set suffix '#' |     # - user | ||||||
|         case '*' |     # - host | ||||||
|             set color_cwd $fish_color_cwd |     # - git repo | ||||||
|             set suffix '>' |     # - git branch | ||||||
|  |     # - lambda character as prompt | ||||||
|  | 
 | ||||||
|  |     # Cache status before we overwrite it. | ||||||
|  |     set -l last_status $status | ||||||
|  | 
 | ||||||
|  |     # Colors | ||||||
|  |     set -l color_inactive (set_color red --bold) | ||||||
|  |     set -l color_active (set_color green --bold) | ||||||
|  |     set -l color_normal (set_color normal) | ||||||
|  | 
 | ||||||
|  |     # SSH information | ||||||
|  |     if set -q SSH_CLIENT; or set -q SSH_TTY | ||||||
|  |         echo -en "$color_active \bssh ✓ [$color_normal$USER@"(hostname)"$color_active]$color_normal" | ||||||
|  |     else | ||||||
|  |         echo -en "$color_inactive \bssh ✗ [$color_normal$USER@"(hostname)"$color_inactive]$color_normal" | ||||||
|     end |     end | ||||||
| 
 | 
 | ||||||
|     echo -n -s "$USER" @ (prompt_hostname) ' ' (set_color $color_cwd) (pwd) (set_color normal) |     # Separator | ||||||
|     echo -e "\n$suffix " |     echo -n " " | ||||||
|  | 
 | ||||||
|  |     # Git information | ||||||
|  |     set -l git_repo (git rev-parse --show-toplevel 2>/dev/null) | ||||||
|  |     set -l git_status $status | ||||||
|  |     set -l dir_parent (basename (realpath ..)) | ||||||
|  |     set -l dir_current (basename (realpath .)) | ||||||
|  |     if test $git_status -eq 0 | ||||||
|  |         set -l git_repo_name (basename (git rev-parse --show-toplevel)) | ||||||
|  |         set -l git_branch (git branch 2>/dev/null | grep '^\*' | cut -d' ' -f2-) | ||||||
|  |         echo -en "$color_active \bgit ✓ [$color_normal$git_branch$color_active|$color_normal$git_repo_name$color_active|$color_normal$dir_parent/$dir_current$color_active]$color_normal" | ||||||
|  |     else | ||||||
|  |         echo -en "$color_inactive \bgit ✗ [$color_normal$dir_parent/$dir_current$color_inactive]$color_normal" | ||||||
|  |     end | ||||||
|  | 
 | ||||||
|  |     # Newline | ||||||
|  |     echo | ||||||
|  | 
 | ||||||
|  |     # Handle root vs non-root | ||||||
|  |     if [ "$USER" = "root" ] | ||||||
|  |         set -g prompt_sigil "#" | ||||||
|  |     else | ||||||
|  |         set -g prompt_sigil "λ" | ||||||
|  |     end | ||||||
|  | 
 | ||||||
|  |     # TODO(wpcarro): For root directories like /tmp, there will not be a parent | ||||||
|  |     # directory. Support these directories. | ||||||
|  |     set -l time (date +"%T") | ||||||
|  |     if test $last_status -eq 0 | ||||||
|  |         # TODO(wpcarro): I'd prefer to use black here instead of white, but for | ||||||
|  |         # some reason white is black and black is invisible. | ||||||
|  |         set -l color_prompt (set_color white --bold) | ||||||
|  |         echo -n "$time$color_prompt $prompt_sigil$color_normal " | ||||||
|  |     else | ||||||
|  |         set -l color_prompt (set_color red --bold) | ||||||
|  |         echo -n "$time$color_prompt $prompt_sigil$color_normal " | ||||||
|  |     end | ||||||
| end | end | ||||||
| 
 | 
 | ||||||
| source ./functions.fish | source ./functions.fish | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue