diff --git a/docs/docs/installation.mdx b/docs/docs/installation.mdx index 2a8561a8..aa00f6c3 100644 --- a/docs/docs/installation.mdx +++ b/docs/docs/installation.mdx @@ -237,47 +237,13 @@ Once added, reload your profile for the changes to take effect. Add the following to `~/.zshrc`: -```bash -function omp_preexec() { - omp_start_time=$(oh-my-posh --millis) -} - -function omp_precmd() { - omp_elapsed=-1 - if [ $omp_start_time ]; then - omp_now=$(oh-my-posh --millis) - omp_elapsed=$(($omp_now-$omp_start_time)) - fi - eval "$(oh-my-posh --config ~/.poshthemes/jandedobbeleer.omp.json --error $? --execution-time $omp_elapsed --eval)" - unset omp_start_time - unset omp_now - unset omp_elapsed -} - -function install_omp_hooks() { - for s in "${preexec_functions[@]}"; do - if [ "$s" = "omp_preexec" ]; then - return - fi - done - preexec_functions+=(omp_preexec) - - for s in "${precmd_functions[@]}"; do - if [ "$s" = "omp_precmd" ]; then - return - fi - done - precmd_functions+=(omp_precmd) -} - -if [ "$TERM" != "linux" ]; then - install_omp_hooks -fi +```zshrc +eval "$(oh-my-posh --init --shell zsh --config ~/.poshthemes/jandedobbeleer.omp.json)" ``` Once added, reload your profile for the changes to take effect. -```shell +```zsh source ~/.zshrc ``` diff --git a/init/omp.zsh b/init/omp.zsh new file mode 100644 index 00000000..033029d9 --- /dev/null +++ b/init/omp.zsh @@ -0,0 +1,37 @@ +export POSH_THEME=::CONFIG:: + +function omp_preexec() { + omp_start_time=$(::OMP:: --millis) +} + +function omp_precmd() { + omp_elapsed=-1 + if [ $omp_start_time ]; then + omp_now=$(::OMP:: --millis) + omp_elapsed=$(($omp_now-$omp_start_time)) + fi + eval "$(::OMP:: --config $POSH_THEME --error $? --execution-time $omp_elapsed --eval)" + unset omp_start_time + unset omp_now + unset omp_elapsed +} + +function install_omp_hooks() { + for s in "${preexec_functions[@]}"; do + if [ "$s" = "omp_preexec" ]; then + return + fi + done + preexec_functions+=(omp_preexec) + + for s in "${precmd_functions[@]}"; do + if [ "$s" = "omp_precmd" ]; then + return + fi + done + precmd_functions+=(omp_precmd) +} + +if [ "$TERM" != "linux" ]; then + install_omp_hooks +fi diff --git a/main.go b/main.go index a9cb6412..015559fa 100644 --- a/main.go +++ b/main.go @@ -149,6 +149,8 @@ func initShell(shell, config string) string { switch shell { case pwsh: return fmt.Sprintf("Invoke-Expression (@(&\"%s\" --print-init --shell pwsh --config %s) -join \"`n\")", executable, config) + case zsh: + return printShellInit(shell, config) default: return fmt.Sprintf("echo \"No initialization script available for %s\"", shell) } @@ -161,7 +163,9 @@ func printShellInit(shell, config string) string { } switch shell { case pwsh: - return getShellInitScript(executable, config, "init/pwsh.ps1") + return getShellInitScript(executable, config, "init/omp.ps1") + case zsh: + return getShellInitScript(executable, config, "init/omp.zsh") default: return fmt.Sprintf("echo \"No initialization script available for %s\"", shell) }