Skip to content

Instantly share code, notes, and snippets.

@tos-kamiya
Last active March 21, 2022 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tos-kamiya/dca411638ba6eb766489de515b2ef402 to your computer and use it in GitHub Desktop.
Save tos-kamiya/dca411638ba6eb766489de515b2ef402 to your computer and use it in GitHub Desktop.
show execution time of commands and git branch, fish shell
function fish_prompt
# show execution time
set hh (math -s0 "$CMD_DURATION / 3600000")
set mm (math -s0 "$CMD_DURATION % 3600000 / 60000")
set ss (math -s0 "$CMD_DURATION % 60000 / 1000")
set ms (math -s3 "$CMD_DURATION / 1000")
set t ""
if [ $hh -gt 0 ]
set t "$t$hh""h "
end
if [ $mm -gt 0 ]; or [ -n $t ]
set t "$t$mm""m "
end
if [ $ss -gt 0 ]; or [ -n $t ]
set t "$t$ss""s"
end
if [ -z $t ]
set t "$t$ms""s"
end
printf (set_color $fish_pager_color_description --bold)"\u2357 \u23f1 $t"(set_color normal)"\n"
# show current directory / git branch
printf (set_color -o)'%s '(set_color normal)(set_color $fish_color_cwd)'%s'(set_color normal)' ' (prompt_hostname) (prompt_pwd)
set -l git_dir (git rev-parse --git-dir 2> /dev/null)
if test -n "$git_dir"
set -l git_branch (git branch 2> /dev/null | sed -n '/\* /s///p')
printf (set_color -d)'%s\u2d56'(set_color normal)' ' "$git_branch"
end
printf '\u2771 '
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment