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
}
const (
zsh = "zsh"
bash = "bash"
pwsh = "pwsh"
powershell5 = "powershell"
)
func (r *AnsiRenderer) init(shell string) {
r.shell = shell
r.formats = &formats{}

View file

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

View file

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