fzf: add ctrl-e binding to edit selected file
This commit is contained in:
parent
87a25f35c5
commit
0c0c557f0d
@ -3,10 +3,18 @@ set -gx FZF_DEFAULT_OPTS "--no-height --layout=reverse"
|
|||||||
set -gx FZF_DEFAULT_COMMAND "fd --type=file"
|
set -gx FZF_DEFAULT_COMMAND "fd --type=file"
|
||||||
|
|
||||||
function __fzf_files
|
function __fzf_files
|
||||||
set -l src_cmd "fd --type=file --hidden --follow --color=always --exclude=.git 2>/dev/null"
|
set -l output (
|
||||||
set -l fzf_cmd "fzf --ansi --preview 'bat --style=header,numbers --color=always {}' --preview-window right:70%:hidden:wrap --bind '?:toggle-preview'"
|
fd --type=file --hidden --follow --color=always --exclude=.git 2>/dev/null |
|
||||||
if set -l selection (eval "$src_cmd | $fzf_cmd")
|
fzf --ansi --preview='bat --style=header,numbers --color=always {}' --preview-window='right:70%:hidden:wrap' --bind='?:toggle-preview' --expect='ctrl-e' --header='ctrl-e to edit'
|
||||||
commandline -i (echo $selection | string escape)
|
)
|
||||||
|
set -l key $output[1]
|
||||||
|
set -l file $output[2]
|
||||||
|
switch $key
|
||||||
|
case ctrl-e
|
||||||
|
set -q EDITOR; or set EDITOR vim
|
||||||
|
commandline -r "$EDITOR $file"
|
||||||
|
case '*'
|
||||||
|
commandline -i $file
|
||||||
end
|
end
|
||||||
commandline -f repaint
|
commandline -f repaint
|
||||||
end
|
end
|
||||||
@ -15,10 +23,11 @@ function __fzf_git_log
|
|||||||
if not git rev-parse --git-dir >/dev/null 2>&1
|
if not git rev-parse --git-dir >/dev/null 2>&1
|
||||||
echo '__fzf_search_git_log: Not in a git repository!' >&2
|
echo '__fzf_search_git_log: Not in a git repository!' >&2
|
||||||
else
|
else
|
||||||
set -l src_cmd 'command git logsearch'
|
set -l output (
|
||||||
set -l fzf_cmd 'fzf --ansi --tiebreak=index'
|
command git logsearch |
|
||||||
if set -l selection (eval "$src_cmd | $fzf_cmd")
|
fzf --ansi --tiebreak=index
|
||||||
set commit_hash (string split --max 1 " " $selection)[1]
|
)
|
||||||
|
if set -l commit_hash (string split --max 1 " " $output)[1]
|
||||||
commandline -i $commit_hash
|
commandline -i $commit_hash
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -26,10 +35,11 @@ function __fzf_git_log
|
|||||||
end
|
end
|
||||||
|
|
||||||
function __fzf_history
|
function __fzf_history
|
||||||
set -l src_cmd 'history search --null --show-time="%Y-%m-%d | "'
|
set -l output (
|
||||||
set -l fzf_cmd "fzf --read0 --tiebreak=index --query=(commandline) --preview='echo {}' --preview-window='bottom:50%:hidden:wrap' --bind='?:toggle-preview'"
|
history search --null --show-time="%Y-%m-%d | " |
|
||||||
if set -l selection (eval "$src_cmd | $fzf_cmd")
|
fzf --read0 --tiebreak=index --query=(commandline) --preview='echo {}' --preview-window='bottom:50%:hidden:wrap' --bind='?:toggle-preview'
|
||||||
set -l command (string split --max 1 " | " $selection)[2..-1]
|
)
|
||||||
|
if set -l command (string split --max 1 " | " $output)[2..-1]
|
||||||
commandline -r $command
|
commandline -r $command
|
||||||
end
|
end
|
||||||
commandline -f repaint
|
commandline -f repaint
|
||||||
|
Loading…
x
Reference in New Issue
Block a user