~gpanders/dotfiles

67485cdda638a7b21aecf3fbab4140b712b496a9 — Greg Anders 1 year, 7 months ago 5629911
Change back to fzf from fzy
16 files changed, 28 insertions(+), 177 deletions(-)

M fish/.config/fish/conf.d/fzf.fish
D fish/.config/fish/conf.d/ual.fish
M fish/.config/fish/fisher/fishfile
D fish/.config/fish/functions/__fzy.fish
D fish/.config/fish/functions/__fzy_history.fish
D fish/.config/fish/functions/d.fish
M fish/.config/fish/functions/fish_user_key_bindings.fish
D fish/.config/fish/functions/fmail.fish
M fish/.config/fish/functions/pkill.fish
M setup.sh
M vim/.vim/after/plugin/fzf.vim
M vim/.vim/autoload/fzf.vim
D vim/.vim/autoload/fzy.vim
A vim/.vim/plugin/fzf.vim
D vim/.vim/plugin/fzy.vim
D vim/.vim/plugin/polyglot.vim
M fish/.config/fish/conf.d/fzf.fish => fish/.config/fish/conf.d/fzf.fish +2 -3
@@ 1,4 1,4 @@
if status is-login; and command -sq fzf
if command -sq fzf
    if command -sq fd
        set -gx FZF_FIND_FILE_COMMAND "fd --type f --hidden --follow --exclude .git"
        set -gx FZF_CD_COMMAND "fd -t d"


@@ 8,6 8,5 @@ if status is-login; and command -sq fzf
        set -gx FZF_FIND_FILE_COMMAND "ag -g ''"
    end

    set -gx FZF_COLORS "bg+:10,bg:0,spinner:6,hl:4,fg:12,header:4,info:3,pointer:6,marker:6,fg+:13,prompt:3,hl+:4"
    set -gx FZF_DEFAULT_OPTS "--height $FZF_TMUX_HEIGHT --color $FZF_COLORS"
    set -gx FZF_DEFAULT_OPTS "--height=10 --reverse --no-info --color=16"
end

D fish/.config/fish/conf.d/ual.fish => fish/.config/fish/conf.d/ual.fish +0 -2
@@ 1,2 0,0 @@
set ual_path $HOME/.notes
set ual_author "Greg Anders"

M fish/.config/fish/fisher/fishfile => fish/.config/fish/fisher/fishfile +1 -0
@@ 2,3 2,4 @@ franciscolourenco/done
jorgebucaran/fishtape
gpanders/pure
edc/bass
jethrokuan/fzf

D fish/.config/fish/functions/__fzy.fish => fish/.config/fish/functions/__fzy.fish +0 -41
@@ 1,41 0,0 @@
function __fzy_find --argument-names cmd
    set -l tok (commandline -t)
    eval $cmd | fzy --query=$tok | read -l selection
    and commandline -t -- (string escape $selection)
    commandline -f repaint
end

function __fzy_files
    if not set -q FZY_FIND_FILE_COMMAND
        if command -sq fd
            set FZY_FIND_FILE_COMMAND "fd --type f"
        else if command -sq rg
            set FZY_FIND_FILE_COMMAND "rg --files"
        else if command -sq ag
            set FZY_FIND_FILE_COMMAND "ag -g ''"
        else
            set FZY_FIND_FILE_COMMAND "find . -type f -not -path '*/.*' 2>/dev/null"
        end
    end
    __fzy_find $FZY_FIND_FILE_COMMAND
end

function __fzy_dir
    if not set -q FZY_FIND_DIR_COMMAND
        if command -sq fd
            set FZY_FIND_DIR_COMMAND "fd --type d"
        else
            set FZY_FIND_DIR_COMMAND "find . -type d -not -path '*/.*' 2>/dev/null"
        end
    end
    __fzy_find $FZY_FIND_DIR_COMMAND
end

function __fzy
    set -l cmd (commandline -oc)
    if test "$cmd[1]" = "cd"
        __fzy_dir
    else
        __fzy_files
    end
end

D fish/.config/fish/functions/__fzy_history.fish => fish/.config/fish/functions/__fzy_history.fish +0 -7
@@ 1,7 0,0 @@
function __fzy_history --description "Show command history with fzy"
    history merge
    eval (string trim "history "(commandline)) | fzy | read -l selection
    and commandline -- $selection
    commandline -f repaint
end


D fish/.config/fish/functions/d.fish => fish/.config/fish/functions/d.fish +0 -3
@@ 1,3 0,0 @@
function d --description "Alias for cdh"
    cdh $argv
end

M fish/.config/fish/functions/fish_user_key_bindings.fish => fish/.config/fish/functions/fish_user_key_bindings.fish +0 -9
@@ 1,7 1,4 @@
function fish_user_key_bindings
    bind -M insert ! __history_previous_command
    bind -M insert '$' __history_previous_command_arguments

    bind \ef nextd-or-forward-word
    bind -M insert \ef nextd-or-forward-word



@@ 13,10 10,4 @@ function fish_user_key_bindings

    bind \es __fish_prepend_sudo
    bind -M insert \es __fish_prepend_sudo

    bind \ct __fzy
    bind -M insert \ct __fzy

    bind \cr __fzy_history
    bind -M insert \cr __fzy_history
end

D fish/.config/fish/functions/fmail.fish => fish/.config/fish/functions/fmail.fish +0 -7
@@ 1,7 0,0 @@
function fmail -w mutt -d "Use fzf with khard to find email recipients"
    set -l addrs (khard email -p --remove-first-line | column -ts\t | fzy | awk '{print $1}')
    if test (count $addrs) -eq 0
        return 1
    end
    mutt $argv -- $addrs
end

M fish/.config/fish/functions/pkill.fish => fish/.config/fish/functions/pkill.fish +1 -1
@@ 1,6 1,6 @@
function pkill -d "Wrapper around pkill to use fuzzy finder when no argument given"
    if test (count $argv) -eq 0
        ps ax -o user=,pid=,%cpu=,%mem=,stat=,time=,command= | fzy | awk '{print $2}' | xargs kill
        ps ax -o user=,pid=,%cpu=,%mem=,stat=,time=,command= | fzf | awk '{print $2}' | xargs kill
    else
        command pkill $argv
    end

M setup.sh => setup.sh +2 -2
@@ 65,8 65,8 @@ if [ $# -eq 0 ]; then
        fi
    done

    if ! installed fzy && ask "Install fzy?"; then
        install fzy
    if ! installed fzf && ask "Install fzf?"; then
        install fzf
    fi

    if ! installed nnn && ask "Install nnn?"; then

M vim/.vim/after/plugin/fzf.vim => vim/.vim/after/plugin/fzf.vim +8 -6
@@ 18,11 18,13 @@ nnoremap <silent> <C-P> :FZF<CR>
command! -bang Helptags call fzf#helptags(<bang>0)
nnoremap <silent> <C-H> :<C-U>Helptags<CR>

command! -bang -nargs=? Tags call fzf#tags(<bang>0, '<args>', '')
nnoremap <Space>] :<C-U>Tags<CR>

command! -bang -nargs=? Ptags call fzf#tags(<bang>0, '<args>', 'p')
nnoremap <Space>} :<C-U>Ptags<CR>
command! -bang -nargs=? Tag call fzf#tags(<bang>0, <q-args>, '')
command! -bang -nargs=? Ptag call fzf#tags(<bang>0, <q-args>, 'p')
nnoremap <Space>t :<C-U>Tag<CR>
nnoremap <C-W><Space>t :<C-U>call fzf#tags(0, '', 's')<CR>

" Hide statusline in FZF buffers
autocmd! FileType fzf set laststatus=0 noruler | autocmd BufLeave <buffer> set laststatus=2 ruler
augroup plugin.fzf
    autocmd!
    autocmd FileType fzf set laststatus=0 noruler | autocmd BufLeave <buffer> set laststatus=2 ruler
augroup END

M vim/.vim/autoload/fzf.vim => vim/.vim/autoload/fzf.vim +12 -6
@@ 2,7 2,7 @@
" Author: Greg Anders
" Date: 2019-05-07

function! fzf#helptags(bang)
function! fzf#helptags(bang) abort
    if !exists('*fzf#run')
        echohl ErrorMsg
        echom 'FZF installation not found'


@@ 18,7 18,7 @@ function! fzf#helptags(bang)
                \ }, a:bang))
endfunction

function! fzf#tags(bang, query, mod)
function! fzf#tags(bang, query, mod) abort
    if !exists('*fzf#run')
        echohl ErrorMsg
        echom 'FZF installation not found'


@@ 26,15 26,21 @@ function! fzf#tags(bang, query, mod)
        return
    endif

    let tags = map(taglist('.'), {_, v -> printf('%-40s %-10s %s', v.name, v.kind, v.filename)})
    let options = '--select-1 --no-multi'
    let tags = map(taglist('.'), {_, v -> printf('%-40s %-10s %s', v.name, v.kind, fnamemodify(v.filename, ':.'))})
    let options = '--select-1 --no-multi --cycle'
    if !empty(a:query)
        let options .= ' --query=' . a:query
    endif

    call fzf#run(fzf#wrap('Tags', {
    call fzf#run(fzf#wrap('Tag', {
                \ 'source': tags,
                \ 'sink': {t -> execute(a:mod . 'tag ' . split(t)[0])},
                \ 'sink': {t -> s:tags(t, a:mod)},
                \ 'options': options,
                \ }, a:bang))
endfunction

function! s:tags(line, mod) abort
    let [tag, _, filename] = split(a:line)[0:2]
    let index = index(map(taglist('^' . tag . '$'), 'v:val.filename'), filename) + 1
    execute index . a:mod . 'tag ' . tag
endfunction

D vim/.vim/autoload/fzy.vim => vim/.vim/autoload/fzy.vim +0 -47
@@ 1,47 0,0 @@
function! s:completed(winid, filename, action, ...) abort
    bdelete!
    call win_gotoid(a:winid)
    if filereadable(a:filename)
        let lines = readfile(a:filename)
        if !empty(lines)
            if type(a:action) ==# type('')
                exe a:action . ' ' . lines[0]
            elseif type(a:action) ==# type({->0})
                call a:action(lines[0])
            endif
        endif
        call delete(a:filename)
    endif
endfunction

function! s:tags(line) abort
    let [tag, _, filename] = split(a:line)[0:2]
    let index = index(map(taglist('^' . tag . '$'), 'v:val.filename'), filename) + 1
    execute index . 'tag ' . tag
endfunction

function! s:fzy(cmd, action, title) abort
    let file = tempname()
    let winid = win_getid()
    let cmd = split(&shell) + split(&shellcmdflag) + [a:cmd . ' | fzy > ' . file]
    let F = function('s:completed', [winid, file, a:action])
    botright 10 new
    if has('nvim')
        call termopen(cmd, {'on_exit': F})
    else
        call term_start(cmd, {'exit_cb': F, 'curwin': 1, 'term_kill': 'quit'})
    endif
    exe 'file ' . a:title
    startinsert
endfunction

function! fzy#files()
    call s:fzy(get(b:, 'fzy_find_files_cmd', g:fzy_find_files_cmd), 'e', 'files')
endfunction

function! fzy#tags()
    let tags = map(taglist('.'), {_, v -> printf('%-40s %-12s %s', v.name, v.kind, fnamemodify(v.filename, ':.'))})
    let file = tempname()
    call writefile(tags, file)
    call s:fzy('cat ' . file, {t -> s:tags(t) && delete(file)}, 'tags')
endfunction

A vim/.vim/plugin/fzf.vim => vim/.vim/plugin/fzf.vim +2 -0
@@ 0,0 1,2 @@
" Homebrew does not add fzf plugin to vim runtimepath so source it manually
silent! source /usr/local/opt/fzf/plugin/fzf.vim

D vim/.vim/plugin/fzy.vim => vim/.vim/plugin/fzy.vim +0 -36
@@ 1,36 0,0 @@
" fzy
" Author: Greg Anders <greg@gpanders.com>
" Date: 2019-10-02

if exists('g:loaded_fzy') || !executable('fzy')
    finish
endif
let g:loaded_fzy = 1

let s:save_cpo = &cpo
set cpo&vim

if executable('fd')
    let g:fzy_find_files_cmd = 'fd --type f'
elseif executable('rg')
    let g:fzy_find_files_cmd = 'rg --files'
elseif executable('ag')
    let g:fzy_find_files_cmd = 'ag -g '''''
elseif executable('find')
    let g:fzy_find_files_cmd = 'find . -type f'
endif

augroup plugin.fzy
    autocmd!
    " If in a git repo use git ls-files
    autocmd BufReadPost *
                \ if get(systemlist('git rev-parse --is-inside-work-tree'), 0, '') ==# 'true' |
                \   let b:fzy_find_files_cmd = 'git ls-files -co --exclude-standard' |
                \ endif
augroup END

nnoremap <silent> <C-P> :call fzy#files()<CR>
nnoremap <silent> <Space>t :call fzy#tags()<CR>

let &cpo = s:save_cpo
unlet s:save_cpo

D vim/.vim/plugin/polyglot.vim => vim/.vim/plugin/polyglot.vim +0 -7
@@ 1,7 0,0 @@
" vim-polyglot configuration
" This file is executed BEFORE vim-polyglot is loaded
" Author: Greg Anders <greg@gpanders.com>
" Date: 2019-03-06

" Disable things
let g:polyglot_disabled = ['markdown', 'latex']