nice! the biggest thing holding me back from using fish was the behavior of ctrl+r - i just installed fish to play around, and it looks like they completely fixed it - ctrl+r is now incremental! i don’t know if that happened in this release, but it was a welcome surprise.
also, i must say that i’m amazed by how quickly this release came together. i have never seen a rewrite happen so fast - huge props to everyone working on fish!
Sure, I pretty much just setup my desired fzf call in a function and bound it to <c-r>. Keep an eye out for the odd deprecation, I haven’t touched this code in ages. Here you go:
# FZF {{{1
# ripgrep options being used to power fzf:
# --files : Print file's names but not their content
# --hidden : Search hidden files and directories
# --smart-case : Search smart with upper and lower case
# --glob "!.git/*" : Ignore .git/ folder
set --export \
FZF_DEFAULT_COMMAND 'rg --files --hidden --smart-case --glob "!.git/*"'
function _fzf_search_history --description "Search command history with `fzf`"
# TODO: Ensure `fzf` is installed locally
# Get history and pipe into fzf
history --null |
# Run fzf using history's entries as source
fzf \
# Prefill query with command line content
--query=(commandline) \
# Prompt indicator
--prompt=" " \
# Current line indicator
--pointer="" \
# Enable multi-selection
--multi \
# Selected line indicator
--marker="+" \
# Read input delimited by ascii null
--read0 \
# Print input delimited by ascii null
--print0 \
# Not fullscreen but hang down with this much height under cursor
--height=10 \
# Extra left margin to align text with my prompt
--padding="0,0,0,2" \
# Keep default layout with prompt and first result at bottom
--layout="default" \
# Show info to right end of prompt line
--info="inline-right" \
# Theme slightly customized from default base theme
# NOTE: Place ANSI attributes(`bold`) before other styles
--color="fg+:bold,gutter:-1,info:italic,info:dim,separator:dim" \
# When other multi-selections are selected and enter is hit on a
# unselected line, the current unselected line is not chosen and
# only the previously selected lines are chosen. Fix that behavior
# with enter
--bind="enter:select+accept" \
# Accept current line, ignoring other selections
--bind="alt-enter:clear-selection+accept" \
# Tab toggles selection without moving line
--bind="tab:toggle" \
# Shift-tab deselects without moving line
--bind="btab:deselect" \
# Vertical movement
--bind="ctrl-alt-n:first,ctrl-alt-p:last" \
--bind="ctrl-alt-j:first,ctrl-alt-k:last" \
# NOTE: Cannot do`ctrl-alt` + up/down as it is not available
# --bind="ctrl-alt-up:first,ctrl-alt-p:down" \
# Offset up/down, like with `c-e`/`c-y` in vim
--bind="ctrl-e:offset-down,ctrl-y:offset-up" \
# Select/deselect up/down wards. (Aids consecutive selections)
# (Currently not doing n/p+j/k just up/down)
--bind="shift-up:select+up,shift-down:select+down" \
--bind="alt-shift-up:deselect+up,alt-shift-down:deselect+down" \
# TODO: Ensure this history file location exists and is
# periodically cleared out.
--history="$HOME/.cache/fzf-history/fzf-history-file" \
# NOTE: When history is specified, `c-n`/`c-p` is automatically
# remapped to next/prev history, so explicitly rebind that
# don't want it
--bind="alt-up:prev-history,alt-down:next-history" \
# Preview disabled
# --bind="ctrl-alt-f:preview-page-up,ctrl-alt-b:preview-page-down" \
# --preview-window="right" \
# --preview="cat {}" \ # "head -$LINES {}"
# Strategy to use when search scores are tied
--tiebreak=index |
# Split string received on null byte
string split0 |
# Remove blank line between "multi-selections"
string replace "\n\n" "\n" |
# Trim trailing/leading whitespace
# string trim |
# Remove end-of-file blank line in "multi-selections"
string collect |
# Store received string into `$result`
read --function --null result
# Run only if previous command succeeds,
# replacing commandline with previous result.
and commandline --replace -- $result
# Repaint commandline. Necessary to avoid UI glitches.
commandline --function repaint
end
# Trigger fzf search with `<c-r>`
bind \cr _fzf_search_history
bind \cr --mode default _fzf_search_history
bind \cr --mode insert _fzf_search_history
It depends on percol, which is fine for me because I use it daily for all sorts of things. It’s invaluable but it doesn’t support multi line commands smoothly.
They added incremental history search to fish recently but AFAICT, it hasn’t reached the major Linux distro as stable (no idea how things are on OSX land).
I too been craving for this feature to be supported natively. Rejoice!
In case a page is lacking anchors for a section I want to link to or I want to highlight something specifically, many browser support “text fragments” these days as a way to encode a snippet of text in the URL, search for it in the page, and highlight it. The following bookmarklet automates the process for the currently selected text:
nice! the biggest thing holding me back from using fish was the behavior of ctrl+r - i just installed fish to play around, and it looks like they completely fixed it - ctrl+r is now incremental! i don’t know if that happened in this release, but it was a welcome surprise.
also, i must say that i’m amazed by how quickly this release came together. i have never seen a rewrite happen so fast - huge props to everyone working on fish!
Sucks that held you back so long, I just had hooked up to fzf and it worked great. Anyway this is a welcome update indeed.
Can you share the config for this setup, by any chance?
Sure, I pretty much just setup my desired fzf call in a function and bound it to
<c-r>. Keep an eye out for the odd deprecation, I haven’t touched this code in ages. Here you go:I had exactly the same experience. This l, together with finally being able to disable auto completion is great qol.
I have had this little function in my fish_config for many years, binded to Ctrl+r, for that purpose.
https://github.com/oh-my-fish/plugin-percol/blob/master/functions/percol_select_history.fish
It depends on percol, which is fine for me because I use it daily for all sorts of things. It’s invaluable but it doesn’t support multi line commands smoothly.
They added incremental history search to fish recently but AFAICT, it hasn’t reached the major Linux distro as stable (no idea how things are on OSX land).
I too been craving for this feature to be supported natively. Rejoice!
I had to look up what that did. I never heard of it.
In case a page is lacking anchors for a section I want to link to or I want to highlight something specifically, many browser support “text fragments” these days as a way to encode a snippet of text in the URL, search for it in the page, and highlight it. The following bookmarklet automates the process for the currently selected text:
(I don’t recall where I got it from)
Example URL: https://lobste.rs/s/vjdc18/bookmarklets_do_you_use_them_if_so_wanna#:~:text=which%20is%20awesome