Skip to content

Instantly share code, notes, and snippets.

@tommorris
Last active November 12, 2024 15:07
Show Gist options
  • Save tommorris/738d8f2b7a10a0f03c42c3af5726afa5 to your computer and use it in GitHub Desktop.
Save tommorris/738d8f2b7a10a0f03c42c3af5726afa5 to your computer and use it in GitHub Desktop.
if you use fish and nerdfonts, you can plumb this function into your prompt to see which git host (github, codeberg, gitlab, bitbucket) you're using
function git_host_prompt --description "Use nerdfonts to show which Git repo host the origin is on"
set -l repo_info (command git rev-parse --git-dir --is-inside-git-dir --is-bare-repository --is-inside-work-tree HEAD 2>/dev/null)
test -n "$repo_info"
or return
set -l git_dir $repo_info[1]
set -l inside_gitdir $repo_info[2]
set -l bare_repo $repo_info[3]
set -l inside_worktree $repo_info[4]
set -q repo_info[5]
and set -l sha $repo_info[5]
test command git config --get-remote 2>/dev/null
or return
if test true = $inside_worktree
set -l remotes (command git remote 2>/dev/null)
test $status -eq 0
or return
set -l remotesCount (count remotes)
test 0 -ne $remotesCount
or return
if contains origin $remotes
set -f chosenRemote origin
else
set -f chosenRemote $remotes[1]
end
set -l remoteUrl (git remote get-url --push $chosenRemote)
if string match -q -r "github.com" $remoteUrl
echo ""
else if string match -q -r "gitlab.com" $remoteUrl
echo "󰮠"
else if string match -q -r "codeberg.org" $remoteUrl
echo ""
else if string match -q -r "bitbucket.org" $remoteUrl
echo ""
else
echo ""
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment