Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions home-manager/packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
bottom # `btm`, alt top
xh # alt HTTPie
zellij
sad

typos
hyperfine
Expand Down
32 changes: 20 additions & 12 deletions pkgs/ir/ir.bash
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
tmprb="$(mktemp --suffix='.rb')"
cat <<'RUBY' >"$tmprb"
$_.gsub!(
/before/,
%q|after|
)
RUBY
command "$EDITOR" "$tmprb"
if [ $# -lt 2 ]; then
# shellcheck disable=SC2016
echo 'Should be specified $1:<PATTERN> and $2:[REPLACE]' >&2
fi

# TODO: grep takes the "before" if given then via CLI
fd --type file --hidden --exclude .git |
xargs grep --binary-files=without-match -l --fixed-strings -e '' |
xargs ruby -i -pn "$tmprb"
# https://stackoverflow.com/a/28090709
nl=$'\n'

fzf_options="$(
cat <<-EOF
--style full --height 80% --layout reverse \
--border --padding '1,2' --border-label ' Inline Replacer ' \
--input-label ' Path Filter ' \
--header-label ' Keybinds ' \
--header "Tab(+Shift): Toggle${nl}Alt+t: Toggle All" \
--bind 'alt-t:toggle-all'
EOF
)"

fd --type file --hidden --exclude .git --exclude .direnv --exclude node_modules |
sad --fzf="$fzf_options" "$@"
24 changes: 14 additions & 10 deletions pkgs/ir/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,23 @@ pkgs.writeShellApplication rec {
runtimeInputs = with pkgs; [
fd

# Don't use these candidates
# - sed: Always forgot how to use
# Why not other candidates?
# - sed: Always forgot how to use. And the regex is much classic
# - sd: Inactive
# - sad: Too much for filter
ruby_3_4
# - fastmod: Does not fit for list based preview
# - srgn: Much options, but I don't know how to use that
sad

findutils # xargs
gnugrep

coreutils # cat
mktemp
unstable.fzf # Require latest to enable new options. e.g `--input-label` # TODO: Prefer stable since nixos-25.05
riffdiff
];
runtimeEnv = {
GIT_PAGER = "riff --color=on";
};
meta = {
description = "Inline replacer with Ruby regex";
description = ''
Inline replacer with a preview UI.
This is also a note on how to use "sad" with external dependencies.
'';
};
}