Skip to content

Commit 847984b

Browse files
melvinwAndy C
and
Andy C
authored
[interactive] Respect OILS_COMP_UI in oshrc/yshrc (#2244)
You can do # oshrc OILS_COMP_UI=nice Rather than osh --completion-display nice - Update docs - add test/manual.sh - thinking about ENV.OILS_COMP_UI issue --------- Co-authored-by: Andy C <[email protected]>
1 parent 0002e42 commit 847984b

File tree

5 files changed

+57
-11
lines changed

5 files changed

+57
-11
lines changed

core/shell.py

+14-11
Original file line numberDiff line numberDiff line change
@@ -1082,8 +1082,21 @@ def Main(
10821082
mutable_opts.set_redefine_const()
10831083
mutable_opts.set_redefine_source()
10841084

1085+
# NOTE: rc files loaded AFTER _InitDefaultCompletions.
1086+
for rc_path in rc_paths:
1087+
with state.ctx_ThisDir(mem, rc_path):
1088+
try:
1089+
SourceStartupFile(fd_state, rc_path, lang, parse_ctx,
1090+
cmd_ev, errfmt)
1091+
except util.UserExit as e:
1092+
return e.status
1093+
1094+
completion_display = state.MaybeString(mem, 'OILS_COMP_UI')
1095+
if completion_display is None:
1096+
completion_display = flag.completion_display
1097+
10851098
if readline:
1086-
if flag.completion_display == 'nice':
1099+
if completion_display == 'nice':
10871100
display = comp_ui.NiceDisplay(comp_ui_state, prompt_state,
10881101
debug_f, readline, signal_safe) # type: comp_ui._IDisplay
10891102
else:
@@ -1101,21 +1114,11 @@ def Main(
11011114
debug_f, signal_safe)
11021115

11031116
process.InitInteractiveShell(signal_safe) # Set signal handlers
1104-
11051117
# The interactive shell leads a process group which controls the terminal.
11061118
# It MUST give up the terminal afterward, otherwise we get SIGTTIN /
11071119
# SIGTTOU bugs.
11081120
with process.ctx_TerminalControl(job_control, errfmt):
11091121

1110-
# NOTE: rc files loaded AFTER _InitDefaultCompletions.
1111-
for rc_path in rc_paths:
1112-
with state.ctx_ThisDir(mem, rc_path):
1113-
try:
1114-
SourceStartupFile(fd_state, rc_path, lang, parse_ctx,
1115-
cmd_ev, errfmt)
1116-
except util.UserExit as e:
1117-
return e.status
1118-
11191122
assert line_reader is not None
11201123
line_reader.Reset() # After sourcing startup file, render $PS1
11211124

doc/ref/chap-special-var.md

+11
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,17 @@ Override the default OSH history location.
379379

380380
Override the default YSH history location.
381381

382+
## Interactive
383+
384+
### OILS_COMP_UI
385+
386+
Set which completion UI to use. Defaults to `minimal`.
387+
388+
- `minimal` - a UI that approximates the default behavior of GNU readline.
389+
- `nice` - a UI with a fancy pager and a prompt with horizontal scrolling instead of wrapping.
390+
391+
This variable is currently only checked once during shell initialization.
392+
382393
## cd
383394

384395
### PWD

doc/ref/toc-osh.md

+1
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ X [Unsupported] enable
199199
</h2>
200200

201201
```chapter-links-special-var
202+
[Interactive] OILS_COMP_UI
202203
[Oils VM] OILS_VERSION LIB_OSH
203204
[POSIX Special] $@ $* $# $? $- $$ $! $0 $9
204205
[Shell Vars] IFS X LANG X GLOBIGNORE

doc/ref/toc-ysh.md

+1
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ X [External Lang] BEGIN END when (awk)
366366
[YSH Tracing] SHX_indent SHX_punct SHX_pid_str
367367
[YSH read] _reply
368368
[History] YSH_HISTFILE
369+
[Interactive] OILS_COMP_UI
369370
[Oils VM] OILS_VERSION
370371
OILS_GC_THRESHOLD OILS_GC_ON_EXIT
371372
OILS_GC_STATS OILS_GC_STATS_FD

test/manual.sh

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Manual tests
4+
#
5+
# Usage:
6+
# test/manual.sh <function name>
7+
8+
: ${LIB_OSH=stdlib/osh}
9+
source $LIB_OSH/bash-strict.sh
10+
source $LIB_OSH/task-five.sh
11+
12+
readonly OSHRC=_tmp/manual-oshrc
13+
14+
setup() {
15+
cat >$OSHRC <<EOF
16+
OILS_COMP_UI=nice
17+
EOF
18+
}
19+
20+
test-osh() {
21+
# Test it manually
22+
bin/osh --rcfile $OSHRC
23+
}
24+
25+
test-ysh() {
26+
# same OSHRC? Should it respect ENV.OILS_COMP_UI?
27+
bin/ysh --rcfile $OSHRC
28+
}
29+
30+
task-five "$@"

0 commit comments

Comments
 (0)