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
|
2022-02-07 12:48:26 +00:00
|
|
|
set -g "CURRENT_IP" (who -m | awk '{print $5}')
|
|
|
|
|
2021-09-30 21:51:15 +00:00
|
|
|
if test -z "$CURRENT_IP"
|
2021-10-03 22:17:44 +00:00
|
|
|
set -g "CURRENT_IP" (who | grep "$USER" | awk '{print $5}')
|
|
|
|
end
|
|
|
|
|
|
|
|
if test -z "$CURRENT_IP"
|
|
|
|
set -g "CURRENT_IP" (who | grep "$SUDO_USER" | awk '{print $5}')
|
2021-09-30 21:51:15 +00:00
|
|
|
end
|
|
|
|
|
2021-09-30 21:55:35 +00:00
|
|
|
if test -z "$CURRENT_IP"
|
2021-07-14 20:54:12 +00:00
|
|
|
set_color green
|
2022-02-07 12:48:26 +00:00
|
|
|
else if test "$CURRENT_IP" "=" "(:0)"
|
|
|
|
set_color brgreen
|
2022-02-07 12:53:02 +00:00
|
|
|
else if string match --regex --quiet '\(.+\)' "$CURRENT_IP" > /dev/null
|
2021-09-30 21:55:35 +00:00
|
|
|
set_color cyan
|
2022-02-07 12:48:26 +00:00
|
|
|
else
|
|
|
|
set_color green
|
2021-07-14 20:54:12 +00:00
|
|
|
end
|
2021-09-30 21:51:15 +00:00
|
|
|
|
2021-07-14 20:54:12 +00:00
|
|
|
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
|
2022-02-07 12:48:26 +00:00
|
|
|
if not test -e "$PWD"
|
2021-07-14 20:54:12 +00:00
|
|
|
set_color brblack
|
2022-02-07 12:48:26 +00:00
|
|
|
else if not test -x .
|
|
|
|
set_color white
|
2021-07-14 20:54:12 +00:00
|
|
|
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
|