mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-03-27 14:45:13 +08:00
Don't replace tilde for error messages if we have no $HOME
This was an issue with "--no-execute", which has no variables and therefore no $HOME: ```fish fish --no-execute /path/to/file ``` would say the error is in `~/path/to/file`. Instead, since this is just for a message, we simply return the filename without doing the replacement. Fixes #10171
This commit is contained in:
parent
81c8cd1b61
commit
e318585021
@ -307,6 +307,11 @@ pub fn replace_home_directory_with_tilde(s: &wstr, vars: &dyn Environment) -> WS
|
|||||||
if result.starts_with("/"L) {
|
if result.starts_with("/"L) {
|
||||||
let mut home_directory = "~"L.to_owned();
|
let mut home_directory = "~"L.to_owned();
|
||||||
expand_tilde(&mut home_directory, vars);
|
expand_tilde(&mut home_directory, vars);
|
||||||
|
// If we can't get a home directory, don't replace anything.
|
||||||
|
// This is the case e.g. with --no-execute
|
||||||
|
if home_directory.is_empty() {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
if !home_directory.ends_with("/"L) {
|
if !home_directory.ends_with("/"L) {
|
||||||
home_directory.push('/');
|
home_directory.push('/');
|
||||||
}
|
}
|
||||||
|
@ -23,5 +23,14 @@ echo "begin; echo oops" | $fish -n
|
|||||||
echo $status
|
echo $status
|
||||||
#CHECK: 127
|
#CHECK: 127
|
||||||
|
|
||||||
|
echo "begin" > broken
|
||||||
|
$fish -n $PWD/broken
|
||||||
|
#CHECKERR: /{{.*}}broken (line 1): Missing end to balance this begin
|
||||||
|
#CHECKERR: begin
|
||||||
|
#CHECKERR: ^~~~^
|
||||||
|
#CHECKERR: warning: Error while reading file /{{.*}}broken
|
||||||
|
|
||||||
|
rm broken
|
||||||
|
|
||||||
# Littlecheck assumes a status of 127 means the shebang was invalid.
|
# Littlecheck assumes a status of 127 means the shebang was invalid.
|
||||||
exit 0
|
exit 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user