From 0e6adff3a0bca33fabee0cc5621e44fdeb798266 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Mon, 1 Jan 2018 07:45:13 -0800 Subject: [PATCH] tg-checkout.sh: allow +[n] and -[n] aliases Allow `tg checkout +` to mean `tg checkout next` or even `tg checkout +n` to mean `tg checkout next n`. Similarly `tg checkout -` to mean `tg checkout prev` or `tg checkout -n` to mean `tg checkout prev n`. Whitespace is allowed between the +/- and the count. Signed-off-by: Kyle J. McKay --- README | 8 +++++++- tg-checkout.sh | 33 ++++++++++++++++++++++----------- tg.sh | 2 +- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/README b/README index e14b1fc..02162a8 100644 --- a/README +++ b/README @@ -1515,7 +1515,7 @@ tg checkout is not ``-a``, ``--all``, ``-h``, ``--help``, ``goto``, ``--``, ``n``, ``next``, ``push``, ``child``, ``p``, ``prev``, ``previous``, - ``pop``, ``parent`` or ``..``. + ``pop``, ``parent``, ``+``, ``-`` or ``..``. ``tg checkout [goto] [--] --series[=]`` Check out a topic branch that belongs to @@ -1523,6 +1523,9 @@ tg checkout A list with descriptions (``tg info --series``) will be shown to choose from if more than one. + ``tg checkout + []`` + An alias for ``next``. + ``tg checkout push []`` An alias for ``next``. @@ -1532,6 +1535,9 @@ tg checkout ``tg checkout`` Semi-deprecated alias for ``next``. + ``tg checkout - []`` + An alias for ``prev``. + ``tg checkout pop []`` An alias for ``prev``. diff --git a/tg-checkout.sh b/tg-checkout.sh index f98ad90..7184852 100644 --- a/tg-checkout.sh +++ b/tg-checkout.sh @@ -1,7 +1,7 @@ #!/bin/sh # TopGit - A different patch queue manager # Copyright (C) 2013 Per Cederqvist -# Copyright (C) 2015,2017 Kyle J. McKay +# Copyright (C) 2015,2017,2018 Kyle J. McKay # All rights reserved. # GPLv2 @@ -68,6 +68,9 @@ while [ $# -gt 0 ]; do case "$1" in dashdash=1 break ;; + -[0-9]*) + break + ;; -?*) usage 1 "Unknown option: $1" ;; @@ -77,13 +80,21 @@ while [ $# -gt 0 ]; do case "$1" in esac; shift; done [ $# -ne 0 ] || [ -n "$dashdash" ] || set -- "next" # deprecated "next" alias [ $# -gt 0 ] || usage 1 -[ -n "$dashdash" ] || -case "$1" in - n|next|push|child) shift;; - p|prev|previous|pop|parent|..) reverse=1; shift;; - -*) usage 1;; - *) dashdash=1;; -esac +pinstep= +[ -n "$dashdash" ] || { + case "$1" in +[0-9]*|-[0-9]*) + arg="$1" + shift + set -- "${arg%%[0-9]*}" "${arg#?}" "$@" + pinstep=1 + esac + case "$1" in + +|n|next|push|child) shift;; + -|p|prev|previous|pop|parent|..) reverse=1; shift;; + -*) usage 1;; + *) dashdash=1;; + esac +} choices="$(get_temp choices)" desc= @@ -115,11 +126,11 @@ else [1-9]*) [ "$1" = "${1%%[!0-9]*}" ] || usage 1 "invalid next/previous step count" v_verify_topgit_branch branch "${branch:-HEAD}" - navigate_deps -t -s="$1" ${reverse:+-r} "$branch" >"$choices" || exit + navigate_deps -t -s="$1" ${reverse:+-r} ${pinstep:+-k} "$branch" >"$choices" || exit pl="s" dir="next" - [ "$steps" != 1 ] || pl= + [ "$1" != 1 ] || pl= [ -z "$reverse" ] || dir="previous" - no_branch_found="No $dir TopGit branch(es) found $steps$pl away" + no_branch_found="No $dir TopGit branch(es) found $1 step$pl away" ;; *) usage 1 "invalid next/previous movement; must be --all or positive number" diff --git a/tg.sh b/tg.sh index 83f0e1b..458da1b 100644 --- a/tg.sh +++ b/tg.sh @@ -1,7 +1,7 @@ #!/bin/sh # TopGit - A different patch queue manager # Copyright (C) 2008 Petr Baudis -# Copyright (C) 2014-2017 Kyle J. McKay +# Copyright (C) 2014-2018 Kyle J. McKay # All rights reserved. # GPLv2 -- 2.11.4.GIT