reobin / typewritten

A minimal, lightweight, informative zsh prompt theme

Home Page:https://typewritten.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Color Mapping error

huy-ha opened this issue · comments

After installation through npm, I'm getting this error

/usr/lib/node_modules/typewritten/lib/colors.zsh:1: no matches found: [foreground]=default
prompt_typewritten_setup:37: division by zero

And the default prompt for zsh is used instead.

I've encountered this problem on two of my machines, both running Ubuntu 18.04.

$ zsh --version
zsh 5.4.2 (x86_64-ubuntu-linux-gnu)

Hi @huy-ha !

Thanks for filing this bug report.

Has it worked before, or is it the first time you install typewritten? I'll try a clean install this morning on ubuntu and search for errors.

Cheers!

I have tried a couple of times with a fresh ubuntu container, and it seems to work well once typewritten is installed. I couldn't reproduce the error.

Could you share your .zshrc?

Also, did you notice any errors related to the symlinks, etc. during the installation through npm?

So I actually got it working on 2 of my machines, but not the other 3 (I just tried on another one) with the same zshrc. They are all running Ubuntu 18.04.

# From .bashrc

PATH=/usr/local/cuda/bin:$PATH
LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH

PATH=$HOME/go/bin:$PATH
[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh
export FZF_DEFAULT_COMMAND='ag -g ""'
export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
alias vim='nvim'

# If you come from bash you might have to change your $PATH.
export PATH=$HOME/bin:/usr/local/bin:$PATH

# Path to your oh-my-zsh installation.
export ZSH="/home/huy/.oh-my-zsh"

# 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=""


# Uncomment the following line to use case-sensitive completion.
CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment the following line to disable bi-weekly auto-update checks.
# DISABLE_AUTO_UPDATE="true"

# Uncomment the following line to automatically update without prompting.
# DISABLE_UPDATE_PROMPT="true"

# Uncomment the following line to change how often to auto-update (in days).
# export UPDATE_ZSH_DAYS=13

# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"


# Set fzf installation directory path
export FZF_BASE=/home/huy/.fzf/

# Uncomment the following line to disable fuzzy completion
# export DISABLE_FZF_AUTO_COMPLETION="true"

# Uncomment the following line to disable key bindings (CTRL-T, CTRL-R, ALT-C)
# export DISABLE_FZF_KEY_BINDINGS="true"


# Which plugins would you like to load?
# Add wisely, as too many plugins slow down shell startup.
plugins=(
    git 
    nvm
    zsh-syntax-highlighting
    zsh-autosuggestions
    fzf
)

__git_files () { 
    _wanted files expl 'local files' _files     
}

source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
# export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
if [[ -n $SSH_CONNECTION ]]; then
  export EDITOR='nvim'
else
  export EDITOR='nvim'
fi

# Compilation flags
# export ARCHFLAGS="-arch x86_64"

# Set personal aliases, overriding those provided by oh-my-zsh libs,
# plugins, and themes. Aliases can be placed here, though oh-my-zsh
# users are encouraged to define aliases within the ZSH_CUSTOM folder.
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"

# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/huy/anaconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
    eval "$__conda_setup"
else
    if [ -f "/home/huy/anaconda3/etc/profile.d/conda.sh" ]; then
        . "/home/huy/anaconda3/etc/profile.d/conda.sh"
    else
        export PATH="/home/huy/anaconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda initialize <<<

fpath+=$HOME/.zsh/typewritten
autoload -U promptinit; promptinit
prompt typewritten
TYPEWRITTEN_CURSOR="beam"

On the machine I created this issue on, there were permission errors when I first tried doing npm install (installed with zsh's nvm), so I used sudo [path to npm] install -g typewritten. I've also tried the manual installation and oh-my-zsh installation then changing the theme in zshrc to typewritten, but they give the same error.

/home/huy/.oh-my-zsh/custom/themes/typewritten/lib/colors.zsh:1: no matches found: [foreground]=default
/home/huy/.oh-my-zsh/custom/themes/typewritten.zsh-theme:37: bad math expression: operand expected at `%m%# '

On both of the machines I got it to work, npm did not work for me and I ended up installing it using oh-my-zsh instructions on the docs.

Thanks a lot @huy-ha

I also had some trouble installing it on linux with npm. A lot of the issues had to do with permission during the symlinks creation.

I'll close this for now, but I'll keep an eye open for more issues like this one. Maybe the npm install script can be improved but there is a lot of limitations (and rightly so) to what you can do with the npm preinstall script.

Ah wait sorry let me clarify, on the 5 machines, I got 2 of them to work (using oh-my-zsh), but 3 of them don't (they give errors like those in color.zsh). On the 3 that don't work I've already tried npm installation, manual installation and oh-my-zsh installation, but none of them worked :(

@huy-ha I tried using your .zshrc and got it running no problem. I'm not on Linux, though.

I'll try the manual install on a docker ubuntu image to see if anything pops up.

I got it working flawlessly with a clean docker ubuntu image.

Dockerfile:

FROM ubuntu:latest

ENV TERM xterm-256color

RUN apt-get update && apt-get install -y \
  vim \
  git \
  zsh \
  sudo \
  curl

WORKDIR /root

RUN echo "# zsh config" >> /root/.zshrc

ENTRYPOINT ["/bin/zsh"]
  1. mkdir -p "$HOME/.zsh"
  2. git clone https://github.com/reobin/typewritten.git "$HOME/.zsh/typewritten"
  3. Add following lines to .zshrc:
fpath+=$HOME/.zsh/typewritten
autoload -U promptinit; promptinit
prompt typewritten

It is a super lean setup, nothing else than typewritten and zsh installed, pretty much. We need to find what is it about your setup that doesn't like typewritten 🤔

I'll keep digging and I'll lyk if I find anything!

I don't know Zsh syntax but changing the associative array declaration to this worked for me.

declare -A color_mappings=( 
"foreground" "default"
"primary" "magenta"
"secondary" "blue"

"accent" "default"

"info_positive" "green"
"info_negative" "red"

"info_neutral_1" "yellow"
"info_neutral_2" "blue"

"info_special" "cyan"
)

Hi @ninja18 !

Were you having the same errors? What does your setup looks like? Ubuntu as well?

Thank you for trying other options btw! Your snippet is also right zsh syntax, and could be more compatible than what I have there, right now.

Could you make a PR with these changes? Syntax can be discussed there

@huy-ha Could you try @ninja18's method?

Yup that worked for me! Thank you so much @ninja18 !

@all-contributors please add @huy-ha for bug, and userTesting

@reobin

I've put up a pull request to add @huy-ha! 🎉