Most of this is taken from fzf.fish. A really nice fzf integration with fish-shell.
There's quite a bit of usage of a fish command called commandline
. It would be super helpful for porting things like this script if we had such a utility to modify the readline command line buffer.
Set the default fzf options
let-env FZF_DEFAULT_OPTS = '--cycle --layout=reverse --border --height=90% --preview-window=wrap --marker="*"'
Set the Log Format String
let log_fmt_str = '%C(bold blue)%h%C(reset) - %C(cyan)%ad%C(reset) %C(yellow)%d%C(reset) %C(normal)%s%C(reset) %C(dim normal)[%an]%C(reset)'
Set the selected log lines and invote fzf
let selected_log_lines = (
git log [--format=format:($log_fmt_str) --date=short --color=always] |
fzf [--ansi --multi --tiebreak=index '--preview=git show --color=always --stat --patch {1}']
)
Here's an example of what $selected_log_lines
looks like after an fzf selection
echo $selected_log_lines
1086fbe9 - Sun Jul 31 12:36:14 2022 -0700 Revert `query` command to `query db` (#6200) [Reilly Wood]
Get full git hash
let abbreviated_commit_hash = ($selected_log_lines | split row ' ' | first)
let full_commit_hash = (git rev-parse $abbreviated_commit_hash | str trim)
Set fd options
let fd_ops = [--color=always --strip-cwd-prefix]
Set fzf arguments
let fzf_arguments = [--multi --ansi]
Get the selected file
let file_paths_selected = (
fd $fd_ops | fzf $fzf_arguments
)
Example of selection:
$file_paths_selected
crates/nu-command/src/filesystem/ls.rs
let command_with_ts = (history | each {|h| $"($h | get start_timestamp | into datetime | date format '%m-%d %H:%M:%S') ($h | get command)(char -i 0)"} | to text | fzf [--read0 --tiebreak=index "--preview=^echo -- {4..}" "--preview-window=bottom:3:wrap"])
maybe use $command_with_ts | str trim | str substring '15,'
instead of echo -- {4..}
that is really cool stuff 😮 🤩
everything is working fine
apart from just the last one gives me
in every line and
fork/exec /bin/bash: argument list too long
in the preview window of
fzf
👍