1

I rarely post a question because I tend to get obsessed with trying to figure things out on my own, but today I am really stuck.... and I've had a long week and my brain is dead...

anyways, I am trying to load a var that draws a horizontal straight line the length of my console.

I've tried drawing the line a couple of ways:

The '⎼' is not an underscore, the char sits a little higher than the underscore ie: ⎼_

  1. printf '⎼%.s' $(seq 1 $COLUMNS)

  2. python3 -c "print('⎼' * $COLUMNS)"

both commands draws the line, and when I assign it to a var like: HORZLINE=$(printf '⎼%.s' $(seq 1 $COLUMNS)

and then call $HORZLINE, it also draws the line.

I run into problems when I try to add that line (HORZLINE=$(printf '⎼%.s' $(seq 1 $COLUMNS)) to .bashrc and try to load it on start up.

The var loads, but the whole line doesn't load. Only one char is loaded. So when I try:

$: echo -e "$HORZLINE" ⎼

AFTER the terminal boots, if I source the .bashrc file again, the variable loads properly and draws the whole line.

Anyone have any ideas as to what I am doing wrong, or what is going on?

**

UPDATE - SOLVED

**

I just wanted to give you guys a heads up and update this for anyone out there experiencing the same problem..

All I had to do to fix the problem was to enable force_color_prompt (uncomment it in .bashrc)

Here's a screen shot of my prompt not loading correctly: force_color_prompt commented out

and here is what it is supposed to look like: force_color_prompt enabled

I feel so stupid. I spent so long trying all these different things, when I should have just looked at the bashrc.

But just so you know, I didn't even think about the force_color_prompt because the terminal was doing some wierd things, like: 1. if I launched mate-terminal, the prompt loaded correctly 2. I re-launch xterm, and NOTHING 3. Messed around with the preferences in xterm, changed the font, launch the terminal again, and it stopped working. BUT if I changed the font back to systems default, it would work again.

So I was messing around with xterm's setting, which if you've had experience with, isn't so easy.

Anyways.. thats it.

Thanks for all your help.

0

The issue is that even when checkwinsize is set, the $COLUMNS variable doesn't get set until a SIGWINCH signal is received.

I'm not sure if it's the right way to do it, but this seems to work for me:

kill -s SIGWINCH $$
HORZLINE=$(printf '⎼%.s' $(seq 1 $COLUMNS))
echo "$HORZLINE"

[EDIT: you don't need -e since there are no escape sequences in the string.]

|improve this answer|||||
0

This doesn't directly solve your problem but in my ~/.bashrc I print a horizontal line in between each command:

terminal dividing line.png

This is accomplished by setting $PS1 in ~/.bashrc:


Divider=""
for ((i=0; i<$COLUMNS; i++)) ; do
    Divider="$Divider""─"
done

if [ "$color_prompt" = yes ]; then
    PS1='${Divider}\n${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${Divider}\n${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi

unset color_prompt force_color_prompt

Note: if you change the width of the gnome-terminal windows you need to resource .bashrc with the command . ~/.bashrc to get the dividing line resized in the command prompt.

|improve this answer|||||
0

like I added to my question, the issue was because I didn't have force_color_prompt enabled in .bashrc.

once I uncommented the line, the variables loaded properly.

|improve this answer|||||
0

From the bash man page for COLUMNS,
Automatically set if the checkwinsize option is enabled or in an interactive shell upon receipt of a SIGWINCH.
So the key is "interactive shell". At a terminal type:
printf '⎼%.s' $(seq 1 $COLUMNS)
You get the line.

Put that command into a file (myline), set the executable bit and try:
./myline
Single char output.

bash myline
Single char output

bash -i myline
You get the line again with the explicit "-i" to force an interactive shell.

|improve this answer|||||
  • checkwinsize IS enabled in .bashrc and calling "$-" gives me: "himBH" – Booey Dec 30 '19 at 1:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.