2012-09-06 16:30:26 +08:00
|
|
|
|
# name: Nim
|
|
|
|
|
# author: Guilhem "Nim" Saurel − https://github.com/nim65s/dotfiles/
|
|
|
|
|
|
|
|
|
|
function fish_prompt
|
2019-01-08 00:24:17 +08:00
|
|
|
|
# This prompt shows:
|
|
|
|
|
# - green lines if the last return command is OK, red otherwise
|
|
|
|
|
# - your user name, in red if root or yellow otherwise
|
|
|
|
|
# - your hostname, in cyan if ssh or blue otherwise
|
|
|
|
|
# - the current path (with prompt_pwd)
|
|
|
|
|
# - date +%X
|
|
|
|
|
# - the current virtual environment, if any
|
2019-01-26 20:36:54 +08:00
|
|
|
|
# - the current git status, if any, with fish_git_prompt
|
2019-01-08 00:24:17 +08:00
|
|
|
|
# - the current battery state, if any, and if your power cable is unplugged, and if you have "acpi"
|
|
|
|
|
# - current background jobs, if any
|
|
|
|
|
|
|
|
|
|
# It goes from:
|
|
|
|
|
# ┬─[nim@Hattori:~]─[11:39:00]
|
|
|
|
|
# ╰─>$ echo here
|
|
|
|
|
|
|
|
|
|
# To:
|
|
|
|
|
# ┬─[nim@Hattori:~/w/dashboard]─[11:37:14]─[V:django20]─[G:master↑1|●1✚1…1]─[B:85%, 05:41:42 remaining]
|
2020-06-17 23:55:23 +08:00
|
|
|
|
# │ 2 15054 0% arrêtée sleep 100000
|
|
|
|
|
# │ 1 15048 0% arrêtée sleep 100000
|
2019-01-08 00:24:17 +08:00
|
|
|
|
# ╰─>$ echo there
|
|
|
|
|
|
2019-07-07 12:28:48 +08:00
|
|
|
|
set -l retc red
|
|
|
|
|
test $status = 0; and set retc green
|
|
|
|
|
|
2019-01-08 00:24:17 +08:00
|
|
|
|
set -q __fish_git_prompt_showupstream
|
|
|
|
|
or set -g __fish_git_prompt_showupstream auto
|
|
|
|
|
|
|
|
|
|
function _nim_prompt_wrapper
|
|
|
|
|
set retc $argv[1]
|
2020-05-15 13:56:06 +08:00
|
|
|
|
set -l field_name $argv[2]
|
|
|
|
|
set -l field_value $argv[3]
|
2019-01-08 00:24:17 +08:00
|
|
|
|
|
|
|
|
|
set_color normal
|
|
|
|
|
set_color $retc
|
|
|
|
|
echo -n '─'
|
|
|
|
|
set_color -o green
|
|
|
|
|
echo -n '['
|
|
|
|
|
set_color normal
|
|
|
|
|
test -n $field_name
|
|
|
|
|
and echo -n $field_name:
|
|
|
|
|
set_color $retc
|
|
|
|
|
echo -n $field_value
|
|
|
|
|
set_color -o green
|
|
|
|
|
echo -n ']'
|
|
|
|
|
end
|
2012-09-06 16:30:26 +08:00
|
|
|
|
|
|
|
|
|
set_color $retc
|
2018-07-06 04:30:52 +08:00
|
|
|
|
echo -n '┬─'
|
2012-09-06 16:30:26 +08:00
|
|
|
|
set_color -o green
|
|
|
|
|
echo -n [
|
2020-06-17 23:55:23 +08:00
|
|
|
|
|
2020-09-05 15:02:32 +08:00
|
|
|
|
if functions -q fish_is_root_user; and fish_is_root_user
|
2012-09-06 16:30:26 +08:00
|
|
|
|
set_color -o red
|
|
|
|
|
else
|
|
|
|
|
set_color -o yellow
|
|
|
|
|
end
|
2020-06-17 23:55:23 +08:00
|
|
|
|
|
2012-09-06 16:30:26 +08:00
|
|
|
|
echo -n $USER
|
|
|
|
|
set_color -o white
|
|
|
|
|
echo -n @
|
2020-06-17 23:55:23 +08:00
|
|
|
|
|
2021-11-23 21:45:28 +08:00
|
|
|
|
if test -z "$SSH_CLIENT"
|
2012-09-06 16:30:26 +08:00
|
|
|
|
set_color -o blue
|
|
|
|
|
else
|
|
|
|
|
set_color -o cyan
|
|
|
|
|
end
|
2020-06-17 23:55:23 +08:00
|
|
|
|
|
2016-10-24 06:02:14 +08:00
|
|
|
|
echo -n (prompt_hostname)
|
2012-09-06 16:30:26 +08:00
|
|
|
|
set_color -o white
|
2018-07-06 04:30:52 +08:00
|
|
|
|
echo -n :(prompt_pwd)
|
2012-09-06 16:30:26 +08:00
|
|
|
|
set_color -o green
|
|
|
|
|
echo -n ']'
|
2016-11-02 10:19:45 +08:00
|
|
|
|
|
2018-07-06 04:30:52 +08:00
|
|
|
|
# Date
|
|
|
|
|
_nim_prompt_wrapper $retc '' (date +%X)
|
|
|
|
|
|
2020-03-25 00:07:10 +08:00
|
|
|
|
# Vi-mode
|
|
|
|
|
# The default mode prompt would be prefixed, which ruins our alignment.
|
2020-03-27 03:45:40 +08:00
|
|
|
|
function fish_mode_prompt
|
|
|
|
|
end
|
2020-06-17 23:55:23 +08:00
|
|
|
|
|
2020-03-25 00:07:10 +08:00
|
|
|
|
if test "$fish_key_bindings" = fish_vi_key_bindings
|
|
|
|
|
or test "$fish_key_bindings" = fish_hybrid_key_bindings
|
|
|
|
|
set -l mode
|
|
|
|
|
switch $fish_bind_mode
|
|
|
|
|
case default
|
|
|
|
|
set mode (set_color --bold red)N
|
|
|
|
|
case insert
|
|
|
|
|
set mode (set_color --bold green)I
|
|
|
|
|
case replace_one
|
|
|
|
|
set mode (set_color --bold green)R
|
|
|
|
|
echo '[R]'
|
|
|
|
|
case replace
|
|
|
|
|
set mode (set_color --bold cyan)R
|
|
|
|
|
case visual
|
|
|
|
|
set mode (set_color --bold magenta)V
|
|
|
|
|
end
|
|
|
|
|
set mode $mode(set_color normal)
|
|
|
|
|
_nim_prompt_wrapper $retc '' $mode
|
|
|
|
|
end
|
|
|
|
|
|
2018-07-06 04:30:52 +08:00
|
|
|
|
# Virtual Environment
|
2020-01-06 19:39:09 +08:00
|
|
|
|
set -q VIRTUAL_ENV_DISABLE_PROMPT
|
|
|
|
|
or set -g VIRTUAL_ENV_DISABLE_PROMPT true
|
2018-07-06 04:30:52 +08:00
|
|
|
|
set -q VIRTUAL_ENV
|
2023-01-26 03:04:57 +08:00
|
|
|
|
and _nim_prompt_wrapper $retc V (path basename "$VIRTUAL_ENV")
|
2018-07-06 04:30:52 +08:00
|
|
|
|
|
|
|
|
|
# git
|
2021-04-01 20:06:52 +08:00
|
|
|
|
set -l prompt_git (fish_git_prompt '%s')
|
2018-07-06 04:30:52 +08:00
|
|
|
|
test -n "$prompt_git"
|
|
|
|
|
and _nim_prompt_wrapper $retc G $prompt_git
|
|
|
|
|
|
|
|
|
|
# Battery status
|
|
|
|
|
type -q acpi
|
2024-09-17 20:44:05 +08:00
|
|
|
|
and acpi -a 2>/dev/null | string match -rq off
|
2018-07-06 04:30:52 +08:00
|
|
|
|
and _nim_prompt_wrapper $retc B (acpi -b | cut -d' ' -f 4-)
|
|
|
|
|
|
|
|
|
|
# New line
|
2012-09-06 16:30:26 +08:00
|
|
|
|
echo
|
2018-07-06 04:30:52 +08:00
|
|
|
|
|
|
|
|
|
# Background jobs
|
2012-09-06 16:30:26 +08:00
|
|
|
|
set_color normal
|
2020-06-17 23:55:23 +08:00
|
|
|
|
|
2012-09-06 16:30:26 +08:00
|
|
|
|
for job in (jobs)
|
|
|
|
|
set_color $retc
|
2018-07-06 04:30:52 +08:00
|
|
|
|
echo -n '│ '
|
2012-09-06 16:30:26 +08:00
|
|
|
|
set_color brown
|
|
|
|
|
echo $job
|
|
|
|
|
end
|
2020-06-17 23:55:23 +08:00
|
|
|
|
|
2012-09-06 16:30:26 +08:00
|
|
|
|
set_color normal
|
|
|
|
|
set_color $retc
|
2018-07-06 04:30:52 +08:00
|
|
|
|
echo -n '╰─>'
|
2012-09-06 16:30:26 +08:00
|
|
|
|
set_color -o red
|
|
|
|
|
echo -n '$ '
|
|
|
|
|
set_color normal
|
|
|
|
|
end
|