zsh-users / antigen

The plugin manager for zsh.
http://antigen.sharats.me
MIT License
8.01k stars 279 forks source link

Issue with sourcing zshrc after antigen install : bad substitution #748

Closed ridhwaans closed 8 months ago

ridhwaans commented 8 months ago

A test is failing

#!/bin/bash

#set -e

current_user=$(whoami)
echo "Hello, $current_user!"
echo "Current shell: $SHELL"

bash --version
zsh --version

source /etc/zsh/zshrc
#source /etc/bash.bashrc

:assert something:
Hello, vscode!
Current shell: /bin/zsh

GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
zsh 5.8.1 (x86_64-ubuntu-linux-gnu)

/etc/zsh/zshrc: line 73:  ${+terminfo[smkx]} : bad substitution
/etc/zsh/zshrc: line 75: zstyle: command not found
/etc/zsh/zshrc: line 83:  ${+aliases[run-help]} : bad substitution
/etc/zsh/zshrc: line 84: autoload: command not found
/etc/zsh/zshrc: line 89:  ${${(@f)"$(</etc/os-release)"}[(I)ID*=*ubuntu]} : bad substitution
/usr/local/share/.zsh/bundle/bin/antigen.zsh: line 9: zmodload: command not found
/usr/local/share/.zsh/bundle/bin/antigen.zsh: line 10: autoload: command not found
/usr/local/share/.zsh/bundle/bin/antigen.zsh: line 30: syntax error near unexpected token `fi'
/usr/local/share/.zsh/bundle/bin/antigen.zsh: line 30: `      fi'
/etc/zsh/zshrc: line 130: antigen: command not found
/etc/zsh/zshrc: line 133: antigen: command not found
/etc/zsh/zshrc: line 136: antigen: command not found

The test is running in a devcontainer (javascript-node:1-18)

The line source /etc/zsh/zshrc manually reloads but throws the above errors The current resolution was to remove set -e and make the test finish

How do you fix antigen to the current shell session?

How antigen was installed:

groupadd -r vundle
usermod -a -G vundle ${USERNAME}

git clone https://github.com/VundleVim/Vundle.vim.git ${VUNDLE_DIR}/Vundle.vim
chown -R "root:vundle" "${VUNDLE_DIR}/Vundle.vim"
chmod -R g+rws "${VUNDLE_DIR}/Vundle.vim"

How zshrc was updated:

zsh_rc_snippet=$(cat <<EOF
# General
ADOTDIR="$ANTIGEN_DIR"
ANTIGEN_LOG=\${ADOTDIR}/antigen.log

# Customization
ANTIGEN_CACHE=\${ADOTDIR}/init.zsh
ANTIGEN_COMPDUMP=\${ADOTDIR}/.zcompdump
ANTIGEN_BUNDLES=\${ADOTDIR}/bundles
ANTIGEN_LOCK=\${ADOTDIR}/.lock
ANTIGEN_DEBUG_LOG=\${ADOTDIR}/debug.log

source \${ADOTDIR}/bin/antigen.zsh

# Load the oh-my-zsh's library.
antigen use oh-my-zsh

# Load the theme.
antigen theme agnoster

# Tell Antigen that you're done.
antigen apply
EOF
)

echo -e zsh_rc_snippet >> "/etc/zsh/zshrc"

Full zshrc file

# /etc/zsh/zshrc: system-wide .zshrc file for zsh(1).
#
# This file is sourced only for interactive shells. It
# should contain commands to set up aliases, functions,
# options, key bindings, etc.
#
# Global Order: zshenv, zprofile, zshrc, zlogin

READNULLCMD=${PAGER:-/usr/bin/pager}

# An array to note missing features to ease diagnosis in case of problems.
typeset -ga debian_missing_features

if [[ -z "${DEBIAN_PREVENT_KEYBOARD_CHANGES-}" ]] &&
   [[ "$TERM" != 'emacs' ]]
then

    typeset -A key
    key=(
        BackSpace  "${terminfo[kbs]}"
        Home       "${terminfo[khome]}"
        End        "${terminfo[kend]}"
        Insert     "${terminfo[kich1]}"
        Delete     "${terminfo[kdch1]}"
        Up         "${terminfo[kcuu1]}"
        Down       "${terminfo[kcud1]}"
        Left       "${terminfo[kcub1]}"
        Right      "${terminfo[kcuf1]}"
        PageUp     "${terminfo[kpp]}"
        PageDown   "${terminfo[knp]}"
    )

    function bind2maps () {
        local i sequence widget
        local -a maps

        while [[ "$1" != "--" ]]; do
            maps+=( "$1" )
            shift
        done
        shift

        sequence="${key[$1]}"
        widget="$2"

        [[ -z "$sequence" ]] && return 1

        for i in "${maps[@]}"; do
            bindkey -M "$i" "$sequence" "$widget"
        done
    }

    bind2maps emacs             -- BackSpace   backward-delete-char
    bind2maps       viins       -- BackSpace   vi-backward-delete-char
    bind2maps             vicmd -- BackSpace   vi-backward-char
    bind2maps emacs             -- Home        beginning-of-line
    bind2maps       viins vicmd -- Home        vi-beginning-of-line
    bind2maps emacs             -- End         end-of-line
    bind2maps       viins vicmd -- End         vi-end-of-line
    bind2maps emacs viins       -- Insert      overwrite-mode
    bind2maps             vicmd -- Insert      vi-insert
    bind2maps emacs             -- Delete      delete-char
    bind2maps       viins vicmd -- Delete      vi-delete-char
    bind2maps emacs viins vicmd -- Up          up-line-or-history
    bind2maps emacs viins vicmd -- Down        down-line-or-history
    bind2maps emacs             -- Left        backward-char
    bind2maps       viins vicmd -- Left        vi-backward-char
    bind2maps emacs             -- Right       forward-char
    bind2maps       viins vicmd -- Right       vi-forward-char

    # Make sure the terminal is in application mode, when zle is
    # active. Only then are the values from $terminfo valid.
    if (( ${+terminfo[smkx]} )) && (( ${+terminfo[rmkx]} )); then
        function zle-line-init () {
            emulate -L zsh
            printf '%s' ${terminfo[smkx]}
        }
        function zle-line-finish () {
            emulate -L zsh
            printf '%s' ${terminfo[rmkx]}
        }
        zle -N zle-line-init
        zle -N zle-line-finish
    else
        for i in {s,r}mkx; do
            (( ${+terminfo[$i]} )) || debian_missing_features+=($i)
        done
        unset i
    fi

    unfunction bind2maps

fi # [[ -z "$DEBIAN_PREVENT_KEYBOARD_CHANGES" ]] && [[ "$TERM" != 'emacs' ]]

zstyle ':completion:*:sudo:*' command-path /usr/local/sbin \
                                           /usr/local/bin  \
                                           /usr/sbin       \
                                           /usr/bin        \
                                           /sbin           \
                                           /bin            \
                                           /usr/X11R6/bin

(( ${+aliases[run-help]} )) && unalias run-help
autoload -Uz run-help

# If you don't want compinit called here, place the line
# skip_global_compinit=1
# in your $ZDOTDIR/.zshenv
if (( ${${(@f)"$(</etc/os-release)"}[(I)ID*=*ubuntu]} )) &&
   [[ -z "$skip_global_compinit" ]]; then
  autoload -U compinit
  compinit
fi

if [ -z "${USER}" ]; then export USER=$(whoami); fi
if [[ "${PATH}" != *"$HOME/.local/bin"* ]]; then export PATH="${PATH}:$HOME/.local/bin"; fi

# Display optional first run image specific notice if configured and terminal is interactive
if [ -t 1 ] && [[ "${TERM_PROGRAM}" = "vscode" || "${TERM_PROGRAM}" = "codespaces" ]] && [ ! -f "$HOME/.config/vscode-dev-containers/first-run-notice-already-displayed" ]; then
    if [ -f "/usr/local/etc/vscode-dev-containers/first-run-notice.txt" ]; then
        cat "/usr/local/etc/vscode-dev-containers/first-run-notice.txt"
    elif [ -f "/workspaces/.codespaces/shared/first-run-notice.txt" ]; then
        cat "/workspaces/.codespaces/shared/first-run-notice.txt"
    fi
    mkdir -p "$HOME/.config/vscode-dev-containers"
    # Mark first run notice as displayed after 10s to avoid problems with fast terminal refreshes hiding it
    ((sleep 10s; touch "$HOME/.config/vscode-dev-containers/first-run-notice-already-displayed") &)
fi

# Set the default git editor if not already set
if [ -z "$(git config --get core.editor)" ] && [ -z "${GIT_EDITOR}" ]; then
    if  [ "${TERM_PROGRAM}" = "vscode" ]; then
        if [[ -n $(command -v code-insiders) &&  -z $(command -v code) ]]; then 
            export GIT_EDITOR="code-insiders --wait"
        else 
            export GIT_EDITOR="code --wait"
        fi
    fi
fi
# General
ADOTDIR="/usr/local/share/.zsh/bundle"
ANTIGEN_LOG=${ADOTDIR}/antigen.log

# Customization
ANTIGEN_CACHE=${ADOTDIR}/init.zsh
ANTIGEN_COMPDUMP=${ADOTDIR}/.zcompdump
ANTIGEN_BUNDLES=${ADOTDIR}/bundles
ANTIGEN_LOCK=${ADOTDIR}/.lock
ANTIGEN_DEBUG_LOG=${ADOTDIR}/debug.log

source ${ADOTDIR}/bin/antigen.zsh

# Load the oh-my-zsh's library.
antigen use oh-my-zsh

# Load the theme.
antigen theme agnoster

# Tell Antigen that you're done.
antigen apply
export SDKMAN_DIR="/usr/local/sdkman"

[[ -s "$SDKMAN_DIR/bin/sdkman-init.sh" ]] && source "$SDKMAN_DIR/bin/sdkman-init.sh"
export PYENV_ROOT="/usr/local/pyenv"

[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"

eval "$(pyenv init -)"

eval "$(pyenv virtualenv-init -)"
export RBENV_ROOT="/usr/local/rbenv"

[[ -d $RBENV_ROOT/bin ]] && export PATH="$RBENV_ROOT/bin:$PATH"

eval "$(rbenv init -)"
export NVM_DIR="/usr/local/nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
export PATH="/usr/local/go/bin:$PATH"
export GOPATH="/go"

The following are the file permission in the antigen install directory

> ls -al /usr/local/share/.zsh/bundle/bin/antigen.zsh

total 348
drwxrwsr-x 1 root   antigen   4096 Jan 14 00:44 .
drwxr-xr-x 1 root   root      4096 Jan 14 00:11 ..
drwxrwsr-x 8 root   antigen   4096 Jan 14 00:11 .git
-rw-rwSr-- 1 root   antigen    562 Jan 14 00:11 .gitignore
-rw-r--r-- 1 vscode antigen     35 Jan 14 00:44 .resources
-rw-rwSr-- 1 root   antigen   1513 Jan 14 00:11 .travis.yml
-rw-r--r-- 1 vscode antigen  49091 Jan 14 00:44 .zcompdump
-r--r--r-- 1 vscode antigen 116856 Jan 14 00:44 .zcompdump.zwc
-rw-rwSr-- 1 root   antigen  19770 Jan 14 00:11 CHANGELOG.md
-rw-rwSr-- 1 root   antigen   5465 Jan 14 00:11 CODE_OF_CONDUCT.md
-rw-rwSr-- 1 root   antigen   5374 Jan 14 00:11 CONTRIBUTING.md
-rw-rwSr-- 1 root   antigen    546 Jan 14 00:11 ISSUE_TEMPLATE.md
-rw-rwSr-- 1 root   antigen   1104 Jan 14 00:11 LICENSE
-rw-rwSr-- 1 root   antigen   4944 Jan 14 00:11 Makefile
-rw-rwSr-- 1 root   antigen   4512 Jan 14 00:11 Makefile.in
-rw-rwSr-- 1 root   antigen   6518 Jan 14 00:11 README.mkd
-rw-rwSr-- 1 root   antigen      8 Jan 14 00:11 VERSION
-rw-r--r-- 1 vscode antigen     78 Jan 14 00:44 antigen.log
-rw-rwSr-- 1 root   antigen   6170 Jan 14 00:11 antigen.png
-rw-rwSr-- 1 root   antigen     75 Jan 14 00:11 antigen.zsh
drwxrwsr-x 2 root   antigen   4096 Jan 14 00:11 bin
drwxr-sr-x 3 vscode antigen   4096 Jan 14 00:44 bundles
-rwxrwsr-x 1 root   antigen   2304 Jan 14 00:11 configure
-rw-r--r-- 1 vscode antigen  28043 Jan 14 00:44 debug.log
-rw-r--r-- 1 vscode antigen   3055 Jan 14 00:44 init.zsh
-r--r--r-- 1 vscode antigen   8456 Jan 14 00:44 init.zsh.zwc
drwxrwsr-x 6 root   antigen   4096 Jan 14 00:11 src
drwxrwsr-x 2 root   antigen   4096 Jan 14 00:11 tests
drwxrwsr-x 2 root   antigen   4096 Jan 14 00:11 tools
> ls -al /usr/local/share/.zsh/bundle

total 16
drwxr-xr-x 4 root root   4096 Jan 14 00:11 .
drwxr-xr-x 3 root root   4096 Jan 14 00:11 ..
drwxrwsr-x 8 root vundle 4096 Jan 14 00:11 Vundle.vim
drwxr-xr-x 6 root root   4096 Jan 14 00:11 vim-gotham
ridhwaans commented 8 months ago

User shell was not aligned. Changed header to #!/bin/zsh to fix the bad substitution error.