mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-03-15 23:22:53 +08:00
Added a -s option to echo to mean "don't output spaces"
Replaced default prompt to stop calling printf. I opened a bug to replace the default prompt entirely with one that's cheaper.
This commit is contained in:
parent
f1d22b6300
commit
d09c9fba02
27
builtin.cpp
27
builtin.cpp
@ -1451,7 +1451,9 @@ static int builtin_functions( parser_t &parser, wchar_t **argv )
|
||||
}
|
||||
|
||||
/** The echo builtin.
|
||||
bash only respects -n if it's the first argument. We'll do the same. */
|
||||
bash only respects -n if it's the first argument. We'll do the same.
|
||||
We also support a new option -s to mean "no spaces"
|
||||
*/
|
||||
|
||||
static int builtin_echo( parser_t &parser, wchar_t **argv )
|
||||
{
|
||||
@ -1459,19 +1461,26 @@ static int builtin_echo( parser_t &parser, wchar_t **argv )
|
||||
if (! *argv++)
|
||||
return STATUS_BUILTIN_ERROR;
|
||||
|
||||
/* Process -n */
|
||||
bool show_newline = true;
|
||||
if (*argv && ! wcscmp(*argv, L"-n")) {
|
||||
show_newline = false;
|
||||
argv++;
|
||||
/* Process options */
|
||||
bool print_newline = true, print_spaces = true;
|
||||
while (*argv) {
|
||||
if (! wcscmp(*argv, L"-n")) {
|
||||
print_newline = false;
|
||||
argv++;
|
||||
} else if (! wcscmp(*argv, L"-s")) {
|
||||
print_spaces = false;
|
||||
argv++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
for (size_t idx = 0; argv[idx]; idx++) {
|
||||
if (idx > 0)
|
||||
if (print_spaces && idx > 0)
|
||||
stdout_buffer.push_back(' ');
|
||||
stdout_buffer.append(argv[idx]);
|
||||
}
|
||||
if (show_newline)
|
||||
if (print_newline)
|
||||
stdout_buffer.push_back('\n');
|
||||
return STATUS_BUILTIN_OK;
|
||||
}
|
||||
|
@ -1,6 +1,3 @@
|
||||
complete -c echo -s n --description "No newline"
|
||||
complete -c echo -s e --description "Use backslash escaped characters"
|
||||
complete -c echo -s E --description "Do not use backslash escaped characters"
|
||||
complete -c echo -l help --description "Display help and exit"
|
||||
complete -c echo -l version --description "Display version and exit"
|
||||
complete -c echo -s n --description "Do not output a newline"
|
||||
complete -c echo -s n --description "Do not separate arguments with spaces"
|
||||
complete -c echo -u
|
||||
|
@ -25,7 +25,7 @@ function fish_prompt --description "Write out the prompt"
|
||||
end
|
||||
end
|
||||
|
||||
printf '%s@%s %s%s%s# ' $USER $__fish_prompt_hostname "$__fish_prompt_cwd" (prompt_pwd) "$__fish_prompt_normal"
|
||||
echo -n -s "$USER" @ "$__fish_prompt_hostname" ' ' "$__fish_prompt_cwd" (prompt_pwd) "$__fish_prompt_normal" '# '
|
||||
|
||||
case '*'
|
||||
|
||||
@ -33,7 +33,7 @@ function fish_prompt --description "Write out the prompt"
|
||||
set -g __fish_prompt_cwd (set_color $fish_color_cwd)
|
||||
end
|
||||
|
||||
printf '%s@%s %s%s%s> ' $USER $__fish_prompt_hostname "$__fish_prompt_cwd" (prompt_pwd) "$__fish_prompt_normal"
|
||||
echo -n -s "$USER" @ "$__fish_prompt_hostname" ' ' "$__fish_prompt_cwd" (prompt_pwd) "$__fish_prompt_normal" '> '
|
||||
|
||||
end
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user