feat: add fish init script

This commit is contained in:
Jan De Dobbeleer 2020-12-23 13:48:14 +01:00 committed by Jan De Dobbeleer
parent eb42e0c93a
commit 1676d839af
4 changed files with 16 additions and 14 deletions

View file

@ -47,13 +47,6 @@ type AnsiRenderer struct {
shell string shell string
} }
const (
zsh = "zsh"
bash = "bash"
pwsh = "pwsh"
powershell5 = "powershell"
)
func (r *AnsiRenderer) init(shell string) { func (r *AnsiRenderer) init(shell string) {
r.shell = shell r.shell = shell
r.formats = &formats{} r.formats = &formats{}

View file

@ -273,15 +273,13 @@ Or, when using `~/.profile`.
Redefine `fish_prompt` in `~/.config/fish/config.fish`: Redefine `fish_prompt` in `~/.config/fish/config.fish`:
```bash ```fish
function fish_prompt oh-my-posh --init --shell fish --config ~/.poshthemes/jandedobbeleer.omp.json | source
eval oh-my-posh --config ~/.poshthemes/jandedobbeleer.omp.json --error $status --eval
end
``` ```
Once added, reload your config for the changes to take effect. Once added, reload your config for the changes to take effect.
```bash ```fish
. ~/.config/fish/config.fish . ~/.config/fish/config.fish
``` ```

4
init/omp.fish Normal file
View file

@ -0,0 +1,4 @@
function fish_prompt
set -l omp_duration "$CMD_DURATION$cmd_duration"
::OMP:: --config ::CONFIG:: --error $status --execution-time $omp_duration
end

11
main.go
View file

@ -14,7 +14,12 @@ import (
var Version = "development" var Version = "development"
const ( const (
noExe = "echo \"Unable to find Oh my Posh executable\"" noExe = "echo \"Unable to find Oh my Posh executable\""
zsh = "zsh"
bash = "bash"
pwsh = "pwsh"
fish = "fish"
powershell5 = "powershell"
) )
type args struct { type args struct {
@ -149,7 +154,7 @@ 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, bash: case zsh, bash, fish:
return printShellInit(shell, config) 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)
@ -168,6 +173,8 @@ func printShellInit(shell, config string) string {
return getShellInitScript(executable, config, "init/omp.zsh") return getShellInitScript(executable, config, "init/omp.zsh")
case bash: case bash:
return getShellInitScript(executable, config, "init/omp.bash") return getShellInitScript(executable, config, "init/omp.bash")
case fish:
return getShellInitScript(executable, config, "init/omp.fish")
default: default:
return fmt.Sprintf("echo \"No initialization script available for %s\"", shell) return fmt.Sprintf("echo \"No initialization script available for %s\"", shell)
} }