Skip to content

Commit

Permalink
[interactive] Respect OILS_COMP_UI in oshrc/yshrc (#2244)
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
melvinw and Andy C authored Feb 3, 2025
1 parent 0002e42 commit 847984b
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 11 deletions.
25 changes: 14 additions & 11 deletions core/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -1082,8 +1082,21 @@ def Main(
mutable_opts.set_redefine_const()
mutable_opts.set_redefine_source()

# NOTE: rc files loaded AFTER _InitDefaultCompletions.
for rc_path in rc_paths:
with state.ctx_ThisDir(mem, rc_path):
try:
SourceStartupFile(fd_state, rc_path, lang, parse_ctx,
cmd_ev, errfmt)
except util.UserExit as e:
return e.status

completion_display = state.MaybeString(mem, 'OILS_COMP_UI')
if completion_display is None:
completion_display = flag.completion_display

if readline:
if flag.completion_display == 'nice':
if completion_display == 'nice':
display = comp_ui.NiceDisplay(comp_ui_state, prompt_state,
debug_f, readline, signal_safe) # type: comp_ui._IDisplay
else:
Expand All @@ -1101,21 +1114,11 @@ def Main(
debug_f, signal_safe)

process.InitInteractiveShell(signal_safe) # Set signal handlers

# The interactive shell leads a process group which controls the terminal.
# It MUST give up the terminal afterward, otherwise we get SIGTTIN /
# SIGTTOU bugs.
with process.ctx_TerminalControl(job_control, errfmt):

# NOTE: rc files loaded AFTER _InitDefaultCompletions.
for rc_path in rc_paths:
with state.ctx_ThisDir(mem, rc_path):
try:
SourceStartupFile(fd_state, rc_path, lang, parse_ctx,
cmd_ev, errfmt)
except util.UserExit as e:
return e.status

assert line_reader is not None
line_reader.Reset() # After sourcing startup file, render $PS1

Expand Down
11 changes: 11 additions & 0 deletions doc/ref/chap-special-var.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,17 @@ Override the default OSH history location.

Override the default YSH history location.

## Interactive

### OILS_COMP_UI

Set which completion UI to use. Defaults to `minimal`.

- `minimal` - a UI that approximates the default behavior of GNU readline.
- `nice` - a UI with a fancy pager and a prompt with horizontal scrolling instead of wrapping.

This variable is currently only checked once during shell initialization.

## cd

### PWD
Expand Down
1 change: 1 addition & 0 deletions doc/ref/toc-osh.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ X [Unsupported] enable
</h2>

```chapter-links-special-var
[Interactive] OILS_COMP_UI
[Oils VM] OILS_VERSION LIB_OSH
[POSIX Special] $@ $* $# $? $- $$ $! $0 $9
[Shell Vars] IFS X LANG X GLOBIGNORE
Expand Down
1 change: 1 addition & 0 deletions doc/ref/toc-ysh.md
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,7 @@ X [External Lang] BEGIN END when (awk)
[YSH Tracing] SHX_indent SHX_punct SHX_pid_str
[YSH read] _reply
[History] YSH_HISTFILE
[Interactive] OILS_COMP_UI
[Oils VM] OILS_VERSION
OILS_GC_THRESHOLD OILS_GC_ON_EXIT
OILS_GC_STATS OILS_GC_STATS_FD
Expand Down
30 changes: 30 additions & 0 deletions test/manual.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env bash
#
# Manual tests
#
# Usage:
# test/manual.sh <function name>

: ${LIB_OSH=stdlib/osh}
source $LIB_OSH/bash-strict.sh
source $LIB_OSH/task-five.sh

readonly OSHRC=_tmp/manual-oshrc

setup() {
cat >$OSHRC <<EOF
OILS_COMP_UI=nice
EOF
}

test-osh() {
# Test it manually
bin/osh --rcfile $OSHRC
}

test-ysh() {
# same OSHRC? Should it respect ENV.OILS_COMP_UI?
bin/ysh --rcfile $OSHRC
}

task-five "$@"

0 comments on commit 847984b

Please sign in to comment.