GithubHelp home page GithubHelp logo

deluan / zsh-in-docker Goto Github PK

View Code? Open in Web Editor NEW
827.0 8.0 103.0 52 KB

Install Zsh, Oh-My-Zsh and plugins inside a Docker container with one line!

License: MIT License

Dockerfile 9.41% Shell 85.73% Makefile 4.86%
zsh oh-my-zsh docker dockerfile vscode

zsh-in-docker's Introduction

Oh My Zsh Installer for Docker

Last Release Build Downloads

This is a script to automate Oh My Zsh installation in development containers. Works with any image based on Alpine, Ubuntu, Debian or Amazon Linux.

The original goal was to simplify setting up zsh and Oh My Zsh in a Docker image for use with VSCode's Remote Containers extension, but it can be used whenever you need a simple way to install Oh My Zsh and its plugins in a Docker image

Usage

One line installation: add the following line in your Dockerfile:

# Default powerline10k theme, no plugins installed
RUN sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v1.1.5/zsh-in-docker.sh)"

Optional arguments:

  • -t <theme> - Selects the theme to be used. Options are available here. By default the script installs and uses Powerlevel10k, one of the "fastest and most awesome" themes for zsh. This is my recommended theme. If <theme> is a url, the script will try to install the theme using git clone.

  • -p <plugin> - Specifies a plugin to be configured in the generated .zshrc. List of bundled Oh My Zsh plugins are available here. If <plugin> is a url, the script will try to install the plugin using git clone.

  • -a <line> - You can add extra lines at the end of the generated .zshrc (but before loading oh-my-zsh) by passing one -a argument for each line you want to add. This is useful to customize plugins or themes. For example, if you want to enable case sensitive completion:

    RUN sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v1.1.5/zsh-in-docker.sh)" -- \
    -a 'CASE_SENSITIVE="true"'
  • -x - Skip installation of dependencies: zsh, git, curl. If you are having issues with the script failing to install these dependencies due to sudo permissions, you can install them yourself in a prior step, and use this flag to make the script skip their installation

Examples:

# Uses "robbyrussell" theme (original Oh My Zsh theme), with no plugins
RUN sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v1.1.5/zsh-in-docker.sh)" -- \
    -t robbyrussell
# Uses "git", "ssh-agent" and "history-substring-search" bundled plugins
RUN sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v1.1.5/zsh-in-docker.sh)" -- \
    -p git -p ssh-agent -p 'history-substring-search' \
    -a 'bindkey "\$terminfo[kcuu1]" history-substring-search-up' \
    -a 'bindkey "\$terminfo[kcud1]" history-substring-search-down'
# Uses "Spaceship" theme with some customization. Uses some bundled plugins and installs some more from github
RUN sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v1.1.5/zsh-in-docker.sh)" -- \
    -t https://github.com/denysdovhan/spaceship-prompt \
    -a 'SPACESHIP_PROMPT_ADD_NEWLINE="false"' \
    -a 'SPACESHIP_PROMPT_SEPARATE_LINE="false"' \
    -p git \
    -p ssh-agent \
    -p https://github.com/zsh-users/zsh-autosuggestions \
    -p https://github.com/zsh-users/zsh-completions

Notes

  • The examples above use wget, but if you prefer curl, just replace wget -O- with curl -L
  • This scripts requires git and curl to work properly. If your Dockerfile uses root as the main user, it should be fine, as the script will install them automatically. If you are using a non-root user, make sure to install the sudo package OR to install git and curl packages before calling this script. In case sudo access is an issue and you already have zsh, git and curl, you can use the option -x to skip the installations.
  • By default this script will install the powerlevel10k theme, as it is one of the fastest and most customizable themes available for zsh. If you want the default Oh My Zsh theme, use the option -t robbyrussell

Liked it?

If you like this script, feel free to thank me with a coffee (or a beer ๐Ÿ˜‰):

ko-fi

zsh-in-docker's People

Contributors

arjentix avatar chaichontat avatar dbalabka avatar ddemarco96 avatar deluan avatar legau avatar mreferre avatar vvdaal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

zsh-in-docker's Issues

Why set the env 'TERM=xterm'

I am using vscode built-in terminal, and when I use this script to create a container, I found the zsh-auto-suggestion is not working properly as the color of the suggestion is wrong:

  • Expected:
    image

  • Actually:
    image

Then I found it was caused by the env TERM was set to xterm.
So I remove the export TERM=xterm, then echo $TERM to find that it is xterm-256color originally.
I wonder why the env 'TERM=xterm' would be set and if there should be an option to disable it.

Error trying to build image with default options

I noticed today when I try to install this in a docker container, I'm getting the following error:

sh: 105: printf: usage: printf format [arg ...]

This is on a "buster" based image, if that matters

non root user install failed: sudo: no tty present and no askpass program specified

dockerfile segment:

ARG DEBIAN_FRONTEND=noninteractive
ENV DEBIAN_FRONTEND=${DEBIAN_FRONTEND}
RUN set -eux; \
    apt-get update; \
    apt-get install -y --no-install-recommends \
    sudo net-tools iputils-ping iproute2 telnet curl wget nano procps

RUN addgroup www && adduser --shell /bin/zsh --home /home/www --gecos "" --ingroup www --disabled-password www
USER www
# Default powerline10k theme, no plugins installed
RUN sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v1.1.1/zsh-in-docker.sh)"

#20 0.833 ###### Installing dependencies for ubuntu
#20 0.837 /usr/bin/sudo
#20 0.854 sudo: no tty present and no askpass program specified
------
executor failed running [/bin/bash -c sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v1.1.1/zsh-in-docker.sh)" --     -p git     -p ssh-agent     -p z     -p autojump     -p history     -p last-working-dir     -p docker     -p github     -p jsontools     -p node     -p npm     -p golang     -p tmux     -p tmuxinator     -p catimg     -p https://github.com/zsh-users/zsh-autosuggestions
 -p https://github.com/zsh-users/zsh-completions     -p https://github.com/zsh-users/zsh-syntax-highlighting     -a 'export ZSH_DISABLE_COMPFIX=true'     -a 'HIST_STAMPS="yyyy-mm-dd"'     -a 'autoload -U compinit && compinit'     -a 'export ZSH_TMUX_AUTOSTART=false'     -a 'export ZSH_TMUX_AUTOCONNECT=false'     -a 'zstyle :omz:plugins:ssh-agent agent-forwarding on'     -a 'if [ -f \$HOME/.myenvset ]; then source \$HOME/.myenvset;fi'     -a '[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh'     -a 'if [ "\$TERM" = "xterm-256color" ] && [ -z "\$INSIDE_EMACS" ]; then test -e "\${HOME}/.iterm2_shell_integration.zsh" && source "\${HOME}/.iterm2_shell_integration.zsh";fi']: exit code: 1

no such widget history-substring-search-up

First of all, great script! Actually, great project! I love that you have tests.

My issue is when using the up arrow to navigate history, I get no such widget history-substring-search-up
(similar for down arrow)

I was able to "fix" the issue by adding -p history-substring-search to my Dockerfile.

Seeing as how the default zshrc template includes

bindkey "\$terminfo[kcuu1]" history-substring-search-up
bindkey "\$terminfo[kcud1]" history-substring-search-down

...you might want to also auto include the history-substring-search plugin?

If I am missing something obvious, please educate me. Either way, thanks for sharing this project.

Permissions are not set properly

Installing ZSH in a Debian based docker container (jupyter/docker-stacks) with this scripts creates folder and files with wrong permissions.

In the Dockerfile installing as root user:

RUN sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v1.1.1/zsh-in-docker.sh)" -- \
    -t bira -p git 

Then running /bin/zsh as a non-root user:

[oh-my-zsh] Insecure completion-dependent directories detected:
drwsrwsr-x. 1 root users 4096 Aug 27 08:18 /home/jovyan/.oh-my-zsh
drwsrwsr-x. 1 root users 8192 Aug 27 08:18 /home/jovyan/.oh-my-zsh/plugins
drwsrwsr-x. 1 root users   45 Aug 27 08:18 /home/jovyan/.oh-my-zsh/plugins/git

[oh-my-zsh] For safety, we will not load completions from these directories until
[oh-my-zsh] you fix their permissions and ownership and restart zsh.
[oh-my-zsh] See the above list for directories with group or other writability.

[oh-my-zsh] To fix your permissions you can do so by disabling
[oh-my-zsh] the write permission of "group" and "others" and making sure that the
[oh-my-zsh] owner of these directories is either root or your current user.
[oh-my-zsh] The following command may help:
[oh-my-zsh]     compaudit | xargs chmod g-w,o-w

[oh-my-zsh] If the above didn't help or you want to skip the verification of
[oh-my-zsh] insecure directories you can set the variable ZSH_DISABLE_COMPFIX to
[oh-my-zsh] "true" before oh-my-zsh is sourced in your zshrc file.

Unfortunately the given compaudit command to fix the permissions cannot be run in the Dockerfile (it seems to work only when the ZSH shell is active, not available in bash, nor with /bin/zsh -c)

There might be a oneliner chmod to fix this, but I thought the goal of such a script was to avoid such basic issues with permissions

passwd

What about the user password ?

Multiple executions fail.

When trying to run this command multiple times, let's say rebuilding a container, but not clearing the data from the volume, it throws the following error:

sh -c "$(curl -L https://github.com/deluan/zsh-in-docker/releases/download/v1.1.4/zsh-in-docker.sh)" -- \                                                                                โ”€โ•ฏ
    -p git \
    -p https://github.com/zsh-users/zsh-autosuggestions /home/sail/.oh-my-zsh/custom/plugins/zsh-autosuggestions \
    -p https://github.com/MichaelAquilina/zsh-you-should-use /home/sail/.oh-my-zsh/custom/plugins/you-should-use \
    -p https://github.com/zsh-users/zsh-syntax-highlighting /home/sail/.oh-my-zsh/custom/plugins/zsh-syntax-highlighting \
    -p https://github.com/zsh-users/zsh-completions /home/sail/.oh-my-zsh/custom/plugins/zsh-completions
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
100  3828  100  3828    0     0   4497      0 --:--:-- --:--:-- --:--:--  7748

Installing Oh-My-Zsh with:
  THEME   = default
  PLUGINS = git https://github.com/zsh-users/zsh-autosuggestions 

###### Installing dependencies for ubuntu
/usr/bin/sudo
Hit:1 http://archive.ubuntu.com/ubuntu jammy InRelease
Hit:2 http://archive.ubuntu.com/ubuntu jammy-updates InRelease                                                                             
Hit:3 http://security.ubuntu.com/ubuntu jammy-security InRelease                                                                           
Hit:4 https://dl.yarnpkg.com/debian stable InRelease                                                                                       
Hit:5 http://archive.ubuntu.com/ubuntu jammy-backports InRelease                                                                           
Hit:6 https://deb.nodesource.com/node_18.x jammy InRelease                                                                       
Hit:7 https://ppa.launchpadcontent.net/ondrej/php/ubuntu jammy InRelease         
Hit:8 http://apt.postgresql.org/pub/repos/apt jammy-pgdg InRelease
Reading package lists... Done
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
zsh is already the newest version (5.8.1-1).
curl is already the newest version (7.81.0-1ubuntu1.6).
git is already the newest version (1:2.34.1-1ubuntu1.5).
locales is already the newest version (2.35-0ubuntu3.1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
locales-all is already the newest version (2.35-0ubuntu3.1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Generating locales (this might take a while)...
  en_US.UTF-8... done
Generation complete.
fatal: destination path '/home/sail/.oh-my-zsh/custom/plugins/zsh-autosuggestions' already exists and is not an empty directory.

Is there a better way to handle this to automatically skip plugins that are already installed? Here is my RUN command:

USER sail
RUN sh -c "$(curl -L https://github.com/deluan/zsh-in-docker/releases/download/v1.1.4/zsh-in-docker.sh)" -- \
    -p git \
    -p https://github.com/zsh-users/zsh-autosuggestions \
    -p https://github.com/MichaelAquilina/zsh-you-should-use \
    -p https://github.com/zsh-users/zsh-syntax-highlighting \
    -p https://github.com/zsh-users/zsh-completions
USER root

How do I exec into the container using zsh?

I've installed the package, but when trying to exec into it I get:

OCI runtime exec failed: exec failed: container_linux.go:380: starting container process caused: exec: "zsh": executable file not found in $PATH: unknown

Using:

docker exec -it 6ea4953e2df4 sh

Powerlevel9k arguments overridden by default p10k theme

Thanks for this script! I'm a fan of p10k myself and have some custom styling I prefer. I tried adding those lines as -a args but was seeing something different in the final terminal. Here's the snippet from my Dockerfile:

RUN sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v1.1.1/zsh-in-docker.sh)" -- \
    -t powerlevel10k/powerlevel10k \
    -a 'POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(os_icon virtualenv anaconda dir vcs newline)' \
    -a 'POWERLEVEL9K_ANACONDA_SHOW_PYTHON_VERSION="true"' \
    -a 'POWERLEVEL9K_ANACONDA_BACKGROUND="cyan"' \
    -a 'POWERLEVEL9K_DIR_BACKGROUND="mediumturquoise"' \
    -a 'POWERLEVE9K_MODE="nerdfont-complete"' \
    -a 'POWERLEVEL9K_PROMPT_ADD_NEWLINE="true"' \
    -a 'alias pip="pip3"' \
    -a 'alias ls="ls -GFh"' \
    -p git \
    -p git-extras \
    -p https://github.com/zsh-users/zsh-completions

I am pretty sure it's because of this bit appending to the zshrc and overriding the prompt elements line in mine:

# Install powerlevel10k if no other theme was specified
if [ "$THEME" = "powerlevel10k/powerlevel10k" ]; then
    git clone https://github.com/romkatv/powerlevel10k $HOME/.oh-my-zsh/custom/themes/powerlevel10k
    powerline10k_config >> $HOME/.zshrc
fi

This happens regardless of if you leave off the -t flag to use the default or specify powerlevel10k/powerlevel10k. Pretty sure the easiest fix might be to just use a different string for the default value of $THEME and check for that in the if condition instead! Thanks again!

Running in devcontainer - theme does not work

I am trying to run the zsh-in-docker script in a docker file like this:

RUN sh -c "$(wget -O- https://github.com/deluan/zsh-in-docker/releases/download/v1.1.5/zsh-in-docker.sh)" -- \
    -t eastwood -p git -x

You can see I am specifying eastwood as the theme with the -t option. This docker file is started with a vscode devcontainer. For some reason - after starting the container the ~/.zshrc file always has this setting for the theme like this:

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
ZSH_THEME="devcontainers"

If I manually change the theme in the .zshrc to eastwood and source it - then it works great with the selected theme.

There does not seem to be a theme even called "devcontainers" available!?? I also can't see any logic in your script that could do this so its weird!

Container size optimization

p10k theme takes about 70MB because storing the whole repository git history:

$ du -du -sh ~/.oh-my-zsh/custom/themes/powerlevel10k/.git
74M     /home/vscode/.oh-my-zsh/custom/themes/powerlevel10k/.git
$ du -du -sh ~/.oh-my-zsh/custom/themes/powerlevel10k
76M     /home/vscode/.oh-my-zsh/custom/themes/powerlevel10k
$ du -sh ~/.oh-my-zsh/
85M     /home/vscode/.oh-my-zsh/

IMO you should install oh-my-zsh and p10k without cloning a git repository.

Q: use existing powerlevel10k config and install needed fonts

This project is fantastic. Don't want to miss oh-my-zsh when working in docker and this does this trick.

You wouldn't happen to know the best way to transfer my powerlevel10k config (it's the .p10k.zsh, right?) and install the minimum required fonts (some icons look odd)?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.