From 994f5c500b3529d524f36d3bb9f93c1121da1f51 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Thu, 5 Jul 2018 22:30:52 +0200 Subject: [PATCH] update nim.fish sample prompt (#5066) * update nim.fish sample prompt - Use an helper function to wrap informations - Add VIRTUAL_ENV infos, if any - Add __fish_git_prompt, wrapped for the theme - Add comments - Remove ASCII failback symbols for tty (no more useful for me, but if someone really needs it, just ask) * fish.nim: test -n __fish_git_prompt --- .../tools/web_config/sample_prompts/nim.fish | 109 +++++++++++------- 1 file changed, 66 insertions(+), 43 deletions(-) diff --git a/share/tools/web_config/sample_prompts/nim.fish b/share/tools/web_config/sample_prompts/nim.fish index 0e4e548f2..b935f8413 100644 --- a/share/tools/web_config/sample_prompts/nim.fish +++ b/share/tools/web_config/sample_prompts/nim.fish @@ -1,19 +1,54 @@ # name: Nim # author: Guilhem "Nim" Saurel − https://github.com/nim65s/dotfiles/ +# 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 +# - the current git status, if any, with __fish_git_prompt +# - 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] +# │ 2 15054 0% arrêtée sleep 100000 +# │ 1 15048 0% arrêtée sleep 100000 +# ╰─>$ echo there + +set __fish_git_prompt_showupstream auto + +function _nim_prompt_wrapper + set retc $argv[1] + set field_name $argv[2] + set field_value $argv[3] + + 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 + function fish_prompt and set retc green or set retc red - tty | string match -q -r tty - and set tty tty - or set tty pts set_color $retc - if [ $tty = tty ] - echo -n .- - else - echo -n '┬─' - end + echo -n '┬─' set_color -o green echo -n [ if test "$USER" = root -o "$USER" = toor @@ -31,53 +66,41 @@ function fish_prompt end echo -n (prompt_hostname) set_color -o white - #echo -n :(prompt_pwd) - echo -n :(pwd|sed "s=$HOME=~=") + echo -n :(prompt_pwd) set_color -o green echo -n ']' - set_color normal - set_color $retc - if [ $tty = tty ] - echo -n '-' - else - echo -n '─' - end - set_color -o green - echo -n '[' - set_color normal - set_color $retc - echo -n (date +%X) - set_color -o green - echo -n ] - if type -q acpi - if [ (acpi -a 2> /dev/null | string match -r off) ] - echo -n '─[' - set_color -o red - echo -n (acpi -b|cut -d' ' -f 4-) - set_color -o green - echo -n ']' - end - end + # Date + _nim_prompt_wrapper $retc '' (date +%X) + + # Virtual Environment + set -q VIRTUAL_ENV + and _nim_prompt_wrapper $retc V (basename "$VIRTUAL_ENV") + + # git + set prompt_git (__fish_git_prompt | string trim -c ' ()') + test -n "$prompt_git" + and _nim_prompt_wrapper $retc G $prompt_git + + # Battery status + type -q acpi + and test (acpi -a 2> /dev/null | string match -r off) + and _nim_prompt_wrapper $retc B (acpi -b | cut -d' ' -f 4-) + + # New line echo + + # Background jobs set_color normal for job in (jobs) set_color $retc - if [ $tty = tty ] - echo -n '; ' - else - echo -n '│ ' - end + echo -n '│ ' set_color brown echo $job end set_color normal set_color $retc - if [ $tty = tty ] - echo -n "'->" - else - echo -n '╰─>' - end + echo -n '╰─>' set_color -o red echo -n '$ ' set_color normal