Skip to content

Commit

Permalink
Merge branch 'fix-sed-vs-gsed'
Browse files Browse the repository at this point in the history
* Branch commit log:
  jj-fzf: fix all gsed uses
  Makefile: check for gsed uses throughout
  Makefile: check-deps: check dependencies before installing

Signed-off-by: Tim Janik <[email protected]>
  • Loading branch information
tim-janik committed Dec 12, 2024
2 parents 71052e7 + 812ef48 commit d5efe09
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
14 changes: 10 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ Q ::= $(if $(findstring 1, $(V)),, @)

all: check

install: jj-fzf
$(INSTALL) -t "$(bindir)" $<

check-deps: jj-fzf
$Q jj-fzf --version
$Q jj-fzf --help >/dev/null # check-deps
install: check-deps
$(INSTALL) -t "$(bindir)" jj-fzf
uninstall:
$(RM) "$(bindir)/jj-fzf"

Expand All @@ -23,4 +25,8 @@ shellcheck-error:
shellcheck -W 3 -S error jj-fzf
tests-basics.sh:
$Q tests/basics.sh
check: jj-fzf shellcheck-error tests-basics.sh
check-gsed: jj-fzf
$Q ! grep --color=auto -E '[^\\]\bsed ' jj-fzf \
|| { echo "ERROR: use gsed" >&2 ; false; }
$Q echo ' OK gsed uses'
check: check-deps shellcheck-error check-gsed tests-basics.sh
12 changes: 6 additions & 6 deletions jj-fzf
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ versionge "$(bash --version)" 5.1.16 || die "failed to find 'bash' version 5.1.1
[[ `set -o` =~ emacs ]] || die "the 'bash' executable lacks interactive readline support"
versionge "$(jj --version --ignore-working-copy)" 0.24 || die "failed to find 'jj' version 0.24.0 in \$PATH"
versionge "$(fzf --version)" 0.43 || die "failed to find 'fzf' version 0.43.0 in \$PATH" # 0.43.0 supports offset-up
sed --version 2>/dev/null | grep -Fq 'GNU sed' && gsed() { sed "$@"; } && export -f gsed ||
sed --version 2>/dev/null | grep -Fq 'GNU sed' && gsed() { \sed "$@"; } && export -f gsed ||
gsed --version | grep -Fq 'GNU sed' || die "failed to find 'gsed' in \$PATH (GNU sed)"
command -v column >/dev/null || column() { cat; }

Expand Down Expand Up @@ -507,7 +507,7 @@ bookmark()
R="$(xrev_or_commit "${1:-@}")"
#echo "# Existing Bookmarks:" && jj --no-pager --ignore-working-copy bookmark list
readarray -t BOOKMARKS < <(jj --no-pager --ignore-working-copy bookmark list -T 'self.name()++"\n"' | sort | uniq)
readarray -t NEAREST < <(jj --no-pager --ignore-working-copy log --no-graph -r "::$R|$R+" -T 'bookmarks++"\n"' | sed -r 's/\b \b/\n/g; s/\*$//; s/\b@.*//; /^$/d')
readarray -t NEAREST < <(jj --no-pager --ignore-working-copy log --no-graph -r "::$R|$R+" -T 'bookmarks++"\n"' | gsed -r 's/\b \b/\n/g; s/\*$//; s/\b@.*//; /^$/d')
[[ ${#NEAREST[@]} -ge 1 ]] && INIT="${NEAREST[0]}" || INIT=""
PROMPT='Bookmark Name: '
echo "# Assign Bookmark to:"
Expand Down Expand Up @@ -566,7 +566,7 @@ delete-refs()
(
R="$(xrev_or_commit "${1:-@}")"
# find first local bookmark in $R, use as query arg
readarray -t NEAREST < <(jj --no-pager --ignore-working-copy log --no-graph -r "$R" -T 'local_bookmarks++"\n"' | sed -r 's/\b \b/\n/g; s/\*$//; s/\b@.*//; /^$/d')
readarray -t NEAREST < <(jj --no-pager --ignore-working-copy log --no-graph -r "$R" -T 'local_bookmarks++"\n"' | gsed -r 's/\b \b/\n/g; s/\*$//; s/\b@.*//; /^$/d')
[[ ${#NEAREST[@]} -ge 1 ]] && B=(-q "${NEAREST[0]}") || B=()
require_git_dir # exports GIT_DIR
# select bookmark or tag
Expand All @@ -579,7 +579,7 @@ delete-refs()
"${B[@]}" \
< <(
# list local bookmarks
jj --ignore-working-copy bookmark list | # sed reorders conflicted
jj --ignore-working-copy bookmark list | # gsed reorders conflicted
gsed -r ':0; /^\s/!s/ \(conflicted\):/: (conflicted)/; N; $!b0; s/\n\s+/ /g' |
while read MARK rest ; do
printf "%-32s [bookmark] %s\n" "${MARK%:}" "$rest"
Expand Down Expand Up @@ -931,7 +931,7 @@ op_log_oneline()
if LAST_OPID=$(jj --no-pager --ignore-working-copy config get jj-fzf.last-undo 2>/dev/null) &&
jj --no-pager --ignore-working-copy op log -n1 --no-graph -T "$OP_LOG_FIRSTLINE" | grep -qF ": undo operation $LAST_OPID" ; then
jj --no-pager --ignore-working-copy op log --color=always -T "$JJ_FZF_OP_LOG_ONELINE16" |
sed -r "1,/${LAST_OPID:0:16}\b/s/([@○])/⋯/" # ⮌ ⋯ ⤺↶
gsed -r "1,/${LAST_OPID:0:16}\b/s/([@○])/⋯/" # ⮌ ⋯ ⤺↶
else
jj --no-pager --ignore-working-copy op log --color=always -T "$JJ_FZF_OP_LOG_ONELINE16"
fi
Expand Down Expand Up @@ -1567,7 +1567,7 @@ list_key_bindings()
}
SHOW_KEYS="$(jj --ignore-working-copy config get 'jj-fzf.show-keys' 2>/dev/null || echo true)"
[[ "$*" =~ --key-toggle ]] && {
SHOW_KEYS="$(echo "$SHOW_KEYS" | sed 's/^false/x/; s/^true/false/; s/^x/true/')"
SHOW_KEYS="$(echo "$SHOW_KEYS" | gsed 's/^false/x/; s/^true/false/; s/^x/true/')"
jj --ignore-working-copy config set --user 'jj-fzf.show-keys' "$SHOW_KEYS"
}
$SHOW_KEYS || {
Expand Down

0 comments on commit d5efe09

Please sign in to comment.