Skip to content

Instantly share code, notes, and snippets.

@brlodi
Created October 8, 2019 20:15
Show Gist options
  • Save brlodi/f8188701cdf19c8b542492bdfcd5d858 to your computer and use it in GitHub Desktop.
Save brlodi/f8188701cdf19c8b542492bdfcd5d858 to your computer and use it in GitHub Desktop.
A WIP snapshot of a native-fish Powerline style prompt I was toying with. Not done by any means, but saving for posterity while I explore alternatives
# Color reference
# fish_color_normal, the default color
# fish_color_command, the color for commands
# fish_color_quote, the color for quoted blocks of text
# fish_color_redirection, the color for IO redirections
# fish_color_end, the color for process separators like ';' and '&'
# fish_color_error, the color used to highlight potential errors
# fish_color_param, the color for regular command parameters
# fish_color_comment, the color used for code comments
# fish_color_match, the color used to highlight matching parenthesis
# fish_color_selection, the color used when selecting text (in vi visual mode)
# fish_color_search_match, used to highlight history search matches and the selected pager item (must be a background)
# fish_color_operator, the color for parameter expansion operators like '*' and '~'
# fish_color_escape, the color used to highlight character escapes like '\n' and '\x70'
# fish_color_cwd, the color used for the current working directory in the default prompt
# fish_color_autosuggestion, the color used for autosuggestions
# fish_color_user, the color used to print the current username in some of fish default prompts
# fish_color_host, the color used to print the current host system in some of fish default prompts
# fish_color_cancel, the color for the '^C' indicator on a canceled command
function __glyph -a name -d 'Print NerdFont glyph by name'
switch "$name"
# Separators
case 'arrow_right'; printf '\uE0B0'
case 'arrow_right_o'; printf '\uE0B1'
case 'arrow_left'; printf '\uE0B2'
case 'arrow_left_o'; printf '\uE0B3'
case 'slash_top_left_bottom_right'; printf '\uE0B8 '
case 'slash_top_left_bottom_right_o'; printf '\uE0B9 '
case 'slash_bottom_left_top_right'; printf '\uE0BA '
case 'slash_bottom_left_top_right_o'; printf '\uE0BB '
case 'slash_top_right_bottom_left'; printf '\uE0BC '
case 'slash_top_right_bottom_left_o'; printf '\uE0BD '
case 'slash_bottom_right_top_left'; printf '\uE0BE '
case 'slash_bottom_right_top_left_o'; printf '\uE0B9 '
# VCS
case 'branch'; printf '\uE0A0'
# Misc.
case 'user'; printf '\uf007'
end
end
function __prompt_start_segment -Sa bg fg -d 'Start a prompt segment'
set -q __prompt_separator; or set -l __prompt_separator 'arrow_right'
set_color normal
switch "$__prompt_current_bg"
case ''
set_color -b $bg $fg $argv[3..-1]
case "$bg"
set_color -b $bg $fg $argv[3..-1]
echo -ns (__glyph "$__prompt_separator"_o)
case '*'
set_color -b $bg "$__prompt_current_bg"
echo -ns (__glyph "$__prompt_separator")
set_color -b $bg $fg $argv[3..-1]
end
set __prompt_current_bg $bg
end
function __prompt_start_custom_segment -Sa sep bg fg -d 'Start a prompt segment with a custom separator'
set -l __prompt_separator "$sep"
__prompt_start_segment $bg $fg $argv[4..-1]
end
function __prompt_change_segment_fg -Sa fg -d 'Change color of active segment'
set_color normal
set_color -b $__prompt_current_bg $fg $argv[2..-1]
end
function __prompt_finish_segments -Sa sep -d 'Close open prompt segments'
set -q sep; or set -l sep 'arrow_right'
if test -n "$__prompt_current_bg"
set_color normal
set_color $__prompt_current_bg
echo -ns (__glyph 'arrow_right')
end
set_color normal
set __prompt_current_bg
end
function __prompt_is_remote
set -q SSH_CONNECTION; or set -q SSH_TTY; or set -q SSH_CLIENT
echo $status
end
function __prompt_hostname
if test "x$PROMPT_HOST_FQDN" = 'xtrue'
echo $hostname
else
echo (string split "." "$hostname")[1]
end
end
function __prompt_show_user
if test "x$PROMPT_SHOW_USER" = 'xalways'
or test "x$PROMPT_SHOW_USER" = 'xremote' -a (__prompt_is_remote) -eq 0
or test "x$PROMPT_SHOW_USER" != 'xnever' -a "x$USER" != "x$PROMPT_DEFAULT_USER"
return 0
end
return 1
end
function __prompt_show_hostname
if test "x$PROMPT_SHOW_HOSTNAME" = 'xalways'
or test "x$PROMPT_SHOW_HOSTNAME" = 'xremote' -a (__prompt_is_remote) -eq 0
return 0
end
return 1
end
# function __prompt_conditional_user_hostname_separator
# set -l sep ""
# if test "x$PROMPT_SHOW_USER" = 'xalways'
# or test "x$PROMPT_SHOW_USER" = 'xremote' -a (__prompt_is_remote) -eq 0
# or test "x$PROMPT_SHOW_USER" != 'xnever' -a "x$USER" != "x$PROMPT_DEFAULT_USER"
# if test "x$PROMPT_SHOW_HOSTNAME" = 'xalways'
# or test "x$PROMPT_SHOW_HOSTNAME" = 'xremote' -a (__prompt_is_remote) -eq 0
# set sep "@"
# end
# end
# printf $sep
# end
function fish_prompt
# Display username and hostname if necessary
if __prompt_show_user; or __prompt_show_hostname
__prompt_start_segment brgreen white
if __prompt_show_user
__prompt_change_segment_fg blue --bold
echo -n "$USER"
end
if __prompt_show_user; and __prompt_show_hostname
__prompt_change_segment_fg white
echo -n "@"
end
if __prompt_show_hostname
__prompt_change_segment_fg green --bold
echo -n (__prompt_hostname)
end
end
# Display the current working directory
set -l prompt_segments (string split -n '/' (prompt_pwd))
if not set -q prompt_segments[1]
set prompt_segments '/'
end
if test (count $prompt_segments) -eq 1
__prompt_start_segment bryellow white --bold
echo -ns " $prompt_segments"
else
for i in (seq 1 (count $prompt_segments))
if test "$i" -eq 1
__prompt_start_segment bryellow white
else if test "$i" -eq (count $prompt_segments)
__prompt_start_custom_segment 'slash_top_right_bottom_left' bryellow white --bold
else
__prompt_start_custom_segment 'slash_top_right_bottom_left' bryellow white
end
echo -n $prompt_segments[$i]
end
end
echo -ns ' '
__prompt_finish_segments
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment