gwqadd 0.3.2 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -3
- package/bin/gwqadd.mjs +38 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -45,15 +45,19 @@ Then add the shell integration:
|
|
|
45
45
|
|
|
46
46
|
```sh
|
|
47
47
|
# zsh — ~/.zshrc
|
|
48
|
-
eval "$(gwqadd --init zsh)"
|
|
48
|
+
eval "$(command gwqadd --init zsh)"
|
|
49
49
|
|
|
50
50
|
# bash — ~/.bashrc
|
|
51
|
-
eval "$(gwqadd --init bash)"
|
|
51
|
+
eval "$(command gwqadd --init bash)"
|
|
52
52
|
|
|
53
53
|
# fish — ~/.config/fish/config.fish
|
|
54
|
-
gwqadd --init fish | source
|
|
54
|
+
command gwqadd --init fish | source
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
+
`command` matters: each tool defines a shell function with its own name, so on a
|
|
58
|
+
second `source ~/.zshrc` the *function* would answer, capture the `--init` output
|
|
59
|
+
and try to `cd` into it. `command` skips functions and goes to the binary.
|
|
60
|
+
|
|
57
61
|
Reload the shell and `gwqadd` moves it.
|
|
58
62
|
|
|
59
63
|
Prefer a different name? `eval "$(gwqadd --init zsh --cmd gwa)"` gives you `gwa`.
|
package/bin/gwqadd.mjs
CHANGED
|
@@ -25,7 +25,7 @@ const HELP = `${PKG} ${VERSION} — create a branch and its gwq worktree here, a
|
|
|
25
25
|
|
|
26
26
|
USAGE
|
|
27
27
|
${PKG} [options] [<branch>]
|
|
28
|
-
eval "$(${PKG} --init zsh)"
|
|
28
|
+
eval "$(command ${PKG} --init zsh)" # then \`${PKG}\` moves the shell itself
|
|
29
29
|
|
|
30
30
|
OPTIONS
|
|
31
31
|
--init <shell> print shell integration for zsh | bash | fish, then exit
|
|
@@ -247,7 +247,7 @@ function shellInit(shell, fnName) {
|
|
|
247
247
|
|
|
248
248
|
if (shell === 'zsh') {
|
|
249
249
|
return `# ${PKG} ${VERSION} — zsh integration
|
|
250
|
-
# Add to ~/.zshrc: eval "$(${PKG} --init zsh)"
|
|
250
|
+
# Add to ~/.zshrc: eval "$(command ${PKG} --init zsh)"
|
|
251
251
|
|
|
252
252
|
__${slug}_fallback=${shq(SELF)}
|
|
253
253
|
|
|
@@ -266,6 +266,18 @@ __${slug}_exec() {
|
|
|
266
266
|
# ${desc}.
|
|
267
267
|
${fnName}() {
|
|
268
268
|
emulate -L zsh
|
|
269
|
+
# These print to stdout for the caller — help text, a list, JSON — and one of
|
|
270
|
+
# them, --json, would collide with the --quiet added below. Capturing that and
|
|
271
|
+
# handing it to cd produced "file name too long" on --help. Pass them through.
|
|
272
|
+
local __a
|
|
273
|
+
for __a in "$@"; do
|
|
274
|
+
case $__a in
|
|
275
|
+
-h|--help|-V|--version|--init|--init=*|--json)
|
|
276
|
+
__${slug}_exec "$@"
|
|
277
|
+
return $?
|
|
278
|
+
;;
|
|
279
|
+
esac
|
|
280
|
+
done
|
|
269
281
|
local __dir
|
|
270
282
|
__dir=$(__${slug}_exec --quiet "$@") || return $?
|
|
271
283
|
# Empty is not a failure: --no-cd, --help and --version all succeed without
|
|
@@ -278,7 +290,7 @@ ${fnName}() {
|
|
|
278
290
|
|
|
279
291
|
if (shell === 'bash') {
|
|
280
292
|
return `# ${PKG} ${VERSION} — bash integration
|
|
281
|
-
# Add to ~/.bashrc: eval "$(${PKG} --init bash)"
|
|
293
|
+
# Add to ~/.bashrc: eval "$(command ${PKG} --init bash)"
|
|
282
294
|
|
|
283
295
|
__${slug}_fallback=${shq(SELF)}
|
|
284
296
|
|
|
@@ -296,6 +308,18 @@ __${slug}_exec() {
|
|
|
296
308
|
|
|
297
309
|
# ${desc}.
|
|
298
310
|
${fnName}() {
|
|
311
|
+
# These print to stdout for the caller — help text, a list, JSON — and one of
|
|
312
|
+
# them, --json, would collide with the --quiet added below. Capturing that and
|
|
313
|
+
# handing it to cd produced "file name too long" on --help. Pass them through.
|
|
314
|
+
local __a
|
|
315
|
+
for __a in "$@"; do
|
|
316
|
+
case "$__a" in
|
|
317
|
+
-h|--help|-V|--version|--init|--init=*|--json)
|
|
318
|
+
__${slug}_exec "$@"
|
|
319
|
+
return $?
|
|
320
|
+
;;
|
|
321
|
+
esac
|
|
322
|
+
done
|
|
299
323
|
local __dir
|
|
300
324
|
__dir=$(__${slug}_exec --quiet "$@") || return $?
|
|
301
325
|
[ -n "$__dir" ] || return 0
|
|
@@ -306,7 +330,7 @@ ${fnName}() {
|
|
|
306
330
|
|
|
307
331
|
if (shell === 'fish') {
|
|
308
332
|
return `# ${PKG} ${VERSION} — fish integration
|
|
309
|
-
# Add to ~/.config/fish/config.fish: ${PKG} --init fish | source
|
|
333
|
+
# Add to ~/.config/fish/config.fish: command ${PKG} --init fish | source
|
|
310
334
|
|
|
311
335
|
set -g __${slug}_fallback ${fishq(SELF)}
|
|
312
336
|
|
|
@@ -322,6 +346,15 @@ function __${slug}_exec
|
|
|
322
346
|
end
|
|
323
347
|
|
|
324
348
|
function ${fnName} --description ${fishq(desc)}
|
|
349
|
+
# Help text, a list or JSON goes to the caller, not to cd. --json would also
|
|
350
|
+
# collide with the --quiet added below.
|
|
351
|
+
for __a in $argv
|
|
352
|
+
switch $__a
|
|
353
|
+
case -h --help -V --version --init '--init=*' --json
|
|
354
|
+
__${slug}_exec $argv
|
|
355
|
+
return $status
|
|
356
|
+
end
|
|
357
|
+
end
|
|
325
358
|
set -l __dir (__${slug}_exec --quiet $argv)
|
|
326
359
|
# \`set\` reports the command substitution's status, but not every fish
|
|
327
360
|
# release agrees on that. Capturing it keeps a failed run from cd'ing,
|
|
@@ -1169,7 +1202,7 @@ async function finish({ repo, branch, base, path, created }) {
|
|
|
1169
1202
|
stderr.write('\n');
|
|
1170
1203
|
stderr.write(renderBox(cdCommand) + '\n');
|
|
1171
1204
|
stderr.write(
|
|
1172
|
-
` ${dim('tip:')} ${dim(`eval "$(${PKG} --init zsh)"`)} ${dim('lets')} ` +
|
|
1205
|
+
` ${dim('tip:')} ${dim(`eval "$(command ${PKG} --init zsh)"`)} ${dim('lets')} ` +
|
|
1173
1206
|
`${bold(PKG)} ${dim('cd for you')}\n`,
|
|
1174
1207
|
);
|
|
1175
1208
|
|