Skip to content

Commit

Permalink
Use better defaults for fzf
Browse files Browse the repository at this point in the history
  • Loading branch information
ajeetdsouza committed Nov 30, 2021
1 parent c392a8b commit 592b2b6
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 43 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Changed

- Better defaults for `fzf`.

### Fixed

- PowerShell: use global scope for aliases.
Expand Down
53 changes: 26 additions & 27 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ anyhow = "1.0.32"
askama = { version = "0.10.3", default-features = false }
bincode = "1.3.1"
clap = "=3.0.0-beta.5"
dirs-next = "2.0.0"
dirs = "4.0.0"
dunce = "1.0.1"
glob = "0.3.0"
ordered-float = "2.0.0"
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::ffi::OsString;
use std::path::PathBuf;

use anyhow::{bail, Context, Result};
use dirs_next as dirs;
use dirs;
use glob::Pattern;

use crate::db::Rank;
Expand Down
13 changes: 13 additions & 0 deletions src/fzf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,19 @@ impl Fzf {
command.arg("-n2..").stdin(Stdio::piped()).stdout(Stdio::piped());
if let Some(fzf_opts) = config::fzf_opts() {
command.env("FZF_DEFAULT_OPTS", fzf_opts);
} else {
command.args(&[
"--bind=ctrl-z:ignore",
"--exit-0",
"--height=35%",
"--inline-info",
"--no-sort",
"--reverse",
"--select-1",
]);
if cfg!(unix) {
command.arg("--preview=ls -p {2}");
}
}

let child = match command.spawn() {
Expand Down
9 changes: 0 additions & 9 deletions src/shell.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
use crate::app::InitHook;

const FZF_COMPLETE_OPTS: &str = "\
--bind=ctrl-z:ignore \
--exit-0 \
--height=35% \
--inline-info \
--no-sort \
--reverse \
--select-1";

#[derive(Debug, Eq, PartialEq)]
pub struct Opts<'a> {
pub cmd: Option<&'a str>,
Expand Down
6 changes: 2 additions & 4 deletions templates/bash.txt
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,8 @@ if [[ :"${SHELLOPTS}": =~ :(vi|emacs): && ${TERM} != 'dumb' ]]; then
# If there is a space after the last word, use interactive selection.
elif [[ -z ${COMP_WORDS[-1]} ]]; then
\local result
result="$(
_ZO_FZF_OPTS='{{ crate::shell::FZF_COMPLETE_OPTS }}' \
\builtin command zoxide query -i -- "${COMP_WORDS[@]:1}"
)" && COMPREPLY=("${__zoxide_z_prefix}${result}")
result="$(\builtin command zoxide query -i -- "${COMP_WORDS[@]:1}")" \
&& COMPREPLY=("${__zoxide_z_prefix}${result}")
\builtin printf '\e[5n'
fi
}
Expand Down
2 changes: 1 addition & 1 deletion templates/fish.txt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function __zoxide_z_complete
else
# Otherwise, use interactive selection.
set -l query $tokens[2..-1]
set -l result (_ZO_FZF_OPTS='{{ crate::shell::FZF_COMPLETE_OPTS }}' zoxide query -i -- $query)
set -l result (zoxide query -i -- $query)
and commandline -p "$tokens[1] "(string escape $result)
commandline -f repaint
end
Expand Down

0 comments on commit 592b2b6

Please sign in to comment.