[BUG]: zsh hangs forever after setting up aliases
masewo opened this issue · comments
What happened?
echo 'eval "$(gh copilot alias -- zsh)"' >> ~/.zshrc
After executing this command the zsh
does not start anymore. It hangs forever but it can be aborted with CTRL + C.
Expectation: zsh
works with aliases setup.
Can be healed by running one time manually gh copilot alias -- zsh
and accepting the data collecting.
Versions
gh v2.46.0, gh-copilot v1.0.0
Relevant terminal output
none
@masewo : thank you for opening this issue! 🙇 Being a Zsh user, I'd like to figure out how to replicate this and what might be causing this.
- What version of
zsh
are you using? - What operating system?
- What happens if this is 1) by itself? 2) moved to the beginning?
Showing my simplified setup
~ $ zsh --version
zsh 5.9 (x86_64-apple-darwin23.0)
~ $ cat ~/.zshrc
export EDITOR=vim
export PATH=/usr/local/opt/go/libexec/bin:$HOME/go/bin:$HOME/.dotnet:$HOME/bin:$PATH
export ZSH="$HOME/.oh-my-zsh"
ZSH_THEME="risto"
plugins=(git)
source $ZSH/oh-my-zsh.sh
alias vim="vim -o"
alias mvim="mvim -o"
export GH_PAGER="cat"
eval "$(gh copilot alias -- zsh)"
~ $ declare -f ghcs
ghcs () {
FUNCNAME="$funcstack[1]"
TARGET="shell"
local GH_DEBUG="$GH_DEBUG"
read -r -d '' __USAGE <<EOF
Wrapper around \`gh copilot suggest\` to suggest a command based on a natural language description of the desired output effort.
Supports executing suggested commands if applicable.
USAGE
$FUNCNAME [flags] <prompt>
FLAGS
-d, --debug Enable debugging
-h, --help Display help usage
-t, --target target Target for suggestion; must be shell, gh, git
default: "$TARGET"
EXAMPLES
- Guided experience
$ $FUNCNAME
- Git use cases
$ $FUNCNAME -t git "Undo the most recent local commits"
$ $FUNCNAME -t git "Clean up local branches"
$ $FUNCNAME -t git "Setup LFS for images"
- Working with the GitHub CLI in the terminal
$ $FUNCNAME -t gh "Create pull request"
$ $FUNCNAME -t gh "List pull requests waiting for my review"
$ $FUNCNAME -t gh "Summarize work I have done in issues and pull requests for promotion"
- General use cases
$ $FUNCNAME "Kill processes holding onto deleted files"
$ $FUNCNAME "Test whether there are SSL/TLS issues with github.com"
$ $FUNCNAME "Convert SVG to PNG and resize"
$ $FUNCNAME "Convert MOV to animated PNG"
EOF
local OPT OPTARG OPTIND
while getopts "dht:-:" OPT
do
if [ "$OPT" = "-" ]
then
OPT="${OPTARG%%=*}"
OPTARG="${OPTARG#"$OPT"}"
OPTARG="${OPTARG#=}"
fi
case "$OPT" in
(debug | d) GH_DEBUG=api ;;
(help | h) echo "$__USAGE"
return 0 ;;
(target | t) TARGET="$OPTARG" ;;
esac
done
shift "$((OPTIND-1))"
TMPFILE="$(mktemp -t gh-copilotXXX)"
trap 'rm -f "$TMPFILE"' EXIT
if GH_DEBUG="$GH_DEBUG" gh copilot suggest -t "$TARGET" "$@" --shell-out "$TMPFILE"
then
if [ -s "$TMPFILE" ]
then
FIXED_CMD="$(cat $TMPFILE)"
print -s "$FIXED_CMD"
echo
eval "$FIXED_CMD"
fi
else
return 1
fi
}
@andyfeller
zsh 5.9 (x86_64-apple-darwin23.0)
on Sonoma 14.4.
I installed it on two nearly identical Macs. On one it worked fine out of the box (it already had preinstalled an earlier version of GitHub Copilot CLI and was upgraded today) the other problematic machine never had GitHub Copilot CLI installed before.
I cannot reproduce the error now anymore because I "fixed" it by accepting data collection manually. Do you know how I can revert this?
I "fixed" it by accepting data collection manually. Do you know how I can revert this?
$ gh copilot config
? What would you like to configure?
> Optional Usage Analytics
? Allow GitHub to collect optional usage data to help us improve? This data does not include your queries.
> No
@your-diary Thanks. I mean how can the setting be reverted to "unset"? Maybe deleting some internal config file?
$ cat ~/.config/gh-copilot/config.yml #Check the content before removing it.
$ rm ~/.config/gh-copilot/config.yml
Thanks. Executing these commands:
➜ ~ cat .config/gh-copilot/config.yml
optional_analytics: true
➜ ~ rm .config/gh-copilot/config.yml
Now I have again the following behaviour: Open a new iTerm2 tab results in a hanging shell:
Last login: Fri Mar 22 19:04:22 on ttys001
If I cancel it with CTRL + C I get:
(eval):1: bad pattern: ^[7^[[?25l^[8^[[0G^[[2K
@andyfeller
Having eval "$(gh copilot alias -- zsh)"
by itself or moving at the top of .zshrc
does not change anything.
@masewo @your-diary : Okay, I think I understand what's going on here. 🤦 Thank you again for patience
In the case you have never used gh copilot
, it will ask you to opt in to sending anonymized telemetry before continuing, which is only a problem if the first time you use the extension is eval "$(gh copilot alias -- zsh)"
.
As a short term workaround, either of the following should workaround the issue until a patch can be issued:
- Use either
gh copilot suggest
orgh copilot explain
and opt in or out of sending anonymized telemetry - Use
gh copilot config
to opt in or out of sending anonymized telemetry
similar problem
zsh 5.9 (x86_64-apple-darwin23.0) on Sonoma 14.4.
I add
echo 'eval "$(gh copilot alias -- zsh)"' >> ~/.zshrc
to my .zshrc
file, then
source ~/.zshrc
/Users/myname/.zshrc:export:155: not valid in this context: ghcs() {\n\tFUNCNAME
I have open anonymized telemetry