This commit is contained in:
kp2pml30 2024-07-05 23:21:18 +03:00
parent 67857e5ae8
commit 9b79d32c60
6 changed files with 201 additions and 6 deletions

View file

@ -0,0 +1,139 @@
# based on https://github.com/oh-my-fish/theme-eden/blob/master/LICENSE
function _git_branch_name
echo (command git symbolic-ref HEAD 2> /dev/null | sed -e 's|^refs/heads/||')
end
function _is_git_dirty
set resStr (timeout 0.2s git status -s --ignore-submodules=dirty 2> /dev/null)
set res $status
if [ $res = 0 ]
if [ "$resStr" = "" ]
echo "clean"
else
echo "dirty"
end
else if [ $res = 124 ]
echo "?"
else
echo "dirty"
end
end
## Function to show a segment
function _prompt_segment -d "Function to show a segment"
# Get colors
set -l bg $argv[1]
set -l fg $argv[2]
# Set 'em
set_color -b $bg
set_color $fg
# Print text
if [ -n "$argv[3]" ]
echo -n -s $argv[3]
end
# Reset
set_color -b normal
set_color normal
# Print padding
if [ (count $argv) = 4 ]
echo -n -s $argv[4]
end
end
function show_ssh_status -d "Function to show the ssh tag"
if test "$THEME_EDEN_HIDE_SSH_TAG" != 'yes'
if [ -n "$SSH_CLIENT" ]
if [ (id -u) = "0" ]
_prompt_segment red white "-SSH-" ' '
else
_prompt_segment blue white "-SSH-" ' '
end
end
end
end
function show_host -d "Show host & user name"
if [ (id -u) = "0" ]
echo -n (set_color red)
else
echo -n (set_color blue)
end
echo -n "$USER@"(hostname|cut -d . -f 1)' ' (set color normal)
end
function show_cwd -d "Function to show the current working directory"
if test "$theme_short_path" != 'yes' -a (prompt_pwd) != '~' -a (prompt_pwd) != '/'
set -l cwd (dirname (prompt_pwd))
test $cwd != '/'; and set cwd $cwd'/'
_prompt_segment normal cyan $cwd
end
set_color -o cyan
echo -n (basename (prompt_pwd))' '
set_color normal
end
function show_git_info -d "Show git branch and dirty state"
if [ (_git_branch_name) ]
set -l git_branch '['(_git_branch_name)']'
set_color -o
echo -ne " "
set dirty (_is_git_dirty)
switch "$dirty"
case "clean"
set_color -o green
echo -ne "$git_branch "
case "dirty"
set_color -o red
echo -ne "$git_branch× "
case '*'
set_color -o yellow
echo -ne "$git_branch? "
end
set_color normal
end
end
function show_times
if test $CMD_DURATION -ge 500
if test $CMD_DURATION -ge 60000
set -l duration_minutes (math "floor($CMD_DURATION / 60000)")
set -l duration_seconds (math "round(($CMD_DURATION % 60000) / 1000)")
printf "%02d:%02d " $duration_minutes $duration_seconds
else if test $CMD_DURATION -ge 1000
set -l duration_seconds (math "round($CMD_DURATION / 1000)")
echo -ns "$duration_seconds""s "
else
echo -ns "$CMD_DURATION""ms "
end
end
# Output the current time
echo -ne (date "+%H:%M:%S")
end
function show_prompt_char -d "Terminate with a nice prompt char"
echo ""
echo -n -s $normal '» '
end
function fish_prompt
set -l code $status
# use tput to move cursor to line start
echo -ne (tput cr)
show_ssh_status
show_host
show_cwd
show_git_info
show_times
if test $code != 0
echo -ns (set_color red) '[' $code ']'
end
show_prompt_char
end

View file

@ -0,0 +1,37 @@
function fish_right_prompt
return
# Last command status
set -l code $status
# https://github.com/fish-shell/fish-shell/issues/3476#issuecomment-256058730
# Save the cursor position, move it up one line, and move it to the right two spaces
tput sc; tput cuf 2
#if test $code != 0
# echo -ns (set_color red) '-' $code '- '
#end
set_color $fish_color_autosuggestion 2> /dev/null; or set_color 555
# Output the duration of the last command
if test $CMD_DURATION -ge 500
if test $CMD_DURATION -ge 60000
set -l duration_minutes (math "floor($CMD_DURATION / 60000)")
set -l duration_seconds (math "round(($CMD_DURATION % 60000) / 1000)")
printf "%02d:%02d " $duration_minutes $duration_seconds
else if test $CMD_DURATION -ge 1000
set -l duration_seconds (math "round($CMD_DURATION / 1000)")
echo "$duration_seconds""s "
else
echo "$CMD_DURATION""ms "
end
end
# Output the current time
echo (date "+%H:%M:%S")
# Restores the cursor position
tput rc
end