From 61a9a252a59106de2e11c5983f7459ada8631a14 Mon Sep 17 00:00:00 2001 From: Christian Nieves Date: Thu, 22 Sep 2022 14:52:38 -0500 Subject: [PATCH] Fix FZF --- config/.config/nvim/lua/diagnostics.lua | 17 +++--- config/.config/nvim/lua/lsp.lua | 4 +- fzf/fzf-at-google.zsh | 71 +++++++++++-------------- zsh/.bash_profile | 1 - zsh/.bash_profile.google | 16 ++---- zsh/.zshrc | 9 ++-- 6 files changed, 49 insertions(+), 69 deletions(-) diff --git a/config/.config/nvim/lua/diagnostics.lua b/config/.config/nvim/lua/diagnostics.lua index 5844f82..e069355 100644 --- a/config/.config/nvim/lua/diagnostics.lua +++ b/config/.config/nvim/lua/diagnostics.lua @@ -32,7 +32,7 @@ require("trouble").setup({ }, indent_lines = true, -- add an indent guide below the fold icons auto_open = false, -- automatically open the list when you have diagnostics - auto_close = false, -- automatically close the list when you have no diagnostics + auto_close = true, -- automatically close the list when you have no diagnostics auto_preview = true, -- automatically preview the location of the diagnostic. to close preview and go back to last window auto_fold = false, -- automatically fold a file trouble list at creation auto_jump = { "lsp_definitions" }, -- for the given modes, automatically jump if there is only a single result @@ -48,9 +48,12 @@ require("trouble").setup({ }) -- Mappings -vim.api.nvim_set_keymap("n", "gr", "Trouble lsp_references", { silent = true, noremap = true }) -vim.api.nvim_set_keymap("n", "xx", "Trouble", { silent = true, noremap = true }) -vim.api.nvim_set_keymap("n", "xw", "Trouble workspace_diagnostics", { silent = true, noremap = true }) -vim.api.nvim_set_keymap("n", "xd", "Trouble document_diagnostics", { silent = true, noremap = true }) -vim.api.nvim_set_keymap("n", "xl", "Trouble loclist", { silent = true, noremap = true }) -vim.api.nvim_set_keymap("n", "xq", "Trouble quickfix", { silent = true, noremap = true }) +local opts = { noremap = true, silent = true } +vim.api.nvim_set_keymap("n", "gr", "Trouble lsp_references", opts) +vim.api.nvim_set_keymap("n", "xx", "Trouble", opts) +vim.api.nvim_set_keymap("n", "xw", "Trouble workspace_diagnostics", opts) +vim.api.nvim_set_keymap("n", "xd", "Trouble document_diagnostics", opts) +vim.api.nvim_set_keymap("n", "xl", "Trouble loclist", opts) +vim.api.nvim_set_keymap("n", "xq", "Trouble quickfix", opts) +vim.api.nvim_set_keymap("n", "[g", "lua vim.diagnostic.goto_prev()", opts) +vim.api.nvim_set_keymap("n", "]g", "lua vim.diagnostic.goto_next()", opts) diff --git a/config/.config/nvim/lua/lsp.lua b/config/.config/nvim/lua/lsp.lua index 510c683..fb4635f 100644 --- a/config/.config/nvim/lua/lsp.lua +++ b/config/.config/nvim/lua/lsp.lua @@ -164,13 +164,11 @@ local on_attach = function(client, bufnr) vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "tab split | lua vim.lsp.buf.definition()", opts) -- vim.api.nvim_buf_set_keymap(bufnr, "n", "gD", "lua vim.lsp.buf.declaration()", opts) vim.api.nvim_buf_set_keymap(bufnr, "n", "gi", "lua vim.lsp.buf.implementation()", opts) - -- vim.api.nvim_buf_set_keymap(bufnr, "n", "gr", "lua vim.lsp.buf.references()", opts) -- diagnostics controls references + vim.api.nvim_buf_set_keymap(bufnr, "n", "grf", "lua vim.lsp.buf.references()", opts) -- diagnostics controls references vim.api.nvim_buf_set_keymap(bufnr, "n", "", "lua vim.lsp.buf.signature_help()", opts) vim.api.nvim_buf_set_keymap(bufnr, "i", "", "lua vim.lsp.buf.signature_help()", opts) vim.api.nvim_buf_set_keymap(bufnr, "n", "gt", "lua vim.lsp.buf.type_definition()", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "[g", "lua vim.diagnostic.goto_prev()", opts) - vim.api.nvim_buf_set_keymap(bufnr, "n", "]g", "lua vim.diagnostic.goto_next()", opts) vim.api.nvim_command("augroup LSP") vim.api.nvim_command("autocmd!") diff --git a/fzf/fzf-at-google.zsh b/fzf/fzf-at-google.zsh index 523cd8a..6b472ee 100644 --- a/fzf/fzf-at-google.zsh +++ b/fzf/fzf-at-google.zsh @@ -2,24 +2,6 @@ export FZF_SOURCE="${HOME}/fzf-relevant-files.zsh" -# General fzf settings. -export FZF_DEFAULT_OPTS=" \ - --inline-info \ - --reverse \ - --exact \ - --color=fg+:#F8F8F8,bg+:#515559,pointer:#F8F8F8,marker:226 \ - --bind=ctrl-e:select-all+accept \ - --bind=ctrl-d:half-page-down \ - --bind=ctrl-e:half-page-up - --bind=ctrl-t:toggle+down - --bind=ctrl-b:toggle+up - --bind=ctrl-g:select-all+accept \ - " -# Preview code with pygmentize. -# export FZF_CS_PREVIEW_COMMAND="python /google/src/files/head/depot/google3/third_party/py/pygments/google/google_pygmentize.py -f terminal16m -O style=native" -# Preview highlight: foreground: RG(248, 248, 248) = #F8F8F8, background: RGB(81, 85, 89) = #515559. -export FZF_CS_PREVIEW_HIGHLIGHT="\x1b[38;2;248;248;248m\x1b[48;2;81;85;89m" - function create_fzf_command() { rg --files $(${FZF_SOURCE}) } @@ -36,50 +18,57 @@ _find_fig_workspaces() { } _find_blaze_targets() { - # Our tool outputs space-separated directories of interest. Conver these to a + # Our tool outputs space-separated directories of interest. Convert these to a # list, which we'll refer to later. local pkg local cleandir local DIRS=( $(${FZF_SOURCE}) ) - # for dir in "${DIRS[@]}"; do - # echo "$dir" - # done + local is_first_iteration=1 + local query="" + for dir in "${DIRS[@]}"; do # Here we want: # .* - match all targets # //foo/bar/baz/... - the blaze package we're searching under - # We do a trailing '&' so that we run all of these in parallel. - # We shunt 2>/dev/null to silence its info output, which for some reason - # comes out on stderr. This isn't ideal, because we'll swallow real errors. - # Looking at `blaze help query`, I can't find any options to turn this off. - # `--logging=0` doesn't do it; `--show_loading_progress=false` doesn't do - # it. # Strip any leading // and trailing /. This allows more flexibility in how # people want to define their targets in their FZF_SOURCE file. - cleandir=`echo $dir | sed 's/^\/\///; s/\/$//'` + # Finally we will append each directory's query together with a "+" which + # allows us to query all targets with a single blaze query call. + if ((is_first_iteration)); then + is_first_iteration=0 + else + query+=" + " + fi + cleandir=`echo $dir | sed 's:^//::; s:/$::'` pkg="//${cleandir}/..." - blaze query "filter(.*, ${pkg})" 2>/dev/null & + query+="filter(.*, ${pkg})" done + + # We shunt 2>/dev/null to silence its info output, which for some reason + # comes out on stderr. This isn't ideal, because we'll swallow real errors. + # Looking at `blaze help query`, I can't find any options to turn this off. + # `--logging=0` doesn't do it; `--show_loading_progress=false` doesn't do + # it. + # --keep_going is required in case any of the pkgs have no subtargets, if not + # provided the query will exit before evaluating other pkgs. + blaze query --keep_going "${query}" 2> /dev/null } -# fzf completion for blaze targets beneath the current directory. eg: +# fzf completion for blaze targets beneath the current directory. Works on +# programs that use the blaze CLI eg: # # blaze build ** +# rabbit build ** +# iblaze build ** # # Syntax for this style of completion is taken from: # https://github.com/junegunn/fzf/wiki/Examples-(completion)#writing-custom-fuzzy-completion _fzf_complete_blaze() { _fzf_complete "" "$@" < <(_find_blaze_targets) } - -# fzf completion for rabbit targets beneath the current directory. eg: -# -# rabbit test ** -# -_fzf_complete_rabbit() { - _fzf_complete "" "$@" < <(_find_blaze_targets) -} +alias _fzf_complete_rabbit="_fzf_complete_blaze" +alias _fzf_complete_iblaze="_fzf_complete_blaze" _fzf_complete_hgd() { _fzf_complete "" "$@" < <(_find_fig_workspaces) @@ -233,7 +222,7 @@ awk -v match_prefix=${match_prefix} ' { for (i = 1; i <= NF; i++) { } -# CTRL-F - Paste the selected flags into the command line. Copied from CTRL-T +# CTRL-Q - Paste the selected flags into the command line. Copied from CTRL-T # bindings shown here: # https://github.com/junegunn/fzf/blob/master/shell/key-bindings.zsh __flagsel() { @@ -271,3 +260,5 @@ fzf-flag-widget() { } zle -N fzf-flag-widget bindkey '^F' fzf-flag-widget +bindkey '^T' fzf-file-widget +bindkey '^R' fzf-history-widget diff --git a/zsh/.bash_profile b/zsh/.bash_profile index 582aeee..2704c28 100644 --- a/zsh/.bash_profile +++ b/zsh/.bash_profile @@ -11,7 +11,6 @@ export EDITOR='nvim' HISTCONTROL=ignoreboth - export DEVKITPRO=/opt/devkitpro export DEVKITARM=${DEVKITPRO}/devkitARM export DEVKITPPC=${DEVKITPRO}/devkitPPC diff --git a/zsh/.bash_profile.google b/zsh/.bash_profile.google index 78c4ffa..c33303b 100644 --- a/zsh/.bash_profile.google +++ b/zsh/.bash_profile.google @@ -36,24 +36,12 @@ fi # Install fzf-query export PATH="${PATH}:/google/bin/releases/editor-devtools" -# General fzf settings. -export FZF_DEFAULT_OPTS=" \ - --inline-info \ - --reverse \ - --color=fg+:#F8F8F8,bg+:#515559,pointer:#F8F8F8,marker:226 \ - --bind=ctrl-e:select-all+accept \ - --bind=ctrl-d:half-page-down \ - --bind=ctrl-e:half-page-up - --bind=ctrl-t:toggle+down - --bind=ctrl-b:toggle+up - --bind=ctrl-g:select-all+accept \ - " + # Preview code with pygmentize. export FZF_CS_PREVIEW_COMMAND="python third_party/py/pygments/google/google_pygmentize.py -f terminal16m -O style=native" # Preview highlight: foreground: RG(248, 248, 248) = #F8F8F8, background: RGB(81, 85, 89) = #515559. export FZF_CS_PREVIEW_HIGHLIGHT="\x1b[38;2;248;248;248m\x1b[48;2;81;85;89m" -source ~/fzf-at-google.zsh source ~/g3path.zsh source /etc/bash_completion.d/hgd @@ -77,3 +65,5 @@ alias hgd='source /google/src/head/depot/google3/experimental/fig_contrib/hgshor export ACID_STARTUP_SCRIPT_PATH=~/acid_startup.sh export PATH=$PATH:/usr/local/google/home/cnieves/.local/binexport PATH=$PATH:/usr/local/google/home/cnieves/.local/bin + +source ~/fzf-at-google.zsh diff --git a/zsh/.zshrc b/zsh/.zshrc index ea75761..74f2032 100644 --- a/zsh/.zshrc +++ b/zsh/.zshrc @@ -21,7 +21,7 @@ if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]] fi # To customize prompt, run `p10k configure` or edit ~/.p10k.zsh. # [[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh -# plugins=(zsh-autosuggestions zsh-syntax-highlighting) +plugins=(zsh-autosuggestions zsh-syntax-highlighting) ZSH_THEME=powerlevel10k/powerlevel10k DISABLE_AUTO_TITLE=true @@ -30,7 +30,6 @@ bindkey "^A" beginning-of-line bindkey "^E" end-of-line bindkey "^K" kill-line bindkey "^L" clear-screen -bindkey "^R" history-incremental-search-backward bindkey "^U" kill-whole-line bindkey "^W" backward-kill-word bindkey "^Y" yank @@ -247,8 +246,8 @@ zstyle :bracketed-paste-magic paste-finish pastefinish # "transport endpoint is not connected" errors autoload -Uz add-zsh-hook -export FZF_DEFAULT_OPTS="--preview 'echo {}' --preview-window down:3:wrap --bind ?:toggle-preview" - -source ~/.bash_profile +[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh export ZSH="$HOME/.oh-my-zsh" source $ZSH/oh-my-zsh.sh + +source ~/.bash_profile