big update

This commit is contained in:
Bruno Carlin 2017-04-14 18:38:15 +02:00
parent 7a45a85686
commit 346a209c13
9 changed files with 133 additions and 11 deletions

View file

@ -1,7 +1,8 @@
## PATH
set -x PATH $PATH ~/.local/bin ~/.go/bin
set -x EDITOR nano
set -x EDITOR vim
set -x VIRTUAL_ENV_DISABLE_PROMPT true
## SSH init
set -x SSH_AUTH_SOCK $XDG_RUNTIME_DIR/ssh-agent.socket
@ -15,6 +16,8 @@ end
## Go utils
set -x GOPATH ~/.go
## aliases
alias jsonpp "python -mjson.tool"
function bind_bang
switch (commandline -t)[-1]
@ -28,3 +31,25 @@ end
function fish_user_key_bindings
bind ! bind_bang
end
function __autovenv --on-variable PWD
set -l base $PWD
set -l has_venv false
while test $base != '/'
if test -f $base/.venv/bin/activate.fish
set has_venv $base/.venv
break
end
set base (dirname $base)
end
if test -n "$VIRTUAL_ENV" -a $has_venv = 'false'
deactivate
else if test $has_venv != 'false'
if test -z "$VIRTUAL_ENV" -o "$VIRTUAL_ENV" != "$has_env"
source "$has_venv/bin/activate.fish"
end
end
end

View file

@ -0,0 +1,7 @@
function __autovenv --on-variable PWD
echo PWD has changed to $PWD
set -l base $PWD
if test -f $base/.venv/bin/activate.fish
source $base/.venv/bin/activate.fish
end
end

View file

@ -14,23 +14,83 @@ function __bcarlin_prompt_suffix
set color_suffix $fish_color_cwd
end
echo -n -s (set_color $color_suffix --bold) "$suffix" (set_color normal)
echo -n -s ' ' (set_color $color_suffix --bold) "$suffix" (set_color normal) ' '
end
function __bcarlin_prompt_git
set -l git_branch (git rev-parse --abbrev-ref HEAD)
set -l git_infos (git status --porcelain --branch ^/dev/null )
if test $status -ne 0
echo -n -s ''
return
end
echo -n -s (set_color blue) ± (set_color normal) '('
set -l git_branch (echo $git_infos | grep '##' | sed -e 's|## \([^\.]\+\).*|\1|')
set -l has_untracked false
set -l staged_count 0
set -l changed_count 0
set -l conflict_count 0
set -l staged_count 0
set -l behind (echo $git_infos | grep '##' | grep behind | sed -e 's|.*behind \([0-9]\+\).*|\1|')
set -l ahead (echo $git_infos | grep '##' | grep ahead | sed -e 's|.*ahead \([0-9]\+\).*|\1|')
for line in $git_infos
set -l flags (echo $line | cut -c '-2')
set flag1 (string sub -l 1 $flags)
set flag2 (string sub -s 2 -l 1 $flags)
if test $flags = '??'
set has_untracked true
continue
end
if test $flag1 = 'U' -o $flag2 = 'U'
set conflict_count (math $conflict_count + 1)
continue
end
if contains $flag1 'M' 'A' 'C' 'R' 'D'
set staged_count (math $staged_count + 1)
end
if contains $flag2 'M' 'A' 'R' 'C' 'D'
set changed_count (math $changed_count + 1)
end
end
echo -n -s ' ' (set_color blue) ± (set_color normal) '('
echo -n -s (set_color red --bold) $git_branch (set_color normal)
if test (math $staged_count + $conflict_count + $changed_count) -ne 0 -o $has_untracked = true
echo -n -s '|'
test -n "$behind"; and echo -s -n (set_color red) "$behind" (set_color normal)
test -n "$ahead"; and echo -s -n (set_color green) "$ahead" (set_color normal)
test $conflict_count -ne 0; and echo -s -n (set_color red) "$conflict_count" (set_color normal)
test $staged_count -ne 0; and echo -s -n (set_color red) "$staged_count" (set_color normal)
test $changed_count -ne 0; and echo -s -n (set_color blue) "$changed_count" (set_color normal)
test $has_untracked = true; and echo -s -n '…'
else
echo -n -s (set_color green --bold) "✔" (set_color normal)
end
echo -n -s ')'
end
function fish_prompt --description 'Write out the prompt'
set -l _pwd (set_color $fish_color_cwd) (prompt_pwd)
echo -n -s "$USER" @ (prompt_hostname) ' ' $_pwd ' ' (__bcarlin_prompt_git) ' ' (__bcarlin_prompt_suffix) ' '
function __bcarlin_prompt_venv
if test -n "$VIRTUAL_ENV"
set -l venv_name (basename $VIRTUAL_ENV)
if test $venv_name = '.venv'
set venv_name (basename (dirname $VIRTUAL_ENV))
end
echo -n -s (set_color blue --bold) "(" $venv_name ") " (set_color normal)
end
end
function fish_prompt --description 'Write out the prompt'
set -l _pwd (set_color $fish_color_cwd) (prompt_pwd)
echo -n -s (__bcarlin_prompt_venv)
echo -n -s "$USER" @ (prompt_hostname) ' ' $_pwd
echo -n -s (__bcarlin_prompt_git)
echo -n -s (__bcarlin_prompt_suffix)
end