1
Fork 0
mirror of https://github.com/Steffo99/config-fish.git synced 2024-10-16 14:27:34 +00:00
config-fish/functions/fish_prompt.fish

82 lines
1.3 KiB
Fish
Raw Normal View History

2020-07-21 14:15:44 +00:00
function fish_prompt
2021-07-14 20:54:12 +00:00
# Save variables before they are gone
2020-07-21 14:15:44 +00:00
set "STATUS" $status
2021-07-14 20:54:12 +00:00
set "UID" (id -u)
2020-07-21 14:15:44 +00:00
2021-07-14 20:54:12 +00:00
# User name
2021-07-15 00:57:25 +00:00
switch ~
2021-07-15 00:58:18 +00:00
case "/root"
2021-07-14 20:54:12 +00:00
# Root
2020-07-21 14:15:44 +00:00
set_color brred
2021-07-15 00:57:25 +00:00
case "/srv/*"
2021-07-14 20:54:12 +00:00
# System account
2020-07-21 14:15:44 +00:00
set_color brpurple
2021-07-15 00:57:25 +00:00
case "/home/*"
2021-07-14 20:54:12 +00:00
# Regular user
set_color brgreen
2021-07-15 00:57:25 +00:00
case "*"
# Temporary account
set_color brcyan
2020-07-21 14:15:44 +00:00
end
echo -n "$USER"
2021-07-14 20:54:12 +00:00
# Jobs
set "JOBSCOUNT" (jobs | count)
if test $JOBSCOUNT -ge 1
set_color brmagenta
echo -n "&$JOBSCOUNT"
end
2020-07-21 14:15:44 +00:00
2021-07-14 20:54:12 +00:00
# @
set_color normal
echo -n "@"
# Hostname
2021-07-14 22:22:20 +00:00
if test (who am i | awk '{print $5}') = "(:0)"
2021-07-14 20:54:12 +00:00
set_color green
else
set_color cyan
end
echo -n (prompt_hostname)
# :
2020-07-21 14:15:44 +00:00
set_color normal
2021-07-14 20:54:12 +00:00
echo -n ":"
2020-07-21 14:15:44 +00:00
2021-07-14 20:54:12 +00:00
# Current working directory
if not test -x .
set_color brblack
else if not test -r .
set_color white
else if not test -w .
set_color yellow
else
set_color brblue
end
2020-07-21 14:15:44 +00:00
echo -n (prompt_pwd)
2021-07-14 20:54:12 +00:00
# Exit status
2020-07-21 14:15:44 +00:00
if test $STATUS -ne 0
set_color brred
2021-07-14 20:54:12 +00:00
echo -n "[$STATUS]"
end
set_color normal
# Dollar
set_color --bold white
if test "$UID" -eq 0
echo -n "# "
2020-07-21 14:15:44 +00:00
else
2021-07-14 20:54:12 +00:00
echo -n "\$ "
2020-07-21 14:15:44 +00:00
end
set_color normal
end