feat: add zsh init script

This commit is contained in:
Jan De Dobbeleer 2020-12-23 13:00:50 +01:00 committed by Jan De Dobbeleer
parent d78d5da148
commit 1b5263e48e
3 changed files with 45 additions and 38 deletions

View file

@ -237,47 +237,13 @@ Once added, reload your profile for the changes to take effect.
Add the following to `~/.zshrc`: Add the following to `~/.zshrc`:
```bash ```zshrc
function omp_preexec() { eval "$(oh-my-posh --init --shell zsh --config ~/.poshthemes/jandedobbeleer.omp.json)"
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
``` ```
Once added, reload your profile for the changes to take effect. Once added, reload your profile for the changes to take effect.
```shell ```zsh
source ~/.zshrc source ~/.zshrc
``` ```

37
init/omp.zsh Normal file
View file

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

View file

@ -149,6 +149,8 @@ func initShell(shell, config string) string {
switch shell { switch shell {
case pwsh: case pwsh:
return fmt.Sprintf("Invoke-Expression (@(&\"%s\" --print-init --shell pwsh --config %s) -join \"`n\")", executable, config) return fmt.Sprintf("Invoke-Expression (@(&\"%s\" --print-init --shell pwsh --config %s) -join \"`n\")", executable, config)
case zsh:
return printShellInit(shell, config)
default: default:
return fmt.Sprintf("echo \"No initialization script available for %s\"", shell) return fmt.Sprintf("echo \"No initialization script available for %s\"", shell)
} }
@ -161,7 +163,9 @@ func printShellInit(shell, config string) string {
} }
switch shell { switch shell {
case pwsh: 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: default:
return fmt.Sprintf("echo \"No initialization script available for %s\"", shell) return fmt.Sprintf("echo \"No initialization script available for %s\"", shell)
} }