Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
fzf key-bindings.bash: ignore duplicates
# ..
# Requires https://st.aticpan.org/source/PERLANCAR/App-nauniq-0.10/script/nauniq
# SHA256: 046d69b8b1ed74aaff38565f08acc9781e7404fa240b2d091601043a5838f9f0
# gsed -i 's?#!perl?#!/usr/bin/env perl?' nauniq
# patch -p1 nauniq < nauniq-ignore-pattern.patch
__fzf_history__() (
local line
shopt -u nocaseglob nocasematch
line=$(
HISTTIMEFORMAT= history |
tac |
nauniq --ignore-pattern="^\s*\d+\s{0,2}" |
tac |
FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} $FZF_DEFAULT_OPTS --tac -n2..,.. --tiebreak=index --bind=ctrl-r:toggle-sort $$
command grep '^ *[0-9]') &&
if [[ $- =~ H ]]; then
sed 's/^ *\([0-9]*\)\** .*/!\1/' <<< "$line"
else
sed 's/^ *\([0-9]*\)\** *//' <<< "$line"
fi
)
# ..
@@ -12,6 +12,7 @@
append => 0,
check_chars => -1,
forget_pattern => undef,
+ ignore_pattern => undef,
ignore_case => 0,
md5 => 0,
num_entries => -1,
@@ -43,6 +44,14 @@
}
$Opts{forget_pattern} = $val;
},
+ 'ignore-pattern=s' => sub {
+ my ($cbobj, $val) = @_;
+ eval { $val = $Opts{ignore_case} ? qr/$val/i : qr/$val/ };
+ if ($@) {
+ warn "Invalid regex pattern in --ignore-pattern: $@\n"; exit 99;
+ }
+ $Opts{ignore_pattern} = $val;
+ },
'md5' => \$Opts{md5},
'read-output' => \$Opts{read_output},
'help|h' => sub {
@@ -62,6 +71,7 @@
-a
--md5
--forget-pattern=S
+ --ignore-pattern=S
For more details, see the manpage/documentation.
USAGE
exit 0;
@@ -137,6 +147,9 @@
$memkey = $Opts{check_chars} > 0 ?
substr($line, $Opts{skip_chars}, $Opts{check_chars}) :
substr($line, $Opts{skip_chars});
+ if ($Opts{ignore_pattern}) {
+ $memkey =~ s/$Opts{ignore_pattern}//g;
+ }
$memkey = lc($memkey) if $Opts{ignore_case};
$memkey = Digest::MD5::md5($memkey) if $Opts{md5};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.