Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: zsh hangs forever after setting up aliases #40

Closed
masewo opened this issue Mar 21, 2024 · 10 comments
Closed

[BUG]: zsh hangs forever after setting up aliases #40

masewo opened this issue Mar 21, 2024 · 10 comments
Assignees
Labels
bug Something isn't working

Comments

@masewo
Copy link

masewo commented Mar 21, 2024

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 masewo added bug Something isn't working needs-triage needs to be reviewed labels Mar 21, 2024
@andyfeller
Copy link
Contributor

@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 andyfeller removed the needs-triage needs to be reviewed label Mar 21, 2024
@andyfeller andyfeller self-assigned this Mar 21, 2024
@masewo
Copy link
Author

masewo commented Mar 21, 2024

@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?

@your-diary
Copy link

@masewo

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

@masewo
Copy link
Author

masewo commented Mar 22, 2024

@your-diary Thanks. I mean how can the setting be reverted to "unset"? Maybe deleting some internal config file?

@your-diary
Copy link

@masewo

$ cat ~/.config/gh-copilot/config.yml #Check the content before removing it.
$ rm ~/.config/gh-copilot/config.yml

@masewo
Copy link
Author

masewo commented Mar 22, 2024

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.

@andyfeller
Copy link
Contributor

andyfeller commented Mar 22, 2024

@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:

  1. Use either gh copilot suggest or gh copilot explain and opt in or out of sending anonymized telemetry
  2. Use gh copilot config to opt in or out of sending anonymized telemetry

@RealKai42
Copy link

RealKai42 commented Mar 26, 2024

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

@PhoenixmitX
Copy link

This also happens in bash, when you run eval "$(gh copilot alias -- bash)" it freezes the shell without any hint why. After debugging my .bashrc I found out it was this command.

If you press the down (or up) arrow key before pressing Strl+C, it will execute the `yes' command, which spams the letter y into the console....
otherwise it will just give you two cryptic error messages:

command ? not found
command No not found.

If you need this telemetry check, please generate valid bash code like

echo aliases not generated, please ...

@BagToad
Copy link

BagToad commented Sep 12, 2024

👋 @masewo thank you again for opening this issue and letting us know about this experience. I apologize for the delay getting to it!

This is now fixed in v1.0.5 where we no longer prompt for metrics opt-in for gh copilot alias.

@BagToad BagToad closed this as completed Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants