RVM Debug output on terminal - ruby

I'm seeing this every time I open terminal, after a RVM installation:
Last login: Tue Dec 2 10:35:44 on ttys000
rvm_debug () {
(( ${rvm_debug_flag:-0} )) || return 0
if rvm_pretty_print stderr
then
printf "%b" "${rvm_debug_clr:-}$*${rvm_reset_clr:-}\n"
else
printf "%b" "$*\n"
fi >&2
}
This is my bash_profile:
[10:54:13] old_ian :: Ians-MacBook-Pro-2 ➜ ~ ⭑ cat .bash_profile
export PATH=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
export SSL_CERT_FILE=/usr/local/etc/cacert.pem
export PATH=/usr/local/sbin:$PATH
### Added by the Heroku Toolbelt
export PATH="/usr/local/heroku/bin:$PATH"
### RVM
source $HOME/.rvm/scripts/rvm
PATH="/Applications/Postgres.app/Contents/MacOS/bin:$PATH"
alias bex="bundle exec"
alias grep="grep --color=auto"
alias vi=vim
alias postgres="pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log"
[10:54:19] old_ian :: Ians-MacBook-Pro-2 ➜ ~ ⭑
Maybe something went wrong with it's install ?
I've been using it with no problems.
UPDATES:
Posting cat RVM
#!/usr/bin/env bash
# rvm : Ruby enVironment Manager
# https://rvm.io
# https://github.com/wayneeseguin/rvm
# partial duplication marker dkjnkjvnckbjncvbkjnvkj
# prevent from loading in sh shells
if
\command \test -n "${BASH_VERSION:-}" -o -n "${ZSH_VERSION:-}"
then
case "`uname`" in
(CYGWIN*) __shell_name="`\command \ps -p $$ | \command \awk 'END {print $NF}'` 2>/dev/null" ;;
(*) __shell_name="`\command \ps -p $$ -o comm=`" ;;
esac
case "$__shell_name" in
(""|dash|sh|*/dash|*/sh) return 0 ;; # silently stop in sh shells
esac
unset __shell_name
else
return 0
fi
# also duplicated in scripts/base
__rvm_has_opt()
{
{
# pre-gnu
[[ -n "${ZSH_VERSION}" ]] && setopt | GREP_OPTIONS="" \command \grep "^${1}$" >/dev/null 2>&1
} ||
{
[[ -n "${BASH_VERSION}" ]] && [[ ":$SHELLOPTS:" =~ ":${1}:" ]]
} ||
return 1
}
# Do not allow sourcing RVM in `sh` - it's not supported
# return 0 to exit from sourcing this script without breaking sh
if __rvm_has_opt "posix"
then return 0
fi
# TODO: Alter the variable names to make sense
\export HOME rvm_prefix rvm_user_install_flag rvm_path
HOME="${HOME%%+(\/)}" # Remove trailing slashes if they exist on HOME
[[ -n "${rvm_stored_umask:-}" ]] || export rvm_stored_umask=$(umask)
if (( ${rvm_ignore_rvmrc:=0} == 0 ))
then
rvm_rvmrc_files=("/etc/rvmrc" "$HOME/.rvmrc")
if [[ -n "${rvm_prefix:-}" ]] && ! [[ "$HOME/.rvmrc" -ef "${rvm_prefix}/.rvmrc" ]]
then rvm_rvmrc_files+=( "${rvm_prefix}/.rvmrc" )
fi
for rvmrc in "${rvm_rvmrc_files[#]}"
do
if [[ -f "$rvmrc" ]]
then
# pre-gnu
if GREP_OPTIONS="" \command \grep '^\s*rvm .*$' "$rvmrc" >/dev/null 2>&1
then
printf "%b" "
Error:
$rvmrc is for rvm settings only.
rvm CLI may NOT be called from within $rvmrc.
Skipping the loading of $rvmrc"
return 1
else
source "$rvmrc"
fi
fi
done
unset rvm_rvmrc_files
fi
# duplication marker jdgkjnfnkjdngjkfnd4fd
# detect rvm_path if not set
if [[ -z "${rvm_path:-}" ]]
then
if [[ -n "${BASH_SOURCE:-$_}" && -f "${BASH_SOURCE:-$_}" ]]
then
rvm_path="${BASH_SOURCE:-$_}"
rvm_path="$( \command \cd "${rvm_path%/scripts/rvm}">/dev/null; pwd )"
rvm_prefix=$( dirname $rvm_path )
elif (( UID == 0 ))
then
if (( ${rvm_user_install_flag:-0} == 0 ))
then
rvm_prefix="/usr/local"
rvm_path="${rvm_prefix}/rvm"
else
rvm_prefix="$HOME"
rvm_path="${rvm_prefix}/.rvm"
fi
else
if [[ -d "$HOME/.rvm" && -s "$HOME/.rvm/scripts/rvm" ]]
then
rvm_prefix="$HOME"
rvm_path="${rvm_prefix}/.rvm"
else
rvm_prefix="/usr/local"
rvm_path="${rvm_prefix}/rvm"
fi
fi
else
# remove trailing slashes, btw. %%/ <- does not work as expected
rvm_path="${rvm_path%%+(\/)}"
fi
# guess rvm_prefix if not set
if [[ -z "${rvm_prefix}" ]]
then
rvm_prefix=$( dirname $rvm_path )
fi
# duplication marker kkdfkgnjfndgjkndfjkgnkfjdgn
case "$rvm_path" in
(/usr/local/rvm) rvm_user_install_flag=0 ;;
($HOME/*|/${USER// /_}*) rvm_user_install_flag=1 ;;
(*) rvm_user_install_flag=0 ;;
esac
export rvm_loaded_flag
if [[ -n "${BASH_VERSION:-}" || -n "${ZSH_VERSION:-}" ]] &&
typeset -f rvm >/dev/null 2>&1
then
rvm_loaded_flag=1
else
rvm_loaded_flag=0
fi
if
(( ${rvm_loaded_flag:=0} == 0 )) || (( ${rvm_reload_flag:=0} == 1 ))
then
if
[[ -n "${rvm_path}" && -d "$rvm_path" ]]
then
true ${rvm_scripts_path:="$rvm_path/scripts"}
if
[[ ! -f "$rvm_scripts_path/base" ]]
then
printf "%b" "WARNING:
Could not source '$rvm_scripts_path/base' as file does not exist.
RVM will likely not work as expected.\n"
elif
! source "$rvm_scripts_path/base"
then
printf "%b" "WARNING:
Errors sourcing '$rvm_scripts_path/base'.
RVM will likely not work as expected.\n"
else
__rvm_ensure_is_a_function
__rvm_setup
export rvm_version
rvm_version="$(\command \cat "$rvm_path/VERSION") ($(\command \cat "$rvm_path/RELEASE" 2>/dev/null))"
alias rvm-restart="rvm_reload_flag=1 source '${rvm_scripts_path:-${rvm_path}/scripts}/rvm'"
# Try to load RVM ruby if none loaded yet
__path_to_ruby="$( builtin command -v ruby 2>/dev/null || true )"
if
[[ -z "${__path_to_ruby}" ]] ||
[[ "${__path_to_ruby}" != "${rvm_path}"* ]] ||
[[ "${__path_to_ruby}" == "${rvm_path}/bin/ruby" ]]
then
if [[ -s "$rvm_path/environments/default" ]]
then source "$rvm_path/environments/default"
fi
if
[[ ${rvm_project_rvmrc:-1} -gt 0 ]] &&
! __function_on_stack __rvm_project_rvmrc
then
# Reload the rvmrc, use promptless ensuring shell processes does not
# prompt if .rvmrc trust value is not stored, revert to default on fail
if
rvm_current_rvmrc=""
rvm_project_rvmrc_default=2 rvm_promptless=1 __rvm_project_rvmrc
then
rvm_hook=after_cd
source "${rvm_scripts_path:-${rvm_path}/scripts}/hook"
fi
fi
fi
unset __path_to_ruby
# Makes sure rvm_bin_path is in PATH atleast once.
[[ ":${PATH}:" == *":${rvm_bin_path}:"* ]] || PATH="$PATH:${rvm_bin_path}"
if
(( ${rvm_reload_flag:=0} == 1 ))
then
[[ "${rvm_auto_reload_flag:-0}" == 2 ]] || printf "%b" 'RVM reloaded!\n'
# make sure we clean env on reload
__rvm_env_loaded=1
unset __rvm_project_rvmrc_lock
fi
rvm_loaded_flag=1
__rvm_teardown
fi
else
printf "%b" "\n\$rvm_path ($rvm_path) does not exist."
fi
unset rvm_prefix_needs_trailing_slash rvm_gems_cache_path rvm_gems_path rvm_project_rvmrc_default rvm_gemset_separator rvm_reload_flag
fi
Hope this Helps!

Related

Texts show up when starting Terminal

The text/code below shows up whenever I startup my terminal. This started happening after I checked a box in VSCode settings on "Send Keybindings To Shell" under the Terminal section. The texts still showed up even after I unchecked the box. I tried restarting both VScode, Terminal, my mac, and tried checking/unchecking that box in settings several times but the problem persists.
I am using MacOS (Big Sur V 11.5.2) and Zsh.
I have no idea how to pinpoint where the problem is coming from and how to solve it. I'd appreciate suggestions on what steps I can take to solve this.
EDIT:
It was tab completion info, autoload -U compinit and compinit -i, in ~/.zshrc that was causing the issue. If I comment this out, texts stop showing up. But even if I keep this part, tab completion stopped working. I'd like to keep my tab completion. Any suggestions on how to fix this?
What my terminal screen looks like when I start it:
Full text:
add-zsh-hook () {
emulate -L zsh
local -a hooktypes
hooktypes=(chpwd precmd preexec periodic zshaddhistory zshexit zsh_directory_name)
local usage="Usage: add-zsh-hook hook function\nValid hooks are:\n $hooktypes"
local opt
local -a autoopts
integer del list help
while getopts "dDhLUzk" opt
do
case $opt in
(d) del=1 ;;
(D) del=2 ;;
(h) help=1 ;;
(L) list=1 ;;
([Uzk]) autoopts+=(-$opt) ;;
(*) return 1 ;;
esac
done
shift $(( OPTIND - 1 ))
if (( list ))
then
typeset -mp "(${1:-${(#j:|:)hooktypes}})_functions"
return $?
elif (( help || $# != 2 || ${hooktypes[(I)$1]} == 0 ))
then
print -u$(( 2 - help )) $usage
return $(( 1 - help ))
fi
local hook="${1}_functions"
local fn="$2"
if (( del ))
then
if (( ${(P)+hook} ))
then
if (( del == 2 ))
then
set -A $hook ${(P)hook:#${~fn}}
else
set -A $hook ${(P)hook:#$fn}
fi
if (( ! ${(P)#hook} ))
then
unset $hook
fi
fi
else
if (( ${(P)+hook} ))
then
if (( ${${(P)hook}[(I)$fn]} == 0 ))
then
typeset -ga $hook
set -A $hook ${(P)hook} $fn
fi
else
typeset -ga $hook
set -A $hook $fn
fi
autoload $autoopts -- $fn
fi
}
compdump () {
# undefined
builtin autoload -XUz
}
compinit () {
emulate -L zsh
setopt extendedglob
typeset _i_dumpfile _i_files _i_line _i_done _i_dir _i_autodump=1
typeset _i_tag _i_file _i_addfiles _i_fail=ask _i_check=yes _i_name
while [[ $# -gt 0 && $1 = -[dDiuC] ]]
do
case "$1" in
(-d) _i_autodump=1
shift
if [[ $# -gt 0 && "$1" != -[dfQC] ]]
then
_i_dumpfile="$1"
shift
fi ;;
(-D) _i_autodump=0
shift ;;
(-i) _i_fail=ign
shift ;;
(-u) _i_fail=use
shift ;;
(-C) _i_check=
shift ;;
esac
done
typeset -gHA _comps _services _patcomps _postpatcomps
typeset -gHA _compautos
typeset -gHA _lastcomp
if [[ -n $_i_dumpfile ]]
then
typeset -g _comp_dumpfile="$_i_dumpfile"
else
typeset -g _comp_dumpfile="${ZDOTDIR:-$HOME}/.zcompdump"
fi
typeset -gHa _comp_options
_comp_options=(bareglobqual extendedglob glob multibyte multifuncdef nullglob rcexpandparam unset NO_allexport NO_aliases NO_cshnullglob NO_cshjunkiequotes NO_errexit NO_errreturn NO_globassign NO_globsubst NO_histsubstpattern NO_ignorebraces NO_ignoreclosebraces NO_kshglob NO_ksharrays NO_kshtypeset NO_markdirs NO_octalzeroes NO_posixbuiltins NO_posixidentifiers NO_shwordsplit NO_shglob NO_warnnestedvar NO_warncreateglobal)
typeset -gH _comp_setup='local -A _comp_caller_options;
_comp_caller_options=(${(kv)options[#]});
setopt localoptions localtraps localpatterns ${_comp_options[#]};
local IFS=$'\'\ \\t\\r\\n\\0\'';
builtin enable -p \| \~ \( \? \* \[ \< \^ \# 2>&-;
exec </dev/null;
trap - ZERR;
local -a reply;
local REPLY;
local REPORTTIME;
unset REPORTTIME'
typeset -ga compprefuncs comppostfuncs
compprefuncs=()
comppostfuncs=()
: $funcstack
compdef () {
local opt autol type func delete eval new i ret=0 cmd svc
local -a match mbegin mend
emulate -L zsh
setopt extendedglob
if (( ! $# ))
then
print -u2 "$0: I need arguments"
return 1
fi
while getopts "anpPkKde" opt
do
case "$opt" in
(a) autol=yes ;;
(n) new=yes ;;
([pPkK]) if [[ -n "$type" ]]
then
print -u2 "$0: type already set to $type"
return 1
fi
if [[ "$opt" = p ]]
then
type=pattern
elif [[ "$opt" = P ]]
then
type=postpattern
elif [[ "$opt" = K ]]
then
type=widgetkey
else
type=key
fi ;;
(d) delete=yes ;;
(e) eval=yes ;;
esac
done
shift OPTIND-1
if (( ! $# ))
then
print -u2 "$0: I need arguments"
return 1
fi
if [[ -z "$delete" ]]
then
if [[ -z "$eval" ]] && [[ "$1" = *\=* ]]
then
while (( $# ))
do
if [[ "$1" = *\=* ]]
then
cmd="${1%%\=*}"
svc="${1#*\=}"
func="$_comps[${_services[(r)$svc]:-$svc}]"
[[ -n ${_services[$svc]} ]] && svc=${_services[$svc]}
[[ -z "$func" ]] && func="${${_patcomps[(K)$svc][1]}:-${_postpatcomps[(K)$svc][1]}}"
if [[ -n "$func" ]]
then
_comps[$cmd]="$func"
_services[$cmd]="$svc"
else
print -u2 "$0: unknown command or service: $svc"
ret=1
fi
else
print -u2 "$0: invalid argument: $1"
ret=1
fi
shift
done
return ret
fi
func="$1"
[[ -n "$autol" ]] && autoload -Uz "$func"
shift
case "$type" in
(widgetkey) while [[ -n $1 ]]
do
if [[ $# -lt 3 ]]
then
print -u2 "$0: compdef -K requires <widget> <comp-widget> <key>"
return 1
fi
[[ $1 = _* ]] || 1="_$1"
[[ $2 = .* ]] || 2=".$2"
[[ $2 = .menu-select ]] && zmodload -i zsh/complist
zle -C "$1" "$2" "$func"
if [[ -n $new ]]
then
bindkey "$3" | IFS=$' \t' read -A opt
[[ $opt[-1] = undefined-key ]] && bindkey "$3" "$1"
else
bindkey "$3" "$1"
fi
shift 3
done ;;
(key) if [[ $# -lt 2 ]]
then
print -u2 "$0: missing keys"
return 1
fi
if [[ $1 = .* ]]
then
[[ $1 = .menu-select ]] && zmodload -i zsh/complist
zle -C "$func" "$1" "$func"
else
[[ $1 = menu-select ]] && zmodload -i zsh/complist
zle -C "$func" ".$1" "$func"
fi
shift
for i
do
if [[ -n $new ]]
then
bindkey "$i" | IFS=$' \t' read -A opt
[[ $opt[-1] = undefined-key ]] || continue
fi
bindkey "$i" "$func"
done ;;
(*) while (( $# ))
do
if [[ "$1" = -N ]]
then
type=normal
elif [[ "$1" = -p ]]
then
type=pattern
elif [[ "$1" = -P ]]
then
type=postpattern
else
case "$type" in
(pattern) if [[ $1 = (#b)(*)=(*) ]]
then
_patcomps[$match[1]]="=$match[2]=$func"
else
_patcomps[$1]="$func"
fi ;;
(postpattern) if [[ $1 = (#b)(*)=(*) ]]
then
_postpatcomps[$match[1]]="=$match[2]=$func"
else
_postpatcomps[$1]="$func"
fi ;;
(*) if [[ "$1" = *\=* ]]
then
cmd="${1%%\=*}"
svc=yes
else
cmd="$1"
svc=
fi
if [[ -z "$new" || -z "${_comps[$1]}" ]]
then
_comps[$cmd]="$func"
[[ -n "$svc" ]] && _services[$cmd]="${1#*\=}"
fi ;;
esac
fi
shift
done ;;
esac
else
case "$type" in
(pattern) unset "_patcomps[$^#]" ;;
(postpattern) unset "_postpatcomps[$^#]" ;;
(key) print -u2 "$0: cannot restore key bindings"
return 1 ;;
(*) unset "_comps[$^#]" ;;
esac
fi
}
typeset _i_wdirs _i_wfiles
_i_wdirs=()
_i_wfiles=()
autoload -Uz compaudit
if [[ -n "$_i_check" ]]
then
typeset _i_q
if ! eval compaudit
then
if [[ -n "$_i_q" ]]
then
if [[ "$_i_fail" = ask ]]
then
if ! read -q "?zsh compinit: insecure $_i_q, run compaudit for list.
Ignore insecure $_i_q and continue [y] or abort compinit [n]? "
then
print -u2 "$0: initialization aborted"
unfunction compinit compdef
unset _comp_dumpfile _comp_secure compprefuncs comppostfuncs _comps _patcomps _postpatcomps _compautos _lastcomp
return 1
fi
_i_wfiles=()
_i_wdirs=()
else
(( $#_i_wfiles )) && _i_files=("${(#)_i_files:#(${(j:|:)_i_wfiles%.zwc})}")
(( $#_i_wdirs )) && _i_files=("${(#)_i_files:#(${(j:|:)_i_wdirs%.zwc})/*}")
fi
fi
typeset -g _comp_secure=yes
fi
fi
autoload -Uz compdump compinstall
_i_done=''
if [[ -f "$_comp_dumpfile" ]]
then
if [[ -n "$_i_check" ]]
then
IFS=$' \t' read -rA _i_line < "$_comp_dumpfile"
if [[ _i_autodump -eq 1 && $_i_line[2] -eq $#_i_files && $ZSH_VERSION = $_i_line[4] ]]
then
builtin . "$_comp_dumpfile"
_i_done=yes
fi
else
builtin . "$_comp_dumpfile"
_i_done=yes
fi
fi
if [[ -z "$_i_done" ]]
then
typeset -A _i_test
for _i_dir in $fpath
do
[[ $_i_dir = . ]] && continue
(( $_i_wdirs[(I)$_i_dir] )) && continue
for _i_file in $_i_dir/^([^_]*|*~|*.zwc)(N)
do
_i_name="${_i_file:t}"
(( $+_i_test[$_i_name] + $_i_wfiles[(I)$_i_file] )) && continue
_i_test[$_i_name]=yes
IFS=$' \t' read -rA _i_line < $_i_file
_i_tag=$_i_line[1]
shift _i_line
case $_i_tag in
(\#compdef) if [[ $_i_line[1] = -[pPkK](n|) ]]
then
compdef ${_i_line[1]}na "${_i_name}" "${(#)_i_line[2,-1]}"
else
compdef -na "${_i_name}" "${_i_line[#]}"
fi ;;
(\#autoload) autoload -Uz "$_i_line[#]" ${_i_name}
[[ "$_i_line" != \ # ]] && _compautos[${_i_name}]="$_i_line" ;;
esac
done
done
if [[ $_i_autodump = 1 ]]
then
compdump
fi
fi
for _i_line in complete-word delete-char-or-list expand-or-complete expand-or-complete-prefix list-choices menu-complete menu-expand-or-complete reverse-menu-complete
do
zle -C $_i_line .$_i_line _main_complete
done
zle -la menu-select && zle -C menu-select .menu-select _main_complete
bindkey '^i' | IFS=$' \t' read -A _i_line
if [[ ${_i_line[2]} = expand-or-complete ]] && zstyle -a ':completion:' completer _i_line && (( ${_i_line[(i)_expand]} <= ${#_i_line} ))
then
bindkey '^i' complete-word
fi
unfunction compinit compaudit
autoload -Uz compinit compaudit
return 0
}
compinstall () {
# undefined
builtin autoload -XUz
}
is-at-least () {
emulate -L zsh
local IFS=".-" min_cnt=0 ver_cnt=0 part min_ver version order
min_ver=(${=1})
version=(${=2:-$ZSH_VERSION} 0)
while (( $min_cnt <= ${#min_ver} ))
do
while [[ "$part" != <-> ]]
do
(( ++ver_cnt > ${#version} )) && return 0
if [[ ${version[ver_cnt]} = *[0-9][^0-9]* ]]
then
order=(${version[ver_cnt]} ${min_ver[ver_cnt]})
if [[ ${version[ver_cnt]} = <->* ]]
then
[[ $order != ${${(On)order}} ]] && return 1
else
[[ $order != ${${(O)order}} ]] && return 1
fi
[[ $order[1] != $order[2] ]] && return 0
fi
part=${version[ver_cnt]##*[^0-9]}
done
while true
do
(( ++min_cnt > ${#min_ver} )) && return 0
[[ ${min_ver[min_cnt]} = <-> ]] && break
done
(( part > min_ver[min_cnt] )) && return 0
(( part < min_ver[min_cnt] )) && return 1
part=''
done
}
Simple Fix: Back up your ~/.zshrc (for example, mv ~/.zshrc ~/.zshrc.bak). Then remove it using rm ~/.zshrc. Restart the terminal. This in princlpe should fix your issue.
Also, you can copy back the relevant PATH informations, etc from the backed up .zshrc if necessary.

unable to read a file in while loop

I've the below code:
#!/bin/bash
. ~/.bash_profile
dt=$(date +"%Y.%m.%d")
if [[ "$#" -eq '0' ]] || [[ "$#" -eq '1' ]]
then
echo -e "Not correct usage"
exit 1
fi
tar zvxf $SHARE/*.gz -C $SHARE/landing/
sleep 3
ops () {
//
some sets of command
//
}
while read -r line
do
if [[ "$1" == "A" ]] || [[ "$1" == "B" ]] || [[ "$1" == "C" ]] && [[ "$2" =~ "$line" ]] || [[ "$2" == "ALL" ]]
then
ops
fi
done < $SHARE/landing/dir/ApprovedList."$1"
When i run the script, i can see that it's able to untar the .gz file and place it into the folder :$SHARE/landing/
But i guess it's not able to read the file and perform the operations inside the ops function, below is the last line of output i'm getting after running the script in interactive mode:
+ read -r line
Any help is most welcome!!!
Please show the input format, the argument format, and some explanation of those. In the meantime, tweaked for readability and error handling - edit to taste. YMMV.
#!/bin/bash
. ~/.bash_profile
ops () { # do some stuff
: some sets of commands ...
}
die() {
printf "%s\n\n Use: $0 x y z ...\n\n" "$1" >&2
kill -term $$ # exit in function behaves like return
}
# dt=$(date +"%Y.%m.%d") # unused
case "$#" in
0|1) die "Insufficient arguments" ;;
esac
tar zvxf "$SHARE"/*.gz -C "$SHARE/landing/" || die "tar failed"
sleep 3
infile="$SHARE/landing/dir/ApprovedList.$1"
[[ -e "$infile" ]] || die "$infile does not exist"
[[ -r "$infile" ]] || die "$infile is nor readable by $0 as $LOGNAME"
while read -r line
do case "$1" in
A|B|C) case "$2" in
*"$line"*|ALL) ops ;;
*) : data does not match, skipping ;;
esac ;;
*) die "Invalid arg1 '$1'";;
esac
done < "$infile"
Notes:
If you require exactly 2 arguments, then let's check exactly that:
die() {
printf "%s\n\n Use: $0 x y\n\n" "$1" >&2
kill -term $$ # exit in function behaves like return
}
and
case "$#" in
2) ;;
*) die "Incorrect # of arguments" ;;
esac
Also, better than the kill - add a trap at the top:
trap 'echo >&2 "ERROR in $0($BASH_SOURCE) at line $LINENO: [$BASH_COMMAND]"; exit $LINENO;' ERR
and use a literal error return in the function.
die() {
printf "%s\n\n Use: $0 x y\n\n" "$1" >&2
return 1
}
The check (except for [[ "$2" =~ "$line" ]])
if [[ "$1" == "A" ]] || [[ "$1" == "B" ]] || [[ "$1" == "C" ]] && [[ "$2" =~ "$line" ]] || [[ "$2" == "ALL" ]]
doesn't change inside the while-loop. So better check once before entering the while-loop.
So now you want to perform ops for each line of $SHARE/landing/dir/ApprovedList."$1".
You can use
xargs -a "$SHARE/landing/dir/ApprovedList.$1" -L 1 ops
EDIT:
When you have a simple check to perform for each line, you can move this check into the ops function.
First save $2 before entering the function:
to_be_checked="$2"
...
ops() {
[[ "$0" =~ "${to_be_checked}" ]] && return

'Bad Substitution' sourcing an auto-completion script as non-root user

I am trying to source an auto-completion script as a non-root user but receive a 'Bad Substitution' error message.
I am able to source it as root though.
On a other server I am able to source the script as non-root user.
I am guessing it is not a permission issue since I receive the same error trying to source a copy of the script with full permissions.
I have tried to echo all the environment variables used in the script, no issue there.
As the auto-completion script is packaged with the software I use I would rather not modify it.
Anyone would have a hint on what could be missing to the user so I can source the script from it ?
Thanks in advance for any idea!
Edit1:
ps output:
PID TTY TIME CMD
3261 pts/0 00:00:00 bash
73620 pts/0 00:00:00 ps
Error only as non-root user:
/opt/splunk/share/splunk/cli-command-completion.sh: 7: /opt/splunk/share/splunk/cli-command-completion.sh: Bad substitution
Script:
# Vainstein K 12aug2013
# # # Check a few prereqs.
feature='"splunk <verb> <object>" tab-completion'
[ `basename $SHELL` != 'bash' ] && echo "Sorry, $feature is only for bash" >&2 && return 11
[ ${BASH_VERSINFO[0]} -lt 4 ] && echo "Sorry, $feature only works with bash 4.0 or higher" >&2 && return 12
[ `type -t complete` != 'builtin' ] && echo "Sorry, $feature requires a bash that supports programmable command completion" >&2 && return 13
die () {
echo "(exit=$?) $#" >&2 && exit 42
}
ifSourced () { # do NOT exit(1) from this function!
local readonly tempfile=`pwd`/tmp--cli-completion--$$
rm -f $tempfile
$BASH ${BASH_ARGV[0]} --populateTempfile $tempfile
[ $? -eq 0 ] || return
[ -e $tempfile ] || return
. $tempfile
rm -f $tempfile
# # # Associate the completion function with the splunk binary.
local readonly completionFunction=fSplunkComplete
complete -r splunk 2>/dev/null
complete -F $completionFunction splunk
# You can view the completion function anytime via: $ type fSplunkComplete
}
ifInvoked () { # all error checking happens in this function
local readonly debug=false
local readonly tempfile=$1
$debug && echo "Told that tempfile=$tempfile"
# # # If anything goes wrong, at least we don't pollute cwd with our tempfile.
$debug || trap "rm -f $tempfile" SIGINT SIGQUIT SIGTERM SIGABRT SIGPIPE
touch $tempfile || die "Cannot touch tempfile=$tempfile"
# # # Decide where SPLUNK_HOME is.
if [ "$(dirname $(pwd))" == 'bin' ]; then
local readonly splunkHome=$(dirname $(dirname $(pwd)))
elif [ -n "$SPLUNK_HOME" ]; then
local readonly splunkHome=$SPLUNK_HOME
else
die 'Cannot figure out where SPLUNK_HOME is'
fi
$debug && echo "Decided SPLUNK_HOME=$splunkHome"
# # # Check that splunk (the binary) exists.
local readonly splunkBinary=$splunkHome/bin/splunk
[ -e $splunkBinary -a -x $splunkBinary ] || die "Cannot find expected binary=$splunkBinary"
# # # Find the file with object->{verb1,verb2,...} map.
local readonly splunkrcCmdsXml=$splunkHome/etc/system/static/splunkrc_cmds.xml
[ -e $splunkrcCmdsXml ] || die "Cannot find expected file $splunkrcCmdsXml"
$debug && echo "Shall read verb-obj info from: $splunkrcCmdsXml"
# # # Parse the map file, and generate our internal verb->{objA,objB,...} map.
local -A verb_to_objects
local line object verb objectsForThisVerb lineNumber=0
local inItem=false
local readonly regex_depr='\<depr\>'
local readonly regex_verb='\<verb\>'
local readonly regex_synonym='\<synonym\>'
while read line; do
lineNumber=$((lineNumber+1))
if $inItem; then
if [[ $line =~ '</item>' ]]; then
$debug && echo "Exited item tag at line=$lineNumber; this was obj=$object"
inItem=false
object=''
elif [[ $line =~ '<cmd name' && ! $line =~ $regex_depr && ! $line =~ $regex_synonym ]]; then
[ -z "$object" ] && die "BUG: No object within item tag. (At line $lineNumber of $splunkrcCmdsXml)"
verb=${line#*\"} # remove shortest match of .*" from the front
verb=${verb%%\"*} # remove longest match of ".* from the back
[ "$verb" == '_internal' ] && continue # Why the... eh, moving on.
objectsForThisVerb=${verb_to_objects[$verb]}
objectsForThisVerb="$objectsForThisVerb $object"
verb_to_objects[$verb]=$objectsForThisVerb
$debug && echo "Mapped object=$object to verb=$verb at line=$lineNumber; now objectsForThisVerb='$objectsForThisVerb'"
fi
else # ! inItem
if [[ $line =~ '<item obj' && ! $line =~ $regex_depr && ! $line =~ $regex_verb && ! $line =~ $regex_synonym ]]; then
inItem=true
object=${line#*\"} # remove shortest match of .*" from the front
object=${object%%\"*} # remove longest match of ".* from the back
$debug && echo "Entered item tag at line=$lineNumber, parsed object=$object"
[ "$object" == 'on' ] && inItem=false # Do not expose Amrit's puerile jest.
[ "$object" == 'help' ] && inItem=false # Although 'help' is a verb, splunkrc_cmds.xml constructs it as an object; ugh. We'll deal with the objects (topics) of 'splunk help' separately, below.
fi
fi
done < $splunkrcCmdsXml
$debug && echo "Processed $lineNumber lines. Map keys: ${!verb_to_objects[*]}, values: ${verb_to_objects[#]}"
# # # Oh wait, '<verb> deploy-server' aren't in splunkrc_cmds.xml; thanks, Jojy!!!!!
for verb in reload enable disable display; do
objectsForThisVerb=${verb_to_objects[$verb]}
objectsForThisVerb="$objectsForThisVerb deploy-server"
verb_to_objects[$verb]=$objectsForThisVerb
done
# # # Find the file with topics understood by 'splunk help <topic>' command, and extract list of topics.
local readonly literalsPy=$splunkHome/lib/python2.7/site-packages/splunk/clilib/literals.py
[ -e $literalsPy ] || die "Cannot find expected file $literalsPy"
$debug && echo "Shall read help topics list from: $literalsPy"
local readonly helpTopics=$(sed '/^addHelp/! d; s/^addHelp//; s/,.*$//; s/[^a-zA-Z_-]/ /g; s/^[ ]*//; s/[ ].*$//; /^$/ d' $literalsPy | sort | uniq)
$debug && echo "Parsed help topics list as: $helpTopics"
#######################################################
# # # Write the completion function to tempfile: BEGIN.
local readonly completionFunction=fSplunkComplete
echo -e 'function '$completionFunction' () {' >> $tempfile
echo -e '\tlocal wordCur=${COMP_WORDS[COMP_CWORD]}' >> $tempfile
echo -e '\tlocal wordPrev=${COMP_WORDS[COMP_CWORD-1]}' >> $tempfile
echo -e '\tcase $wordPrev in' >> $tempfile
# # # What can follow 'splunk' itself? Verbs used in main.c to key the 'cmd_handlers' array; and verbs from splunkrc_cmds.xml; and 'help'.
local readonly keys__cmd_handlers='ftr start startnoss stop restart restartss status rebuild train fsck clean-dispatch clean-srtemp validate verifyconfig anonymize find clean createssl juststopit migrate --version -version version httpport soapport spool ftw envvars _RAW_envvars _port_check cmd _rest_xml_dump search dispatch rtsearch livetail _normalizepath _internal logout btool pooling _web_bootstart offline clone-prep-clear-config diag'
local allVerbs="${!verb_to_objects[*]}"
echo -e '\t\tsplunk)\n\t\t\tCOMPREPLY=( $(compgen -W "'$keys__cmd_handlers $allVerbs' help" -- $wordCur) ) ;;' >> $tempfile
# # # What can follow 'splunk _internal'? see cmd_internal() of main.c
local readonly actions_internal='http mgmt https pre-flight-checks check-db call rpc rpc-auth soap-call soap-call-auth prefixcount totalcount check-xml-files first-time-run make-splunkweb-certs-and-var-run-merged'
echo -e '\t\t_internal)\n\t\t\tCOMPREPLY=( $(compgen -W "'$actions_internal'" -- $wordCur) ) ;;' >> $tempfile
# # # Options to 'splunk clean' are in CLI::clean() of src/main/Clean.cpp; to 'splunk fsck', in usageBanner of src/main/Fsck.cpp; to 'splunk migrate', in CLI::migrate() of src/main/Migration.cpp
echo -e '\t\tclean)\n\t\t\tCOMPREPLY=( $(compgen -W "all eventdata globaldata userdata inputdata locks deployment-artifacts raft" -- $wordCur) ) ;;' >> $tempfile
echo -e '\t\tfsck)\n\t\t\tCOMPREPLY=( $(compgen -W "scan repair clear-bloomfilter make-searchable" -- $wordCur) ) ;;' >> $tempfile
echo -e '\t\tmigrate)\n\t\t\tCOMPREPLY=( $(compgen -W "input-records to-modular-inputs rename-cluster-app" -- $wordCur) ) ;;' >> $tempfile
# # # List the help topics.
echo -e '\t\thelp)\n\t\t\tCOMPREPLY=( $(compgen -W "'$helpTopics'" -- $wordCur) ) ;;' >> $tempfile
# # # What can follow 'splunk cmd'? any executable in SPLUNK_HOME/bin/
echo -e '\t\tcmd)\n\t\t\tCOMPREPLY=( $(compgen -o default -o filenames -G "'$splunkHome'/bin/*" -- $wordCur) ) ;;' >> $tempfile
# # # Finally, let each verb be completed by its objects.
for verb in $allVerbs; do
echo -e '\t\t'$verb')\n\t\t\tCOMPREPLY=( $(compgen -W "'${verb_to_objects[$verb]}'" -- $wordCur) ) ;;' >> $tempfile
done
# # # And if we've run out of suggestions, revert to bash's default completion behavior: filename completion.
echo -e '\t\t*)\n\t\t\tCOMPREPLY=( $(compgen -f -- $wordCur) ) ;;' >> $tempfile
echo -e '\tesac' >> $tempfile
echo -e '}' >> $tempfile
$debug && cp $tempfile $tempfile~bak
# # # Write the completion function to tempfile: DONE.
######################################################
# # # Sanity check: source the tempfile, make sure that the function we wrote can be parsed and loaded by the shell.
unset $completionFunction
. $tempfile
[ "`type -t $completionFunction`" == 'function' ] || die 'BUG: generated completion function cannot be parsed by bash'
}
if [ $SHLVL -eq 1 ]; then
[ $# -ge 1 ] && echo "Ignoring supplied arguments: $#" >&2
ifSourced
elif [ $SHLVL -eq 2 ]; then
if [ $# -eq 2 ] && [ $1 == '--populateTempfile' ]; then
ifInvoked $2
else
echo -e "This script must be sourced, like so:\n\n\t\033[1m. $0\033[0m\n"
fi
else
: # user is running screen(1) or something of the sort.
fi
# # # Clean up.
unset die ifSourced ifInvoked
Edit2:
xtrace output
++ feature='"splunk <verb> <object>" tab-completion'
+++ basename /bin/bash
++ '[' bash '!=' bash ']'
++ '[' 4 -lt 4 ']'
+++ type -t complete
++ '[' builtin '!=' builtin ']'
++ '[' 1 -eq 1 ']'
++ '[' 0 -ge 1 ']'
++ ifSourced
+++ pwd
++ local readonly tempfile=/home/splunk/tmp--cli-completion--12431
++ rm -f /home/splunk/tmp--cli-completion--12431
++ /bin/sh cli-command-completion.sh --populateTempfile /home/splunk/tmp--cli-completion--12431
+ feature="splunk <verb> <object>" tab-completion
+ basename /bin/bash
+ [ bash != bash ]
cli-command-completion.sh: 8: cli-command-completion.sh: Bad substitution
++ '[' 2 -eq 0 ']'
++ return
++ unset die ifSourced ifInvoked
Edit3:
When using
set -o verbose
set -o noglob
set -o noglob
and checking differences between OK (root) and failing (non-root) run.
OK side:
[...]
+++ basename /bin/bash
++ '[' bash '!=' bash ']'
[ ${BASH_VERSINFO[0]} -lt 4 ] && echo "Sorry, $feature only works with bash 4.0 or higher" >&2 && return 12
++ '[' 4 -lt 4 ']'
[...]
++ local readonly tempfile=/home/splunk/tmp--cli-completion--42064
++ rm -f /home/splunk/tmp--cli-completion--42064
++ /bin/bash cli-command-completion.sh --populateTempfile /home/splunk/tmp--cli-completion--42064
+ set -o verbose
set -o noglob
+ set -o noglob
# Vainstein K 12aug2013
[...]
[ ${BASH_VERSINFO[0]} -lt 4 ] && echo "Sorry, $feature only works with bash 4.0 or higher" >&2 && return 12
+ '[' 4 -lt 4 ']'
[...]
Failing side:
[...]
+++ basename /bin/bash
++ '[' bash '!=' bash ']'
[ ${BASH_VERSINFO[0]} -lt 4 ] && echo "Sorry, $feature only works with bash 4.0 or higher" >&2 && return 12
++ '[' 4 -lt 4 ']'
[...]
++ local readonly tempfile=/home/splunk/tmp--cli-completion--40686
++ rm -f /home/splunk/tmp--cli-completion--40686
++ /bin/sh cli-command-completion.sh --populateTempfile /home/splunk/tmp--cli-completion--40686
+ set -o verbose
set -o noglob
+ set -o noglob
# Vainstein K 12aug2013
# # # Check a few prereqs.
feature='"splunk <verb> <object>" tab-completion'
+ feature="splunk <verb> <object>" tab-completion
[ `basename $SHELL` != 'bash' ] && echo "Sorry, $feature is only for bash" >&2 && return 11
+ basename /bin/bash
+ [ bash != bash ]
[ ${BASH_VERSINFO[0]} -lt 4 ] && echo "Sorry, $feature only works with bash 4.0 or higher" >&2 && return 12
cli-command-completion.sh: 10: cli-command-completion.sh: Bad substitution
++ '[' 2 -eq 0 ']'
++ return
# # # Clean up.
unset die ifSourced ifInvoked
++ unset die ifSourced ifInvoked
Seems like as non-root, it runs as /bin/sh whereas as 'bash' as root.
Weird because I tried multiple things to force bash there, maybe not the right ones.
It also fail at line 7 even though the first loop succeeds.
This should do the trick (line 7):
[ $(type -t complete) != 'builtin' ] && echo "Sorry, $feature requires a bash that supports programmable command completion" >&2 && return 13
Turns out from trace output that /bin/sh was used instead of /bin/bash to launch the script because /bin/bash was not set as default shell.
I have changed the default shell to /bin/bash and it is all ok now :)
I have used this method to set /bin/bash as default shell :
Check:
grep /etc/passwd
Change:
chsh --shell /bin/bash
Check modification:
grep /etc/passwd
Thanks for the help!

Space in a folder, terminal can't cd

Macbook Pro 13" 2016, High Sierra 10.13.2
I know that terminal cannot open/cd folders with spaces unless there is exis symbol \, or " " around space or the whole folder name. However, terminal and iTerm still having an issue with that.
*****:~ #######$ cd /Users/#######Google\ Drive
-bash: cd: /Users/#######/Google: No such file or directory
*****:~ #######$ cd Google\ Drive/
-bash: cd: Google: No such file or directory
*****:~ #######$ cd Google' 'Drive/
-bash: cd: Google: No such file or directory
*****:~ #######$ cd 'Google Drive'/
-bash: cd: Google: No such file or directory
*****:~ #######$ cd "Google Drive"
-bash: cd: Google: No such file or directory
*****:~ #######$ cd Google" "Drive
-bash: cd: Google: No such file or directory
Google Drive is visible with ls.
Google Drive is also typed with auto-completion (type Goo and press enter) and drag-n-drop of folder from Finder to Terminal, where terminal inserts \ itself and it gives you Google\ Drive/.
This behavior is relevant to, probably, all folders on my mac. This happens for a while already and I want to solve it.
P.S. Problem occurs primarily for cd command.
upd.
As requested, here's the output of
stivens ~ $ ls -d Google*Drive | xxd
00000000: 476f 6f67 6c65 2044 7269 7665 0a Google Drive.
and type cd
stivens ~ $ type cd
cd is a function
cd ()
{
unset RETVAL;
if __gvm_is_function __gvm_oldcd; then
__gvm_oldcd $*;
fi;
local dot_go_version dot_go_pkgset rslt;
local defaults_go_name defaults_go_pkgset;
local defaults_resolved=false;
local defaults_hash;
defaults_hash=();
if [[ "$GVM_ROOT" == "" ]]; then
__gvm_display_error "GVM_ROOT not set. Please source \$GVM_ROOT/scripts/gvm";
return $?;
fi;
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "Resolving defaults...";
__gvm_read_environment_file "${GVM_ROOT}/environments/default" > /dev/null;
rslt=$?;
defaults_hash=(${RETVAL});
if [[ $rslt -eq 0 ]]; then
defaults_resolved=true;
else
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "Can't find default environment. Falling back to system.";
__gvm_read_environment_file "${GVM_ROOT}/environments/system" > /dev/null;
rslt=$?;
defaults_hash=(${RETVAL});
if [[ $rslt -eq 0 ]]; then
defaults_resolved=true;
else
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "Can't find system environment.";
fi;
fi;
if [[ "${defaults_resolved}" == false ]]; then
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "Resolving fallback go version and pkgset from all available.";
local fallback_go_version="";
__gvm_resolve_fallback_version > /dev/null;
fallback_go_version="${RETVAL}";
local fallback_go_pkgset="";
__gvm_resolve_fallback_pkgset "${fallback_go_version}" > /dev/null;
fallback_go_pkgset="${RETVAL}";
{
setValueForKeyFakeAssocArray "gvm_go_name" "${fallback_go_version}" "${defaults_hash[*]}" > /dev/null;
defaults_hash=(${RETVAL});
setValueForKeyFakeAssocArray "gvm_pkgset_name" "${fallback_go_pkgset}" "${defaults_hash[*]}" > /dev/null;
defaults_hash=(${RETVAL})
};
unset fallback_go_version;
unset fallback_go_pkgset;
defaults_resolved=true;
fi;
defaults_go_name="";
defaults_go_pkgset="";
{
valueForKeyFakeAssocArray "gvm_go_name" "${defaults_hash[*]}" > /dev/null;
defaults_go_name="${RETVAL}";
valueForKeyFakeAssocArray "gvm_pkgset_name" "${defaults_hash[*]}" > /dev/null;
defaults_go_pkgset="${RETVAL}"
};
if [[ "${GVM_DEBUG}" -eq 1 ]]; then
echo "Resolved default go: ${defaults_go_name:-[EMPTY]}";
echo "Resolved default pkgset: ${defaults_go_pkgset:-[EMPTY]}";
fi;
__gvmp_find_closest_dot_go_version > /dev/null;
rslt=$?;
dot_go_version="${RETVAL}";
if [[ $rslt -eq 0 ]]; then
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "Found dot_go_version: ${dot_go_version}";
local use_goversion="";
__gvmp_read_dot_go_version "${dot_go_version}" > /dev/null;
use_goversion="${RETVAL}";
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "Switching to: ${use_goversion}";
\gvm use --quiet "${use_goversion}" || return 1;
unset use_goversion;
else
if [[ -n "${defaults_go_name}" ]]; then
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "No .go-version found. Using system or default go.";
\gvm use --quiet "${defaults_go_name}" || return 1;
else
if [[ "${GVM_DEBUG}" -eq 1 ]]; then
local installed_hash;
installed_hash=();
__gvm_find_installed "" "${GVM_ROOT}/gos" > /dev/null;
installed_hash=(${RETVAL});
local go_archive_path="$GVM_ROOT/archive/go";
echo "No fallback go version could be found.";
if [[ ${#installed_hash[#]} -eq 0 && ! -d "${go_archive_path}" ]]; then
__gvm_locale_text_for_key "go_install_prompt" > /dev/null;
__gvm_display_error "${RETVAL}";
return 1;
fi;
unset go_archive_path;
unset installed_hash;
fi;
return 0;
fi;
fi;
__gvmp_find_closest_dot_go_pkgset > /dev/null;
rslt=$?;
dot_go_pkgset="${RETVAL}";
if [[ $rslt -eq 0 ]]; then
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "Found .go-pkgset: ${dot_go_pkgset}";
local use_gopkgset="";
__gvmp_read_dot_go_pkgset "${dot_go_pkgset}" > /dev/null;
use_gopkgset="${RETVAL}";
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "Switching to: ${use_gopkgset}";
\gvm pkgset use --quiet "${use_gopkgset}" || return 1;
unset use_gopkgset;
else
if [[ -n "${defaults_go_pkgset}" ]]; then
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "No .go-pkgset found. Using system or default pkgset.";
\gvm pkgset use --quiet "${defaults_go_pkgset}" || return 1;
else
[[ "${GVM_DEBUG}" -eq 1 ]] && echo "No fallback pkgset could be found.";
fi;
fi;
return 0
}
command cd Google\ Drive/ does work, \cd Google\ Drive/ does not though.
Okay, I figured out what caused the issue.
I noticed GVM occurrence in type cd and recalled that at some point I installed Go Version Manager, aka GVM, and found a script parser in .bash_profile [[ -s "/Users/stivens/.gvm/scripts/gvm" ]] && source "/Users/stivens/.gvm/scripts/gvm".
I just commented it out and now cd works properly.
Bazinga!

Oh-My-Zsh completion not working

I reinstalled my computer running macOS Sierra and also reinstalled oh-my-zsh. I copied over my old zshrc, which was working fine (and is still working fine on another computer).
However, every start of the zsh, the following output emerges, before the shell starts up:
bracketed-paste-magic () {
# undefined
builtin autoload -XUz
}
colors () {
emulate -L zsh
typeset -Ag color colour
color=(00 none 01 bold 02 faint 22 normal 03 standout 23 no-standout 04 underline 24 no-underline 05 blink 25 no-blink 07 reverse 27 no-reverse 08 conceal 28 no-conceal 30 black 40 bg-black 31 red 41 bg-red 32 green 42 bg-green 33 yellow 43 bg-yellow 34 blue 44 bg-blue 35 magenta 45 bg-magenta 36 cyan 46 bg-cyan 37 white 47 bg-white 39 default 49 bg-default)
local k
for k in ${(k)color}
do
color[${color[$k]}]=$k
done
for k in ${color[(I)3?]}
do
color[fg-${color[$k]}]=$k
done
color[grey]=${color[black]}
color[fg-grey]=${color[grey]}
color[bg-grey]=${color[bg-black]}
colour=(${(kv)color})
local lc=$'\e[' rc=m
typeset -Hg reset_color bold_color
reset_color="$lc${color[none]}$rc"
bold_color="$lc${color[bold]}$rc"
typeset -AHg fg fg_bold fg_no_bold
for k in ${(k)color[(I)fg-*]}
do
fg[${k#fg-}]="$lc${color[$k]}$rc"
fg_bold[${k#fg-}]="$lc${color[bold]};${color[$k]}$rc"
fg_no_bold[${k#fg-}]="$lc${color[normal]};${color[$k]}$rc"
done
typeset -AHg bg bg_bold bg_no_bold
for k in ${(k)color[(I)bg-*]}
do
bg[${k#bg-}]="$lc${color[$k]}$rc"
bg_bold[${k#bg-}]="$lc${color[bold]};${color[$k]}$rc"
bg_no_bold[${k#bg-}]="$lc${color[normal]};${color[$k]}$rc"
done
}
compdump () {
# undefined
builtin autoload -XUz
}
compinit () {
emulate -L zsh
setopt extendedglob
typeset _i_dumpfile _i_files _i_line _i_done _i_dir _i_autodump=1
typeset _i_tag _i_file _i_addfiles _i_fail=ask _i_check=yes _i_name
while [[ $# -gt 0 && $1 = -[dDiuC] ]]
do
case "$1" in
(-d) _i_autodump=1
shift
if [[ $# -gt 0 && "$1" != -[dfQC] ]]
then
_i_dumpfile="$1"
shift
fi ;;
(-D) _i_autodump=0
shift ;;
(-i) _i_fail=ign
shift ;;
(-u) _i_fail=use
shift ;;
(-C) _i_check=
shift ;;
esac
done
typeset -gHA _comps _services _patcomps _postpatcomps
typeset -gHA _compautos
typeset -gHA _lastcomp
if [[ -n $_i_dumpfile ]]
then
typeset -g _comp_dumpfile="$_i_dumpfile"
else
typeset -g _comp_dumpfile="${ZDOTDIR:-$HOME}/.zcompdump"
fi
typeset -gHa _comp_options
_comp_options=(bareglobqual extendedglob glob multibyte multifuncdef nullglob rcexpandparam unset NO_allexport NO_aliases NO_cshnullglob NO_cshjunkiequotes NO_errexit NO_globassign NO_globsubst NO_histsubstpattern NO_ignorebraces NO_ignoreclosebraces NO_kshglob NO_ksharrays NO_kshtypeset NO_markdirs NO_octalzeroes NO_posixbuiltins NO_shwordsplit NO_shglob NO_warncreateglobal)
typeset -gH _comp_setup='local -A _comp_caller_options;
_comp_caller_options=(${(kv)options[#]});
setopt localoptions localtraps localpatterns ${_comp_options[#]};
local IFS=$'\'\ \\t\\r\\n\\0\'';
builtin enable -p \| \~ \( \? \* \[ \< \^ \# 2>/dev/null;
exec </dev/null;
trap - ZERR;
local -a reply;
local REPLY'
typeset -ga compprefuncs comppostfuncs
compprefuncs=()
comppostfuncs=()
: $funcstack
compdef () {
local opt autol type func delete eval new i ret=0 cmd svc
local -a match mbegin mend
emulate -L zsh
setopt extendedglob
if (( ! $# ))
then
print -u2 "$0: I need arguments"
return 1
fi
while getopts "anpPkKde" opt
do
case "$opt" in
(a) autol=yes ;;
(n) new=yes ;;
([pPkK]) if [[ -n "$type" ]]
then
print -u2 "$0: type already set to $type"
return 1
fi
if [[ "$opt" = p ]]
then
type=pattern
elif [[ "$opt" = P ]]
then
type=postpattern
elif [[ "$opt" = K ]]
then
type=widgetkey
else
type=key
fi ;;
(d) delete=yes ;;
(e) eval=yes ;;
esac
done
shift OPTIND-1
if (( ! $# ))
then
print -u2 "$0: I need arguments"
return 1
fi
if [[ -z "$delete" ]]
then
if [[ -z "$eval" ]] && [[ "$1" = *\=* ]]
then
while (( $# ))
do
if [[ "$1" = *\=* ]]
then
cmd="${1%%\=*}"
svc="${1#*\=}"
func="$_comps[${_services[(r)$svc]:-$svc}]"
[[ -n ${_services[$svc]} ]] && svc=${_services[$svc]}
[[ -z "$func" ]] && func="${${_patcomps[(K)$svc][1]}:-${_postpatcomps[(K)$svc][1]}}"
if [[ -n "$func" ]]
then
_comps[$cmd]="$func"
_services[$cmd]="$svc"
else
print -u2 "$0: unknown command or service: $svc"
ret=1
fi
else
print -u2 "$0: invalid argument: $1"
ret=1
fi
shift
done
return ret
fi
func="$1"
[[ -n "$autol" ]] && autoload -Uz "$func"
shift
case "$type" in
(widgetkey) while [[ -n $1 ]]
do
if [[ $# -lt 3 ]]
then
print -u2 "$0: compdef -K requires <widget> <comp-widget> <key>"
return 1
fi
[[ $1 = _* ]] || 1="_$1"
[[ $2 = .* ]] || 2=".$2"
[[ $2 = .menu-select ]] && zmodload -i zsh/complist
zle -C "$1" "$2" "$func"
if [[ -n $new ]]
then
bindkey "$3" | IFS=$' \t' read -A opt
[[ $opt[-1] = undefined-key ]] && bindkey "$3" "$1"
else
bindkey "$3" "$1"
fi
shift 3
done ;;
(key) if [[ $# -lt 2 ]]
then
print -u2 "$0: missing keys"
return 1
fi
if [[ $1 = .* ]]
then
[[ $1 = .menu-select ]] && zmodload -i zsh/complist
zle -C "$func" "$1" "$func"
else
[[ $1 = menu-select ]] && zmodload -i zsh/complist
zle -C "$func" ".$1" "$func"
fi
shift
for i
do
if [[ -n $new ]]
then
bindkey "$i" | IFS=$' \t' read -A opt
[[ $opt[-1] = undefined-key ]] || continue
fi
bindkey "$i" "$func"
done ;;
(*) while (( $# ))
do
if [[ "$1" = -N ]]
then
type=normal
elif [[ "$1" = -p ]]
then
type=pattern
elif [[ "$1" = -P ]]
then
type=postpattern
else
case "$type" in
(pattern) if [[ $1 = (#b)(*)=(*) ]]
then
_patcomps[$match[1]]="=$match[2]=$func"
else
_patcomps[$1]="$func"
fi ;;
(postpattern) if [[ $1 = (#b)(*)=(*) ]]
then
_postpatcomps[$match[1]]="=$match[2]=$func"
else
_postpatcomps[$1]="$func"
fi ;;
(*) if [[ "$1" = *\=* ]]
then
cmd="${1%%\=*}"
svc=yes
else
cmd="$1"
svc=
fi
if [[ -z "$new" || -z "${_comps[$1]}" ]]
then
_comps[$cmd]="$func"
[[ -n "$svc" ]] && _services[$cmd]="${1#*\=}"
fi ;;
esac
fi
shift
done ;;
esac
else
case "$type" in
(pattern) unset "_patcomps[$^#]" ;;
(postpattern) unset "_postpatcomps[$^#]" ;;
(key) print -u2 "$0: cannot restore key bindings"
return 1 ;;
(*) unset "_comps[$^#]" ;;
esac
fi
}
typeset _i_wdirs _i_wfiles
_i_wdirs=()
_i_wfiles=()
autoload -Uz compaudit
if [[ -n "$_i_check" ]]
then
typeset _i_q
if ! eval compaudit
then
if [[ -n "$_i_q" ]]
then
if [[ "$_i_fail" = ask ]]
then
if ! read -q "?zsh compinit: insecure $_i_q, run compaudit for list.
Ignore insecure $_i_q and continue [y] or abort compinit [n]? "
then
print -u2 "$0: initialization aborted"
unfunction compinit compdef
unset _comp_dumpfile _comp_secure compprefuncs comppostfuncs _comps _patcomps _postpatcomps _compautos _lastcomp
return 1
fi
_i_wfiles=()
_i_wdirs=()
else
(( $#_i_wfiles )) && _i_files=("${(#)_i_files:#(${(j:|:)_i_wfiles%.zwc})}")
(( $#_i_wdirs )) && _i_files=("${(#)_i_files:#(${(j:|:)_i_wdirs%.zwc})/*}")
fi
fi
typeset -g _comp_secure=yes
fi
fi
autoload -Uz compdump compinstall
_i_done=''
if [[ -f "$_comp_dumpfile" ]]
then
if [[ -n "$_i_check" ]]
then
IFS=$' \t' read -rA _i_line < "$_comp_dumpfile"
if [[ _i_autodump -eq 1 && $_i_line[2] -eq $#_i_files && $ZSH_VERSION = $_i_line[4] ]]
then
builtin . "$_comp_dumpfile"
_i_done=yes
fi
else
builtin . "$_comp_dumpfile"
_i_done=yes
fi
fi
if [[ -z "$_i_done" ]]
then
typeset -A _i_test
for _i_dir in $fpath
do
[[ $_i_dir = . ]] && continue
(( $_i_wdirs[(I)$_i_dir] )) && continue
for _i_file in $_i_dir/^([^_]*|*~|*.zwc)(N)
do
_i_name="${_i_file:t}"
(( $+_i_test[$_i_name] + $_i_wfiles[(I)$_i_file] )) && continue
_i_test[$_i_name]=yes
IFS=$' \t' read -rA _i_line < $_i_file
_i_tag=$_i_line[1]
shift _i_line
case $_i_tag in
(\#compdef) if [[ $_i_line[1] = -[pPkK](n|) ]]
then
compdef ${_i_line[1]}na "${_i_name}" "${(#)_i_line[2,-1]}"
else
compdef -na "${_i_name}" "${_i_line[#]}"
fi ;;
(\#autoload) autoload -Uz "$_i_line[#]" ${_i_name}
[[ "$_i_line" != \ # ]] && _compautos[${_i_name}]="$_i_line" ;;
esac
done
done
if [[ $_i_autodump = 1 ]]
then
compdump
fi
fi
for _i_line in complete-word delete-char-or-list expand-or-complete expand-or-complete-prefix list-choices menu-complete menu-expand-or-complete reverse-menu-complete
do
zle -C $_i_line .$_i_line _main_complete
done
zle -la menu-select && zle -C menu-select .menu-select _main_complete
bindkey '^i' | IFS=$' \t' read -A _i_line
if [[ ${_i_line[2]} = expand-or-complete ]] && zstyle -a ':completion:' completer _i_line && (( ${_i_line[(i)_expand]} <= ${#_i_line} ))
then
bindkey '^i' complete-word
fi
unfunction compinit compaudit
autoload -Uz compinit compaudit
return 0
}
compinstall () {
# undefined
builtin autoload -XUz
}
down-line-or-beginning-search () {
# undefined
builtin autoload -XU
}
edit-command-line () {
# undefined
builtin autoload -XU
}
is-at-least () {
emulate -L zsh
local IFS=".-" min_cnt=0 ver_cnt=0 part min_ver version order
min_ver=(${=1})
version=(${=2:-$ZSH_VERSION} 0)
while (( $min_cnt <= ${#min_ver} ))
do
while [[ "$part" != <-> ]]
do
(( ++ver_cnt > ${#version} )) && return 0
if [[ ${version[ver_cnt]} = *[0-9][^0-9]* ]]
then
order=(${version[ver_cnt]} ${min_ver[ver_cnt]})
if [[ ${version[ver_cnt]} = <->* ]]
then
[[ $order != ${${(On)order}} ]] && return 1
else
[[ $order != ${${(O)order}} ]] && return 1
fi
[[ $order[1] != $order[2] ]] && return 0
fi
part=${version[ver_cnt]##*[^0-9]}
done
while true
do
(( ++min_cnt > ${#min_ver} )) && return 0
[[ ${min_ver[min_cnt]} = <-> ]] && break
done
(( part > min_ver[min_cnt] )) && return 0
(( part < min_ver[min_cnt] )) && return 1
part=''
done
}
up-line-or-beginning-search () {
# undefined
builtin autoload -XU
}
url-quote-magic () {
# undefined
builtin autoload -XUz
}
It seems some kind of script is written to stdout, instead of executed. However, I cannot find what the problem is. It might have something to do with completion, as the completion is not working.
Does anyone has any suggestion what the problem might be or where I should look next?
I was facing the same issue.
Re-installing Homebrew fixed the problem.
You have to change the default shell to zsh.
chsh -s /bin/zsh

Resources