encountered an error message "zsh parse error near `\n'" - terminal

I'm trying to install jekyll bundler using gem.
I installed rbenv and tried to add a path in my .zshrc file.
After adding these two lines:
export PATH={$Home}/.rbenv/bin:$PATH && \
eval "$(rbenv init -)"
I entered source ~/.zshrc.
However, I got an error
/Users/okclef/.zshrc:127: parse error near '\n'
parse error
How can I fix this problem?
Here are my .zshrc commands:
# Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.
# Initialization code that may require console input (password prompts, [y/n]
# confirmations, etc.) must go above this block; everything else may go below.
if [[ -r "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh" ]]; then
source "${XDG_CACHE_HOME:-$HOME/.cache}/p10k-instant-prompt-${(%):-%n}.zsh"
fi
# 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="/Users/okclef/.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="powerlevel10k/powerlevel10k"
# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in $ZSH/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )
# 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 one of the following lines to change the auto-update behavior
# zstyle ':omz:update' mode disabled # disable automatic updates
# zstyle ':omz:update' mode auto # update automatically without asking
# zstyle ':omz:update' mode reminder # just remind me to update when it's time
# Uncomment the following line to change how often to auto-update (in days).
# zstyle ':omz:update' frequency 13
# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS="true"
# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"
# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="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.
# You can also set it to another string to have that shown instead of the default red dots.
# e.g. COMPLETION_WAITING_DOTS="%F{yellow}waiting...%f"
# Caution: this setting can cause issues with multiline prompts in zsh < 5.7.1 (see #5765)
# 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"
# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder
# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
plugins=(git)
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='vim'
# else
# export EDITOR='mvim'
# 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"
source /opt/homebrew/share/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source /opt/homebrew/share/zsh-autosuggestions/zsh-autosuggestions.zsh
# To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
[[ ! -f ~/.p10k.zsh ]] || source ~/.p10k.zsh
prompt_context() {
if [[ "$USER" != "$DEFAULT_USER" || -n "$SSH_CLIENT" ]]; then
prompt_segment black default "%(!.%{%F{yellow}%}.)"
fi
}:
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
export PATH="/opt/homebrew/bin:$PATH"
export PATH={$Home}/.rbenv/bin:$PATH && \
eval "$(rbenv init -)"

I had the same issue. When trying to load the .zshrc file, it asked me to replace my current line to load the rbenv like this instead:
eval "$(rbenv init - zsh)"

Related

Changing PS1 with conda

I want to change my prompt from ~ $ to ~ > when activating conda.
I tried using env_prompt: in .condarc but it displays > ~ $ instead of the desired ~ > prompt.
(The conda prompt is preceded by the original PS1)
Can someone provide an example on how to implement this in my .bashrc?
Conda's changeps1 functionality is limited to prepending a string to the shell's PS1. This string can be specified using the configuration variable env_prompt (as OP indicates). For completeness, here is how to query the documentation:
env_prompt
$ conda config --describe env_prompt
# # env_prompt (str)
# # Template for prompt modification based on the active environment.
# # Currently supported template variables are '{prefix}', '{name}', and
# # '{default_env}'. '{prefix}' is the absolute path to the active
# # environment. '{name}' is the basename of the active environment
# # prefix. '{default_env}' holds the value of '{name}' if the active
# # environment is a conda named environment ('-n' flag), or otherwise
# # holds the value of '{prefix}'. Templating uses python's str.format()
# # method.
# #
# env_prompt: '({default_env}) '
To customize other aspects of PS1, one must do this independently of Conda. That is, you will need to consult the documentation for your shell (e.g., bash, zsh) or terminal.

Exporting environment variables for local development and heroku deployment

I would like to setup some files for development, staging and production with environment variables, for example:
application_root/development.env
KEY1=value1
KEY2=value2
There would be similar files staging.env and production.env.
I am looking for a couple different bash scripts which would allow the loading of all these variables in either development or staging/production.
In local development I want to effectively run export KEY1=value1 for each line in the file.
For staging/production I will be deploying to Heroku and would like to effectively run heroku config:set -a herokuappname KEY1=value1 for each line in the staging or production.env files.
I know there are some gems designed for doing this but it seems like this might be pretty simple. I also like the flexibility of having the .env files as simple lists of keys and values and not specifically being tied to any language/framework. If I would have to change something about the way these variables need to be loaded it would be a matter of changing the script but not the .env files.
In the simplest form, you can load the key-value pairs into a bash array as follows:
IFS=$'\n' read -d '' -ra nameValuePairs < ./development.env
In Bash v4+, it's even simpler:
readarray -t nameValuePairs < ./development.env
You can then pass the resulting "${nameValuePairs[#]}" array to commands such as export or heroku config:set ...; e.g.:
export "${nameValuePairs[#]}"
Note, however, that the above only works as intended if the input *.env file meets all of the following criteria:
the keys are syntactically valid shell variable names and the lines have the form <key>=<value>, with no whitespace around =
the lines contain no quoting and no leading or trailing whitespace
there are no empty/blank lines or comment lines in the file.
the values are confined to a single line each.
A different approach is needed with files that do not adhere to this strict format; for instance, this related question deals with files that may contain quoted values.
Below is the source code for a bash script named load_env (the .sh suffix is generally not necessary and ambiguous):
You'd invoke it with the *.env file of interest, and it would perform the appropriate action (running heroku config:set … or export) based on the filename.
However, as stated, you must source the script (using source or its effective bash alias, .) in order to create environment variables (export) visible to the current shell.
To prevent obscure failures, the script complains if you pass a development.env file and have invoked the script without sourcing.
Examples:
./load_env ./staging.dev
. ./load_env ./development.dev # !! Note the need to source
load_env source code
#!/usr/bin/env bash
# Helper function that keeps its aux. variables localized.
# Note that the function itself remains defined after sourced invocation, however.
configOrExport() {
local envFile=$1 doConfig=0 doExport=0 appName
case "$(basename "$envFile" '.env')" in
staging)
doConfig=1
# Set the desired app name here.
appName=stagingapp
;;
production)
doConfig=1
# Set the desired app name here.
appName=productionapp
;;
development)
doExport=1
;;
*)
echo "ERROR: Invalid or missing *.env file name: $(basename "$envFile" '.env')" >&2; exit 2
esac
# Make sure the file exists and is readable.
[[ -r "$envFile" ]] || { echo "ERROR: *.env file not found or not readable: $envFile" >&2; exit 2; }
# If variables must be exported, make sure the script is being sourced.
[[ $doExport -eq 1 && $0 == "$BASH_SOURCE" ]] && { echo "ERROR: To define environment variables, you must *source* this script." >&2; exit 2; }
# Read all key-value pairs from the *.env file into an array.
# Note: This assumes that:
# - the keys are syntactically valid shell variable names
# - the lines contain no quoting and no leading or trailing whitespace
# - there are no empty/blank lines or comment lines in the file.
IFS=$'\n' read -d '' -ra nameValuePairs < "$envFile"
# Run configuration command.
(( doConfig )) && { heroku config:set -a "$appName" "${nameValuePairs[#]}" || exit; }
# Export variables (define as environment variables).
(( doExport )) && { export "${nameValuePairs[#]}" || exit; }
}
# Invoke the helper function.
configOrExport "$#"

How do I get rid of the ruby version on my prompt through zsh?

I have zsh and think that I need to go to the profile through ~/.zshrc and then add export PS1=”$“ to get rid of the ruby version, but I'm not sure which export to replace?
Try removing ${rvm-prompt}...
Also, for further easy customization take a look at - Oh My Zsh - A delightful community-driven framework for managing your zsh configuration.
as I am using yadr and prezto I had to open the file ~/.yadr/zsh/prezto/modules/ruby/functions/ruby-info and comment this block, putting a blank to the version variable:
# if (( $+commands[rvm-prompt] )); then
# version="$(rvm-prompt)"
# elif (( $+commands[rbenv] )); then
# version="$(rbenv version-name)"
# elif (( $+commands[ruby] )); then
# version="${${$(ruby --version)[(w)1,(w)2]}/ /-}"
# fi
version=""

.profile: line 31: syntax error: unexpected end of file

I'm bad at bash programming. Where is the error? Here is my .profile file:
# WARNING: For help understanding this file, and before you try
# to change any of it, type "man .profile" and read carefully.
#
#
# Set command search rules
#
if [ -x /bin/showpath ] ; then  
    export PATH; PATH=`/bin/showpath $HOME/bin /u/cs350/sys161/bin /software/gnu/bin standard`
export PATH; PATH=`/bin/showpath usedby=user standard $HOME/bin`
#
# Find out what kind of terminal we are using
#
eval `setterm sytek:kd404 default:vc404`
#
# Set terminal-type dependent options (e.g. sysline or prompt string)
#
#HOMEHOST="<hostname>"
#HOMEUSER="<userid>"
#export HOMEHOST HOMEUSER
PS1="$ "
#
# Now do the usual signing on things
#
export MAIL; MAIL=${MAIL-"/usr/spool/mail/$USER"}
if [ -r /software/.admin/bins/bin/read_system_news ] ; then /software/.admin/bins/bin/read_system_news ; fi
EOF
Your first if is missing a fi.
You are missing a fi at the end of file add it.
Also get rid of EOF. The EOF in your case is treated as a command.
Sometimes running your script using different shells gives you a clue about the error.
When we run your program using:
sh it says Syntax error: end of
file unexpected (expecting "fi")
csh it says if: Expression
Syntax.

To get colors to Less in Ubuntu's Zsh

How can you get similar highlightings to Zsh's Less than Bash's Less in Ubuntu?
I switched from OS X to Ubuntu. My Less do not work as expected in Zsh.
Manuals in my Less are green and black with or without the following code.
# comment these out in Ubuntu
export LESS_TERMCAP_mb=$'\E[01;31m' # begin blinking
export LESS_TERMCAP_me=$'\E[0m' # end mode
export LESS_TERMCAP_se=$'\E[0m' # end standout-mode
export LESS_TERMCAP_so=$'\E[38;5;246m' # begin standout-mode - info box
export LESS_TERMCAP_ue=$'\E[0m' # end underline
export LESS_TERMCAP_us=$'\E[04;33;146m' # begin underline is now yellow
# | | |
# | |----------------- yellow
# |-------------------- underline
# to have the indication of cursor's location and line numbers, and R
export LESS="-mNR"
# |--------- only ASCII color
The code makes manuals readable in OS X, but it does not work for Ubuntu in Zsh.
Ubuntu has excellent highlightings in Bash's Less. My manuals have the colors yellow, green and black in Bash without my code. Both Zsh and Bash use the same Less at /usr/bin/less. This suggests me that Ubuntu's Bash has some dot-files which configure it somewhere.
Where are highlightings for Ubuntu's Less in Bash?
This works for me in zsh on archlinux:
$ mkdir ~/.terminfo/ && cd ~/.terminfo
Now get the terminfo description:
$ wget http://nion.modprobe.de/mostlike.txt
Now compile it using tic (the terminfo entry-description compiler)
$ tic mostlike.txt
(you may want to delete the mostlike.txt file after compiling)
mostlike.txt is this
# Reconstructed via infocmp from file: /usr/share/terminfo/x/xterm-pcolor
mostlike|manpages with color looking like most,
am, hs, km, mir, msgr, xenl,
cols#80, it#8, lines#24, wsl#40,
acsc=``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~,
bel=^G, bold=\E[1m\E[31m, clear=\E[H\E[2J, cr=^M,
csr=\E[%i%p1%d;%p2%dr, cub=\E[%p1%dD, cub1=^H,
cud=\E[%p1%dB, cud1=^J, cuf=\E[%p1%dC, cuf1=\E[C,
cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA, cuu1=\E[A,
dch=\E[%p1%dP, dch1=\E[P, dl=\E[%p1%dM, dl1=\E[M,
dsl=\E]0;\007, ed=\E[J, el=\E[K, enacs=\E)0, fsl=^G,
home=\E[H, ht=^I, hts=\EH, il=\E[%p1%dL, il1=\E[L, ind=^J,
is2=\E7\E[r\E[m\E[?7h\E[?1;3;4;6l\E[4l\E8\E>, kbs=^H,
kcub1=\EOD, kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA,
kdch1=\E[3~, kf1=\E[11~, kf10=\E[21~, kf11=\E[23~,
kf12=\E[24~, kf13=\E[25~, kf14=\E[26~, kf15=\E[28~,
kf16=\E[29~, kf17=\E[31~, kf18=\E[32~, kf19=\E[33~,
kf2=\E[12~, kf20=\E[34~, kf3=\E[13~, kf4=\E[14~,
kf5=\E[15~, kf6=\E[17~, kf7=\E[18~, kf8=\E[19~, kf9=\E[20~,
kfnd=\E[1~, kich1=\E[2~, kmous=\E[M, knp=\E[6~, kpp=\E[5~,
kslt=\E[4~, rc=\E8, rev=\E[7m\E[34m, ri=\EM, rmacs=^O,
rmcup=\E[2J\E[?47l\E8, rmir=\E[4l, rmkx=\E[?1l\E>,
rmso=\E[m, rmul=\E[m,
rs2=\E7\E[r\E8\E[m\E[?7h\E[?1;3;4;6l\E[4l\E>, sc=\E7,
sgr0=\E[m, smacs=^N, smcup=\E7\E[?47h, smir=\E[4h,
smkx=\E[?1h\E=, smso=\E[1;30m\E[47m, smul=\E[32m,
tbc=\E[3g, tsl=\E]0;, u6=\E[%i%d;%dR, u7=\E[6n,
u8=\E[?1;2c, u9=\E[c,
And then just define an alias in the rc file of your favorite shell:
alias man="TERMINFO=~/.terminfo/ LESS=C TERM=mostlike PAGER=less man"
My default shell is bash so take this with a grain of salt. Start with /etc/profile and see how it sources bash-specific files. You need to re-create that logic for zsh. Maybe the zsh-lovers package can help, at least its title of tips, tricks and examples for the zsh
is suggestive.

Resources