Skip to content

Commit

Permalink
Merge branch 'add-jj-am.sh--help'
Browse files Browse the repository at this point in the history
* Branch commit log:
  README.md: briefly describe jj-am.sh
  contrib/jj-am.sh: add --help
  jj-fzf: properly parse options --help, --key-bindings, --color=always
	Fix invalid matching of jj-fzf options within pasted `jj log` output args.

Signed-off-by: Tim Janik <[email protected]>
  • Loading branch information
tim-janik committed Dec 17, 2024
2 parents fedbc83 + cd80736 commit 46f82d4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ To end up with a linear history, the demo then shows how to merge a single branc
![Mega-Merge Workflow](https://github.com/user-attachments/assets/f944afa2-b6ea-438d-802b-8af83650a65f)
**Mega-Merge:** [Asciicast](https://asciinema.org/a/685256) [MP4](https://github.com/user-attachments/assets/eb1a29e6-b1a9-47e0-871e-b2db5892dbf1)

<!-- CONTRIB -->
## Contrib Directory

The `contrib/` directory contains additional tools or scripts that complement the main jj-fzf functionality.
These scripts are aimed at developers and provide useful utilities for working with jj.

* **jj-am.sh:** A very simple script that allows to apply patches to a jj repository.
`Usage: ~/jj-fzf/contrib/jj-am.sh [format-patch-file...]`

<!-- LICENSE -->
## License

Expand Down
19 changes: 18 additions & 1 deletion contrib/jj-am.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,30 @@
# This Source Code Form is licensed MPL-2.0: http://mozilla.org/MPL/2.0
set -Eeuo pipefail #-x
SCRIPTNAME=`basename $0` && function die { [ -n "$*" ] && echo "$SCRIPTNAME: **ERROR**: ${*:-aborting}" >&2; exit 127 ; }
VERSION=0.0.1-alpha
VERSION=0.2.0

# == Help ==
show_help()
{
cat <<-__EOF__
Usage: $SCRIPTNAME [OPTIONS...] PATCHFILE...
Apply one or more patch files (from git-format-patch) to a jj repository.
Options:
-h, --help Display this help and exit
--version Display version information and exit
Arguments:
PATCHFILE Path to a patch file containing commit message and diff
__EOF__
}

# == Parse Options ==
MBOXES=()
while test $# -ne 0 ; do
case "$1" in \
--version) echo "$SCRIPTNAME $VERSION"; exit ;;
-h|--help) show_help; exit 0 ;;
-*) die "unknown option: $1" ;;
*) MBOXES+=("$1") ;;
esac
Expand Down
19 changes: 11 additions & 8 deletions jj-fzf
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,15 @@ sed --version 2>/dev/null | grep -Fq 'GNU sed' && gsed() { \sed "$@"; } && expor
command -v column >/dev/null || column() { cat; }

# == Early Options ==
ONESHOT=false
SHOWHELP= SHOWKEYBINDINGS= COLORALWAYS= ONESHOT=false
while test $# -ne 0 ; do
case "$1" in \
--version) echo "$SCRIPTNAME $VERSION"; exit ;;
--oneshot) ONESHOT=true ;; # auto-exit after first command
*) break ;;
-h|--help) SHOWHELP=t ;;
--key-bindings) SHOWKEYBINDINGS=t ;;
--version) echo "$SCRIPTNAME $VERSION"; exit ;;
--oneshot) ONESHOT=true ;; # auto-exit after first command
--color=always) COLORALWAYS=t ;;
*) break ;;
esac
shift
done
Expand Down Expand Up @@ -1522,7 +1525,7 @@ HELP_OUTRO='

# == --help ==
HELPKEYS=$(declare -p KEYBINDINGS) && declare -A HELPKEYS="${HELPKEYS#*=}" # copy KEYBINDINGS -> HELPKEYS
if [[ " $* " =~ --help ]] ; then
if test -n "$SHOWHELP" ; then
# Key bdingins only shown in long form help
HELPKEYS[Shift-↑]='preview-up'
HELPKEYS[Ctrl-↑]='preview-up'
Expand All @@ -1537,9 +1540,9 @@ if [[ " $* " =~ --help ]] ; then
fi
DISPLAYKEYS="${!HELPKEYS[@]}"
DISPLAYKEYS=$(sort <<<"${DISPLAYKEYS// /$'\n'}" | grep -vF 'Ctrl-Alt-')
if [[ " $* " =~ --help ]] ; then
if test -n "$SHOWHELP" ; then
tty -s <&1 && COLOR=true || { COLOR=false; JJFZFPAGER=cat; }
[[ " $* " =~ --color ]] && COLOR=true
test -z "$COLORALWAYS" || COLOR=true
( :
echo -n "$HELP_INTRO"
for k in $DISPLAYKEYS ; do
Expand Down Expand Up @@ -1587,7 +1590,7 @@ list_key_bindings()
done
echo -n "$OUTPUT"
}
if [[ " $* " =~ --key-bindings ]] ; then
if test -n "$SHOWKEYBINDINGS" ; then
list_key_bindings "$@"
exit 0
fi
Expand Down

0 comments on commit 46f82d4

Please sign in to comment.