Skip to content

Conversation

@somewatson
Copy link

This mod adds bat to code-server, to be installed/updated during container start.

Bat is a cat clone with syntax highlighting and Git integration.

It also includes bat-extras, ripgrep, and aliases for bat in bash and zsh.

linuxserver.io


  • I have read the contributing guideline and understand that I have made the correct modifications

Description:

This mod includes the following features:

  1. Installs the bat and ripgrep packges
  2. It includes an alias for bat since the package will install it under batcat in Ubuntu due to a name collision with another package. It will include the alias in bash and zsh if it's not already included by checking for an existing alias.
  3. It also installed bat-extras which are helper functions for integrating into tools like git
  4. Lastly, it grants appropriate permissions to the bat-extras folder to make sure it can execute it properly

Benefits of this PR and context:

This is in response to an issue I created #1072.

Bat is useful for viewing files in terminal since it's an improved version of cat and offers a lot of useful syntax highlighting and integration with other tools, like git.

There are tools built into the IDE for viewing git diffs and so on, but when you're already typing in the terminal, I have often found myself using bat since I'm already typing commands in terminal to begin with and I've started including this mod in every instance of code-server I run.

I think it would be nice to have it as an option for other developers as well.

How Has This Been Tested?

Yes, I'm running it on all of my instances of code-server.

I tested to make sure it works properly on a fresh install. I also ensured it is idempotent and works on an existing home folder /config.

Source / References:

Ripgrep has also been included because it is a requirment of bat-extras.

This mod adds bat to code-server, to be installed/updated during container start.

Bat is a cat clone with syntax highlighting and Git integration.

It also includes bat-extras, ripgrep, and aliases for bat in bash and zsh.
@LinuxServer-CI
Copy link

PR build pushed to ghcr.io/linuxserver/mods:pull_request_1073

@somewatson somewatson mentioned this pull request Oct 27, 2025
1 task
@somewatson
Copy link
Author

I've done my best to follow the documentation in the README for submitting a PR. One question I have is, in order for it to work for myself on my own dockerhub, I have to update the BuildImage.yml file, like so:

Screenshot 2025-10-27 at 3 59 49 AM

However, how do we ensure the correct values are merged in here in the official repo?

- Make sure that linuxserver is the endpoint
- Restore BuildImage.yml env vars that are labeled "don't modify" to the original values
@LinuxServer-CI
Copy link

PR build pushed to ghcr.io/linuxserver/mods:pull_request_1073

Separate the git clone step from the installation step

It doesn't need to be cloned every time, but it should be installed every time
@LinuxServer-CI
Copy link

PR build pushed to ghcr.io/linuxserver/mods:pull_request_1073

Set MULTI_ARCH to false, since it's not needed
@LinuxServer-CI
Copy link

PR build pushed to ghcr.io/linuxserver/mods:pull_request_1073

@somewatson
Copy link
Author

@aptalca ty for the comments, I've made all the changes requested so far 👍

if ! command -v zsh >/dev/null 2>&1; then
echo "**** zsh not installed, skipping alias setup ****"
else
if [ -f ~/.zshrc ]; then
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use absolute paths. The home folder for the abc user is /config

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, in the next commit I'll fix that

echo 'Installing bat-extras'
cd ~/.bat-extras/src
chmod +x ~/.bat-extras/src/*.sh
ln -s ~/.bat-extras/src/*.sh /usr/local/bin
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this fail on a restart since the symlinks already exist?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thanks for pointing that out. Here's the logs I found on restart:

code-server-somewatson  | Installing bat-extras
code-server-somewatson  | ln: failed to create symbolic link '/usr/local/bin/batdiff.sh': File exists
code-server-somewatson  | ln: failed to create symbolic link '/usr/local/bin/batgrep.sh': File exists
code-server-somewatson  | ln: failed to create symbolic link '/usr/local/bin/batman.sh': File exists
code-server-somewatson  | ln: failed to create symbolic link '/usr/local/bin/bat-modules.sh': File exists
code-server-somewatson  | ln: failed to create symbolic link '/usr/local/bin/batpipe.sh': File exists
code-server-somewatson  | ln: failed to create symbolic link '/usr/local/bin/batwatch.sh': File exists
code-server-somewatson  | ln: failed to create symbolic link '/usr/local/bin/prettybat.sh': File exists
code-server-somewatson  | Setting permissions for bat-extras

Notably, it still moves onto the next step and doesn't exit. But I will fix it so it doesn't error like this.

echo 'Bat-extras already cloned, skipping'
else
echo 'Cloning bat-extras repo'
git clone https://github.com/eth-p/bat-extras.git ~/.bat-extras
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it only gets cloned once on first start, does it need to be updated later?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Let me look into updating that.

- Use absolute paths
- Update bat-extras if it has already been cloned
- Fix symlink to not error if it already exists

Chose to force the symlink because there might be new symlinks after a pull
So I want an update to behave the same every time, which is to install all the scripts
@LinuxServer-CI
Copy link

PR build pushed to ghcr.io/linuxserver/mods:pull_request_1073

@somewatson
Copy link
Author

@aptalca ty for the comments. I made the following changes:

  • Use absolute paths
  • Update bat-extras if it has already been cloned
  • Fix symlink command to not error if the links already exist

I chose to force the symlink because there might be new symlinks after a pull. I want an update to behave the same every time, which is to install all the scripts included in the update.

@LinuxServer-CI
Copy link

PR build pushed to ghcr.io/linuxserver/mods:pull_request_1073

@LinuxServer-CI
Copy link

PR build pushed to ghcr.io/linuxserver/mods:pull_request_1073

@aptalca
Copy link
Member

aptalca commented Nov 4, 2025

Looks good to me, but please test the pr build above and test multiple container restarts and recreation to make sure it works as expected.

I vaguely remember an issue with a git pull failing when run as root after a restart.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants