Reputation: 620
I have a script that I use to start commands on some docker-compose containers.
The script runs docker-compose exec -T {container} {command}
.
I have to use the -T (Disable pseudo-TTY allocation. By default docker compose exec allocates a TTY) option because otherwise my precommit hook, which also runs this script, errors with a panic: provided file is not a console
.
However when I run the script on my own terminal I get a broken output that looks like this :
run v1.22.10
$ vite build
vite v2.7.13 building for production...
transforming...
✓ 378 modules transformed.
rendering chunks...
public/front/assets/Inter-Thin.77d96c1c.woff2 97.30 KiB
public/front/assets/Inter-ExtraLight.b6cd094a.woff2 101.79 KiB
public/front/assets/Inter-ThinItalic.d82beee8.woff2 104.00 KiB
public/front/assets/Inter-ExtraLightItalic.db229bf3.woff2 108.78 KiB
public/front/assets/Inter-Light.36b86832.woff2 101.89 KiB
public/front/assets/Inter-LightItalic.737ac201.woff2 108.72 KiB
public/front/assets/Inter-Regular.d612f121.woff2 96.55 KiB
public/front/assets/Inter-Medium.1b498b95.woff2 103.44 KiB
public/front/assets/Inter-Italic.900058df.woff2 104.37 KiB
public/front/assets/Inter-MediumItalic.81600858.woff2 109.55 KiB
public/front/assets/Inter-SemiBold.15226129.woff2 103.32 KiB
public/front/assets/Inter-SemiBoldItalic.3b6df7d0.woff2 109.42 KiB
public/front/assets/Inter-BoldItalic.3f211964.woff2 109.19 KiB
public/front/assets/Inter-Bold.c63158ba.woff2 103.65 KiB
public/front/assets/Inter-ExtraBoldItalic.cf6b1d6c.woff2 109.09 KiB
public/front/assets/Inter-ExtraBold.307d9809.woff2 103.62 KiB
public/front/assets/Inter-Black.fc10113c.woff2 100.46 KiB
public/front/assets/Inter-BlackItalic.bc80081d.woff2 106.20 KiB
public/front/assets/TRYVesterbro-Light.59d4e0df.woff2 134.08 KiB
public/front/assets/TRYVesterbro-Regular.cf9a26a9.woff2 139.92 KiB
public/front/assets/TRYVesterbro-Medium.116a42a4.woff2 142.17 KiB
public/front/assets/TRYVesterbro-Bold.ac6caaee.woff2 144.62 KiB
public/front/assets/TRYVesterbro-ExtraBold.9be0564d.woff2 142.90 KiB
Without -T the output is fine (every line is aligned correctly) but the hook will not work with the previously stated error.
If that's relevant I use zsh for my shell but I tried running in bash and it doesn't solve the issue either.
Is there any way to fix the terminal output while retaining -T in docker-compose ?
Upvotes: 1
Views: 877
Reputation: 620
So after investigating I found that the output only contained \n
and not \n\r
. The missing \r
is the reason the output skips a line but doesn't go back to the start (carriage return).
I made a simple bash function that I added to my .zshrc
(you can add it to your .bashrc
too).
clout() {
$@ | sed 's/$/\r/'
}
Use it like this
clout your_command args
This function pipes the output of your command and adds a \r
when it sees a \n
.
This is the best solution I found. I am still open to better solutions if someone has one.
Upvotes: 1