mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-28 13:53:10 +00:00
c4593828f4
* commandline: Add --is-valid option to query whether it's syntactically complete This means querying when the commandline is in a state that it could be executed. Because our `execute` bind function also inserts a newline if it isn't. One case that's not handled right now: `execute` also expands abbreviations, those can technically make the commandline invalid again. Unfortunately we have no real way to *check* without doing the replacement. Also since abbreviations are only available in command position when you _execute_ them the commandline will most likely be valid. This is enough to make transient prompts work: ```fish function reset-transient --on-event fish_postexec set -g TRANSIENT 0 end function maybe_execute if commandline --is-valid set -g TRANSIENT 1 commandline -f repaint else set -g TRANSIENT 0 end commandline -f execute end bind \r maybe_execute ``` and then in `fish_prompt` react to $TRANSIENT being set to 1.
19 lines
433 B
Fish
19 lines
433 B
Fish
#RUN: %fish %s
|
|
|
|
commandline --input "echo foo | bar" --is-valid
|
|
and echo Valid
|
|
# CHECK: Valid
|
|
|
|
commandline --input "echo foo | " --is-valid
|
|
or echo Invalid $status
|
|
# CHECK: Invalid 2
|
|
|
|
# TODO: This seems a bit awkward?
|
|
# The empty commandline is an error, not incomplete?
|
|
commandline --input '' --is-valid
|
|
or echo Invalid $status
|
|
# CHECK: Invalid 1
|
|
|
|
commandline --input 'echo $$' --is-valid
|
|
or echo Invalid $status
|
|
# CHECK: Invalid 1
|