Skip to content

Instantly share code, notes, and snippets.

@sostenesapollo
Created May 15, 2026 09:53
Show Gist options
  • Select an option

  • Save sostenesapollo/2f250dc40c3733903f9340e4b76a8f24 to your computer and use it in GitHub Desktop.

Select an option

Save sostenesapollo/2f250dc40c3733903f9340e4b76a8f24 to your computer and use it in GitHub Desktop.
Fish Prompt
function fish_prompt --description 'Uma linha de info + linha do ➜'
set -l laststatus $status
if test $laststatus -eq 127
and set -q __fish_autocd_ok
set laststatus 0
end
set -e __fish_autocd_ok
set -l home_norm (string trim -r / $HOME)
set -l pwd_norm (string trim -r / $PWD)
set -l dir_display (basename $PWD)
test "$pwd_norm" = "$home_norm"
and set dir_display '~'
set -l git_branch_name ''
if command git -C "$PWD" rev-parse --git-dir 2>/dev/null >/dev/null
# Nome curto de branch (nunca refs/heads/…)
set git_branch_name (command git -C "$PWD" symbolic-ref -q --short HEAD 2>/dev/null)
if test -z "$git_branch_name"
set git_branch_name (command git -C "$PWD" describe --tags --always --abbrev=8 HEAD 2>/dev/null)
end
test -z "$git_branch_name"
and set git_branch_name unknown
# Tira qualquer prefixo refs/…
set git_branch_name (string replace -r '^refs/heads/' '' -- $git_branch_name)
set git_branch_name (string replace -r '^refs/remotes/[^/]+/' '' -- $git_branch_name)
set -l parts (string split '/' -- $git_branch_name)
if test (count $parts) -ge 3
set -l last $parts[-1]
if contains -- $last main master develop
set parts $parts[1..-2]
set git_branch_name (string join '/' $parts)
end
end
if test (string length -- $git_branch_name) -gt 44
set git_branch_name (string sub --start 1 --length 41 -- $git_branch_name)''
end
set -l staged 0
set -l unstaged 0
set -l untracked 0
for line in (command git -C "$PWD" status --porcelain 2>/dev/null)
set -l fc (string sub --start 1 --length 1 -- $line)
set -l sc (string sub --start 2 --length 1 -- $line)
if test "$fc$sc" = '??'
set untracked 1
continue
end
test "$fc" != ' '
and set staged 1
if test "$sc" != ' '
and test "$sc" != '?'
set unstaged 1
end
end
set -l gitmarks ''
test $staged -eq 1
and set gitmarks (string join '' $gitmarks '📦')
test $unstaged -eq 1
and set gitmarks (string join '' $gitmarks '')
test $untracked -eq 1
and set gitmarks (string join '' $gitmarks '👻')
set -l br_col (set_color c5b4e8)
# symbolic-ref imprime o ref em stdout; sem >/dev/null aparece refs/heads/… no prompt
if not command git -C "$PWD" symbolic-ref -q HEAD >/dev/null 2>/dev/null
set br_col (set_color d4c4f0)
end
# Um printf contínuo até a branch; depois marks + node + newline (uma linha lógica)
printf '%s%s%s %s%s%s 🌱 %s%s%s' \
(set_color brcyan) $dir_display (set_color normal) \
(set_color eaeaea) 'on' (set_color normal) \
$br_col $git_branch_name (set_color normal)
if test -n "$gitmarks"
printf ' %s[%s]%s' (set_color ff8fab) "$gitmarks" (set_color normal)
end
if command -q node
set -l nv (command node -v 2>/dev/null)
test -n "$nv"
and printf ' %s%s%s' (set_color 9ef0a8) "node $nv" (set_color normal)
end
printf '\n'
else
printf '%s%s%s' (set_color brcyan) $dir_display (set_color normal)
if command -q node
set -l nv (command node -v 2>/dev/null)
test -n "$nv"
and printf ' %s%s%s' (set_color 9ef0a8) "node $nv" (set_color normal)
end
printf '\n'
end
if test $laststatus -eq 0
printf '%s➜ %s' (set_color 7bed9f) (set_color normal)
else
printf '%s➜ %s' (set_color ff6b6b) (set_color normal)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment