view fish/config.fish @ 481:294cda8cf097

Enable mercurial shelve extension.
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 15 Feb 2020 22:21:40 -0800
parents 9df781913175
children
line wrap: on
line source


# Environment variables {{{

set -x fish_greeting 'Hello.'

# Figure out the OS
switch (uname)
case Linux FreeBSD NetBSD DragonFly
    set -x OS Linux
case Darwin
    set -x OS MacOSX
case Windows_NT
    set -x OS Windows_NT
case '*'
    set -x OS Unknown
end

# My own stuff.
if test -d $HOME/.local/bin
    set -x PATH $HOME/.local/bin $PATH
end
if test -d $HOME/bin
    set -x PATH $HOME/bin $PATH
end

# Standard stuff.
set -x EDITOR vim
#set -x TERM screen-256color-bce

# Python.
set -x VIRTUAL_ENV_DISABLE_PROMPT 1

# Detect Git/Hg availability.
if type -q git 
    set -x __local_has_git
end
if type -q hg
    set -x __local_has_hg
end

# Detect my own stuff.
if test -e $HOME/.local/bin/fast-hg-bookmark
    set -x __local_has_fast_hg_bookmark
end

# }}}

# Aliases {{{

# Run Tmux in UTF8 and 256 colours always.
alias tm 'tmux -u2'

# Switch directories.
alias ..    'cd ..'
alias ...   'cd ../..'
alias ....  'cd ../../..'
alias ..... 'cd ../../../..'

alias md 'mkdir -p'

# }}}

# Key Bindings {{{


# }}}

# Prompt {{{

set normal (set_color normal)
set magenta (set_color magenta)
set yellow (set_color yellow)
set green (set_color green)
set gray (set_color -o black)

function virtualenv_prompt
    if set -q VIRTUAL_ENV
        set_color -b blue white
        printf '(venv:%s)' (basename "$VIRTUAL_ENV")
        set_color normal
        printf ' '
    end
end

function prompt_char
    if set -q __local_has_git
        if git branch >/dev/null 2>/dev/null 
            printf '±' ; return
        end
    end
    if set -q __local_has_hg
        if hg root >/dev/null 2>/dev/null
            printf '☿' ; return
        end
        echo '○'
    end
end

function hg_prompt
    if set -q __local_has_hg 
        and set -q __local_has_fast_hg_bookmark
        set_color magenta
        printf '%s' (fast-hg-bookmark 2>/dev/null)
        set_color normal
    end
end

function git_prompt
    if set -q __local_has_git
        if git root >/dev/null 2>&1
            set_color normal
            printf ' on '
            set_color magenta
            printf '%s' (git currentbranch ^/dev/null)
            set_color green
            git_prompt_status
            set_color normal
        end
    end
end

function fish_prompt
    set last_status $status

    echo

    # 'username@hostname: '
    set_color magenta
    printf '%s' (whoami)
    set_color normal
    printf '@'
    set_color yellow
    printf '%s' (hostname|cut -d . -f 1)
    set_color normal
    printf ': '

    set_color $fish_color_cwd
    printf '%s' (prompt_pwd)
    set_color normal

    printf ' '
    prompt_char
    printf ' '

    hg_prompt

    echo

    virtualenv_prompt

    if test $last_status -eq 0
        set_color white -o
        printf '> '
    else
        set_color red -o
        printf '[%d] > ' $last_status
    end

    set_color normal
end

# }}}

# FZF {{{

if type -q fzf 
    function _gen_fzf_default_opts
        set -l base03 "234"
        set -l base02 "235"
        set -l base01 "240"
        set -l base00 "241"
        set -l base0 "244"
        set -l base1 "245"
        set -l base2 "254"
        set -l base3 "230"
        set -l yellow "136"
        set -l orange "166"
        set -l red "160"
        set -l magenta "125"
        set -l violet "61"
        set -l blue "33"
        set -l cyan "37"
        set -l green "64"

        # Solarized Dark color scheme for fzf
        set -x FZF_DEFAULT_OPTS "--color fg:-1,bg:-1,hl:$blue,fg+:$base2,bg+:$base02,hl+:$blue --color info:$yellow,prompt:$yellow,pointer:$base3,marker:$base3,spinner:$yellow"
        # Solarized Light color scheme for fzf
        #set -x FZF_DEFAULT_OPTS "--color fg:-1,bg:-1,hl:$blue,fg+:$base02,bg+:$base2,hl+:$blue --color info:$yellow,prompt:$yellow,pointer:$base03,marker:$base03,spinner:$yellow"
    end

    _gen_fzf_default_opts

    # Use fd, silver-searcher for searching if possible (in that order).
    if type -q fd
        set -x FZF_DEFAULT_COMMAND 'fd --type f'
    else if type -q ag
        set -x FZF_DEFAULT_COMMAND 'ag --nocolor -g ""'
    end

    # Use the default command for searching in Fisherman's FZF plugin.
    set -x FZF_FIND_FILE_COMMAND $FZF_DEFAULT_COMMAND
    set -U FZF_LEGACY_KEYBINDINGS 0
end

# }}}

# Local Settings {{{

if test -s $HOME/.config/fish/local.fish
    . $HOME/.config/fish/local.fish
end
#eval (/usr/local/bin/python -m virtualfish)

# }}}