Skip to content

Commit

Permalink
feat: option to disable status emoji
Browse files Browse the repository at this point in the history
Currently, a status emoji is being displayed in the right prompt of
shell. If you have customised your right prompt you may want to disable
the status emoji.

Closes: #64
  • Loading branch information
Realiserad committed Oct 12, 2024
1 parent 389b24d commit f49146b
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 30 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,19 @@ history_size = 5
If you enable this option, consider the use of [`sponge`](https://github.com/meaningful-ooo/sponge)
to automatically remove broken commands from your commandline history.

### Disable the status emoji

By default, a status emoji is shown in the [right prompt](https://fishshell.com/docs/current/cmds/fish_right_prompt.html).
If you already use your right prompt for something else, or just don't like
emojis, you can disable them:

```ini
[fish-ai]
status_emoji = False
```

Restart any open terminal windows for the change to take effect.

## 🎭 Switch between contexts

You can switch between different sections in the configuration using the
Expand Down
4 changes: 2 additions & 2 deletions conf.d/fish_ai.fish
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ bind \cP _fish_ai_codify_or_explain
bind -k nul _fish_ai_autocomplete_or_fix

##
## This section contains functionality for setting and clearing the status shown
## in the right prompt.
## This section contains functionality for clearing the status emoji
## shown in the right prompt.
##
bind \r 'clear_status; commandline -f execute'
bind \cc 'clear_status; commandline -f repaint; commandline -f cancel-commandline'
Expand Down
6 changes: 5 additions & 1 deletion functions/_fish_ai_autocomplete.fish
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/usr/bin/env fish

function _fish_ai_autocomplete --description "Autocomplete the current command using AI." --argument-names command cursor_position
set selected_completion (~/.fish-ai/bin/autocomplete "$command" "$cursor_position" 2> /dev/null)
if test (~/.fish-ai/bin/lookup_setting "debug") = True
set selected_completion (~/.fish-ai/bin/autocomplete "$command" "$cursor_position")
else
set selected_completion (~/.fish-ai/bin/autocomplete "$command" "$cursor_position" 2> /dev/null)
end
echo -n "$selected_completion"
end
4 changes: 2 additions & 2 deletions functions/_fish_ai_autocomplete_or_fix.fish
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env fish

function fish_right_prompt
echo "$status_emoji"
if test (~/.fish-ai/bin/lookup_setting status_emoji) != False
eval "function fish_right_prompt; echo (string escape \$status_emoji); end"
end

function _fish_ai_autocomplete_or_fix --description "Autocomplete the current command or fix the previous command using AI."
Expand Down
6 changes: 5 additions & 1 deletion functions/_fish_ai_codify.fish
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/usr/bin/env fish

function _fish_ai_codify --description "Turn a comment into a command using AI." --argument-names comment
set output (~/.fish-ai/bin/codify "$comment" 2> /dev/null)
if test (~/.fish-ai/bin/lookup_setting "debug") = True
set output (~/.fish-ai/bin/codify "$comment")
else
set output (~/.fish-ai/bin/codify "$comment" 2> /dev/null)
end
echo -n "$output"
end
4 changes: 2 additions & 2 deletions functions/_fish_ai_codify_or_explain.fish
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env fish

function fish_right_prompt
echo "$status_emoji"
if test (~/.fish-ai/bin/lookup_setting status_emoji) != False
eval "function fish_right_prompt; echo (string escape \$status_emoji); end"
end

function _fish_ai_codify_or_explain --description "Transform a command into a comment and vice versa using AI."
Expand Down
6 changes: 5 additions & 1 deletion functions/_fish_ai_explain.fish
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/usr/bin/env fish

function _fish_ai_explain --description "Turn a command into a comment using AI." --argument-names command
set output (~/.fish-ai/bin/explain "$command" 2> /dev/null)
if test (~/.fish-ai/bin/lookup_setting "debug") = True
set output (~/.fish-ai/bin/explain "$command")
else
set output (~/.fish-ai/bin/explain "$command" 2> /dev/null)
end
echo -n "$output"
end
6 changes: 5 additions & 1 deletion functions/_fish_ai_fix.fish
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
#!/usr/bin/env fish

function _fish_ai_fix --description "Fix a command using AI." --argument-names previous_command
set output (~/.fish-ai/bin/fix "$previous_command" 2> /dev/null)
if test (~/.fish-ai/bin/lookup_setting "debug") = True
set output (~/.fish-ai/bin/fix "$previous_command")
else
set output (~/.fish-ai/bin/fix "$previous_command" 2> /dev/null)
end
echo -n "$output"
end
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "fish_ai"
version = "0.10.2"
version = "0.11.0"
authors = [{ name = "Bastian Fredriksson", email = "realiserad@gmail.com" }]
description = "Provides core functionality for fish-ai, an AI plugin for the fish shell."
readme = "README.md"
Expand Down Expand Up @@ -35,6 +35,7 @@ codify = "fish_ai.codify:codify"
explain = "fish_ai.explain:explain"
autocomplete = "fish_ai.autocomplete:autocomplete"
switch_context = "fish_ai.switch_context:switch_context"
lookup_setting = "fish_ai.config:lookup_setting"

[tool.pytest.ini_options]
minversion = "6.0"
Expand Down
25 changes: 25 additions & 0 deletions src/fish_ai/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
from os import path
import sys
from configparser import ConfigParser

config = ConfigParser()
config.read(path.expanduser('~/.config/fish-ai.ini'))


def lookup_setting():
print(get_config(sys.argv[1] or ''))


def get_config(key):
if not config.has_section('fish-ai'):
# There is no configuration file or the user made a mistake.
# Just return 'None' here to simplify testing.
return None

active_section = config.get(section='fish-ai', option='configuration')

if config.has_option(section=active_section, option=key):
return config.get(section=active_section, option=key)

return config.get(section='fish-ai', option=key, fallback=None)
21 changes: 2 additions & 19 deletions src/fish_ai/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from openai import AzureOpenAI
import google.generativeai as genai
from google.generativeai.types import GenerationConfig
from configparser import ConfigParser
from os import path
from os.path import isfile
import platform
import logging
Expand All @@ -21,9 +19,8 @@
import itertools
from azure.ai.inference import ChatCompletionsClient
from azure.core.credentials import AzureKeyCredential

config = ConfigParser()
config.read(path.expanduser('~/.config/fish-ai.ini'))
from fish_ai.config import get_config
from os import path


def get_args():
Expand Down Expand Up @@ -127,20 +124,6 @@ def get_system_prompt():
}


def get_config(key):
if not config.has_section('fish-ai'):
# There is no configuration file or the user made a mistake.
# Just return 'None' here to simplify testing.
return None

active_section = config.get(section='fish-ai', option='configuration')

if config.has_option(section=active_section, option=key):
return config.get(section=active_section, option=key)

return config.get(section='fish-ai', option=key, fallback=None)


def get_openai_client():
if (get_config('provider') == 'azure'):
return AzureOpenAI(
Expand Down

0 comments on commit f49146b

Please sign in to comment.