diff --git a/README.md b/README.md index ce1fcdf..f1d4ece 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,22 @@ ln -s "$ZSH_CUSTOM/themes/gokart-prompt/gokart.zsh-theme" "$ZSH_CUSTOM/themes/go Set `ZSH_THEME="gokart"` in your `.zshrc`. +
+Bash + +Download and extract the latest release: + +```shell +curl -fsSL https://github.com/LucaScorpion/gokart-prompt/releases/latest/download/gokart-prompt.tar.gz | tar xzvf - -C "$HOME" +``` + +Source `gokart.bash-theme` in your `.bashrc`: + +```shell +source "$HOME/gokart-prompt/gokart.bash-theme" +``` +
+ ## Requirements ✅ ### [Powerline](https://github.com/powerline/fonts) or [Nerd Font](https://www.nerdfonts.com) diff --git a/cmd/gokart.go b/cmd/gokart.go index f11dd51..e85b3fe 100644 --- a/cmd/gokart.go +++ b/cmd/gokart.go @@ -35,6 +35,9 @@ func ps1() { fmt.Print(git.Git()) fmt.Print(versions.All(wdFiles)) fmt.Print(ansi.Reset()) + + fmt.Println() + ps2() } func ps2() { diff --git a/gokart.bash-theme b/gokart.bash-theme new file mode 100644 index 0000000..3d9ec45 --- /dev/null +++ b/gokart.bash-theme @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +GOKART_PROMPT_DIR="$(realpath "$(dirname "${BASH_SOURCE[0]}")")" + +gokart_prompt_precmd() { + export EXIT_CODE=$? + export GOKART_SHELL=bash + + PS1=$("$GOKART_PROMPT_DIR/gokart" ps1) + PS2=$("$GOKART_PROMPT_DIR/gokart" ps2) +} + +gokart_prompt_setup() { + PROMPT_COMMAND=gokart_prompt_precmd +} + +gokart_prompt_setup diff --git a/gokart.zsh-theme b/gokart.zsh-theme old mode 100755 new mode 100644 index 589e122..a180f29 --- a/gokart.zsh-theme +++ b/gokart.zsh-theme @@ -1,16 +1,15 @@ #!/usr/bin/env zsh # Get the path to this file, make it absolute and strip the filename. -# See: https://stackoverflow.com/questions/9901210/bash-source0-equivalent-in-zsh/28336473#28336473 +# See: https://stackoverflow.com/questions/9901210/bash-source0-equivalent-in-zsh/28336473#28336473 GOKART_PROMPT_DIR=${${(%):-%x}:A:h} gokart_prompt_precmd() { export EXIT_CODE=$? + export GOKART_SHELL=zsh + PS1=$("$GOKART_PROMPT_DIR/gokart" ps1) PS2=$("$GOKART_PROMPT_DIR/gokart" ps2) - - local NEWLINE=$'\n' - PROMPT="${PS1}${NEWLINE}${PS2}" } gokart_prompt_setup() { diff --git a/internal/ansi/ansi.go b/internal/ansi/ansi.go index 7584427..ebeace7 100644 --- a/internal/ansi/ansi.go +++ b/internal/ansi/ansi.go @@ -1,16 +1,29 @@ package ansi +import "os" + const esc = "\x1B" const reset = "0" // See: https://stackoverflow.com/a/19731390/2831123 -const zeroWidthStart = "%{" -const zeroWidthEnd = "%}" +const zshZeroWidthStart = "%{" +const zshZeroWidthEnd = "%}" + +// See: https://unix.stackexchange.com/a/504152/176402 +const bashZeroWidthStart = "\x01" +const bashZeroWidthEnd = "\x02" func mode(mode string) string { - return zeroWidthStart + esc + "[" + mode + "m" + zeroWidthEnd + return zeroWidth(esc + "[" + mode + "m") } func Reset() string { return mode(reset) } + +func zeroWidth(s string) string { + if os.Getenv("GOKART_SHELL") == "zsh" { + return zshZeroWidthStart + s + zshZeroWidthEnd + } + return bashZeroWidthStart + s + bashZeroWidthEnd +}