2 # TopGit wayback machine shell command
3 # (C) 2017 Kyle J. McKay <mackyle@gmail.com>
8 Usage: ${tgname:-tg} [...] -w [:]<tgtag> shell [--directory=<dirpath>] [-q] [--] [<arg>...]"
12 if [ "${1:-0}" != 0 ]; then
13 printf '%s\n' "$USAGE" >&2
15 printf '%s\n' "$USAGE"
22 while [ $# -gt 0 ]; do case "$1" in
23 -h|
--help|
--directory|
--directory=*)
26 --directory|
--directory=*)
27 # only one is allowed and it should have been handled by tg.sh
28 # which means this is the second one and it's a usage error
39 echo "Unknown option: $1" >&2
46 [ -n "$wayback" ] || usage
1
48 # Everything's been handled by tg.sh except for verifying a TTY
49 # is present for an interactive shell
55 [ -z "$SHELL" ] || theshell
="$SHELL"
56 test -t 0 || die
"cannot use interactive wayback shell on non-TTY STDIN"
58 test -t 2 || redir
='2>&1'
62 die
"cannot use interactive wayback shell on non-TTY STDOUT/STDERR"
64 PS1
='[../${PWD##*/}] wayback$ ' && export PS1
66 [ -n "$wbname" ] || wbname
='now?!'
67 eval 'info "going wayback to $wbname..."' "$redir"
69 if [ -z "$quote" ]; then
72 # attempt to "quote" the arguments and then glue them together
74 for cmdword
in "$@"; do
76 case "$cmdword" in [A-Za-z_
]*)
77 if test z
"${cmdword%%[!A-Za-z_0-9]*}" = z
"$cmdword"
80 else case "$cmdword" in *=*)
81 cmdvar
="${cmdword%%=*}"
82 if test z
"${cmdvar%%[!A-Za-z_0-9]*}" = z
"$cmdvar"
84 v_quotearg cmdword
"${cmdword#*=}"
85 cmdword
="$cmdvar=$cmdword"
90 test z
"$cmdworddq" = z || v_quotearg cmdword
"$cmdword"
91 cmdstr
="${cmdstr:+$cmdstr }$cmdword"
96 eval '"$theshell"' "$cmd" "$redir"