Pergunta

I have this loop at config.fish:

set W_COLS (tput cols)

for x in (seq $W_COLS)
  echo $x
end

This works great, iterating trought my terminal's width. I get and output of:

1
2
3
.
.
.
80

I'd like to print the number side by side, without a new line.

I tried doing echo -n $x but this caused the loop to not work anymore, and I just get a barebones shell:

Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
>

Why is the loop failing?

Foi útil?

Solução

A little question context: this is happening inside the fish_prompt function. The function works when called directly but not when called as the prompt.

The problem is that the terminal window is too narrow and Fish is not liking it for some undocumented reason. To work around the problem

  1. show one less character than the terminal length
  2. Put a newline after the loop

so the loop would look like

for x in (seq (math $W_COLS - 1))
    echo -n '-'
end
echo

Thanks mainly goes to adisbladis on #fish

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top