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

ubuntu 1804 with zsh shows "sh: 8: [[: not found" #57

Closed
spin6lock opened this issue Aug 7, 2018 · 12 comments
Closed

ubuntu 1804 with zsh shows "sh: 8: [[: not found" #57

spin6lock opened this issue Aug 7, 2018 · 12 comments

Comments

@spin6lock
Copy link

Hi, I got "sh: 8: [[: not found" in branches section and top of the window. zsh version zsh 5.4.2 (x86_64-ubuntu-linux-gnu). lazygit is on b80e811. How can I fix that error?

@jesseduffield
Copy link
Owner

hmm, it shouldn't be showing that error like that anymore. It looks like you're up to date in terms of the lazygit repo. Could you try running go install github.com/jesseduffield/lazygit to build the latest version?

@SolitudeSF
Copy link

you shouldn't be using [[ bashism at all. its not posix.

@ph03
Copy link

ph03 commented Aug 7, 2018

Seeing same issue on f8ca0dd with ubuntu 1804 (using fish shell, not zsh, but bash doesn't work either).

@jesseduffield
Copy link
Owner

jesseduffield commented Aug 7, 2018

The culprit is this script here which gets your branches in reverse chronological order along with their relative last commit time.

set -e
git reflog -n100 --pretty='%cr|%gs' --grep-reflog='checkout: moving' HEAD | {
  seen=":"
  git_dir="$(git rev-parse --git-dir)"
  while read line; do
    date="${line%%|*}"
    branch="${line##* }"
    if ! [[ $seen == *:"${branch}":* ]]; then
      seen="${seen}${branch}:"
      if [ -f "${git_dir}/refs/heads/${branch}" ]; then
        printf "%s\t%s\n" "$date" "$branch"
      fi
    fi
  done \
  | sed 's/ months /m /g' \
  | sed 's/ month /m /g' \
  | sed 's/ days /d /g' \
  | sed 's/ day /d /g' \
  | sed 's/ weeks /w /g' \
  | sed 's/ week /w /g' \
  | sed 's/ hours /h /g' \
  | sed 's/ hour /h /g' \
  | sed 's/ minutes /m /g' \
  | sed 's/ minute /m /g' \
  | sed 's/ seconds /s /g' \
  | sed 's/ second /s /g' \
  | sed 's/ago//g' \
  | tr -d ' '
}

example output:
19h	feature/better-file-opening
65m	master
65m	feature/use-dep
3h	hotfix/windows-support
5h	feature/fetching-without-checking-out
2w	develop
24h	feature/gpgsign-support
23h	feature/no-panic-on-git-commit-error
9h	hotfix/latency
30h	feature/refactor-directory-structure
26h	feature/better-contrast
2d	feature/set-upstream-on-push
2d	feature/testing-setting-upstream
2d	feature/tutorial6

It's probably the weakest part of the codebase, not the least because it hasn't been written in go. If anybody can put up a PR that cleans this guy up or refactors it out into just git commands and Go, I would very much appreciate it! I'll spend some time right now seeing if I can refactor it

@tswsl1989
Copy link

tswsl1989 commented Aug 7, 2018

The following patch seems to have been enough to get the software up and running for me, should anyone want a stopgap until a proper fix is available:

diff --git a/gitcommands.go b/gitcommands.go
index 50c1f2a..63d2ffa 100644
--- a/gitcommands.go
+++ b/gitcommands.go
@@ -116,7 +116,7 @@ func platformShell() (string, string) {
        if runtime.GOOS == "windows" {
                return "cmd", "/c"
        }
-       return "sh", "-c"
+       return "bash", "-c"
 }

 func runDirectCommand(command string) (string, error) {

@jesseduffield
Copy link
Owner

jesseduffield commented Aug 7, 2018

thanks @tswsl1989 :) I switched to sh thinking it would increase compatibility but it seems it's had the opposite effect! I've added that change to the PR that should fix the underlying issue here #60
Feel free to give it a review

@perror
Copy link

perror commented Aug 7, 2018

Beware, the go installer still install the buggy version (I tried a few minutes ago).

And, going to sh do improve portability (especially on plate-forms that do not have bash by default), but you have to care about the fact that all your shell commands are POSIX compliant (these [[ in place of test have to be avoided).

@jesseduffield
Copy link
Owner

@perror I just merged the PR to master, that ugly bash script is now out of the codebase. Let me know if there are still any issues

@perror
Copy link

perror commented Aug 7, 2018

It works like a charm now! :) Just did a go get -u lazygit and it was enough.
Thanks!

@SolitudeSF
Copy link

SolitudeSF commented Aug 7, 2018

you should revert to using sh instead of bash, unless you want to have hard dependency on bash. and from i can see you only use it as a command launcher so its redundant anyway.

@dawidd6
Copy link
Collaborator

dawidd6 commented Aug 7, 2018

This issue seems to be resolved, tested on 16.04 after this referenced pull request merge.

@spin6lock
Copy link
Author

problem solved after update to latest version:) Thanks @jesseduffield !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants