Skip to content
Open

tf 3 #18

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions thefuck_3/tests/shells/test_fish.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,5 @@ def test_how_to_configure_when_config_not_found(self, shell,
assert not shell.how_to_configure().can_configure_automatically

def test_info(self, shell, Popen):
Popen.return_value.stdout.read.side_effect = [b'fish, version 3.5.9\n']
Popen.return_value.stdout.read.side_effect = [b'3.5.9']
assert shell.info() == 'Fish Shell 3.5.9'
assert Popen.call_args[0][0] == ['fish', '--version']
4 changes: 2 additions & 2 deletions thefuck_3/thefuck/shells/fish.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ def how_to_configure(self):

def info(self):
"""Returns the name and version of the current shell"""
proc = Popen(['fish', '--version'],
proc = Popen(['fish', '-c', 'echo $FISH_VERSION'],
stdout=PIPE, stderr=DEVNULL)
version = proc.stdout.read().decode('utf-8').split()[-1]
version = proc.stdout.read().decode('utf-8').strip()
return u'Fish Shell {}'.format(version)
Comment on lines +108 to 111
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

LGTM! Cleaner approach to version retrieval.

The change from fish --version to fish -c 'echo $FISH_VERSION' is more direct and eliminates the need for output parsing. This should be more reliable and efficient.

Please verify that the $FISH_VERSION environment variable is available across all supported Fish shell versions:


🏁 Script executed:

#!/bin/bash
# Verify Fish shell version variable availability
echo "Testing Fish shell version retrieval methods"
echo "Method 1 (new): fish -c 'echo \$FISH_VERSION'"
fish -c 'echo $FISH_VERSION' 2>/dev/null || echo "Failed"
echo "Method 2 (old): fish --version"
fish --version 2>/dev/null || echo "Failed"

Length of output: 364


Ensure reliable fish version retrieval with --no-config and fallback

Using fish -c 'echo $FISH_VERSION' can load users’ config.fish (producing unexpected output) and may not set $FISH_VERSION in non-interactive or older shells. Please adjust the implementation to:

  • Invoke fish with --no-config to skip ~/.config/fish/config.fish.
  • Fall back to the legacy --version flag when $FISH_VERSION is empty.

Suggested diff:

--- a/thefuck_3/thefuck/shells/fish.py
+++ b/thefuck_3/thefuck/shells/fish.py
@@ -108,7 +108,13 @@ class Fish(Shell):
-        proc = Popen(['fish', '-c', 'echo $FISH_VERSION'],
-                     stdout=PIPE, stderr=DEVNULL)
+        # Skip user config to avoid loading any custom prompts or scripts
+        proc = Popen(
+            ['fish', '--no-config', '-c', 'echo $FISH_VERSION'],
+            stdout=PIPE, stderr=DEVNULL
+        )
+        version = proc.stdout.read().decode('utf-8').strip()
+        # Fallback if FISH_VERSION is empty or unsupported
+        if not version:
+            proc = Popen(['fish', '--no-config', '--version'], stdout=PIPE, stderr=DEVNULL)
+            version = proc.stdout.read().decode('utf-8').strip()
+        return u'Fish Shell {}'.format(version)

This ensures consistency across environments and provides a safe fallback.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
proc = Popen(['fish', '-c', 'echo $FISH_VERSION'],
stdout=PIPE, stderr=DEVNULL)
version = proc.stdout.read().decode('utf-8').split()[-1]
version = proc.stdout.read().decode('utf-8').strip()
return u'Fish Shell {}'.format(version)
# Skip user config to avoid loading any custom prompts or scripts
proc = Popen(
['fish', '--no-config', '-c', 'echo $FISH_VERSION'],
stdout=PIPE, stderr=DEVNULL
)
version = proc.stdout.read().decode('utf-8').strip()
# Fallback if FISH_VERSION is empty or unsupported
if not version:
proc = Popen(
['fish', '--no-config', '--version'],
stdout=PIPE, stderr=DEVNULL
)
version = proc.stdout.read().decode('utf-8').strip()
return u'Fish Shell {}'.format(version)
🤖 Prompt for AI Agents
In thefuck_3/thefuck/shells/fish.py around lines 108 to 111, update the fish
version retrieval to invoke fish with the --no-config flag to avoid loading user
config files that may produce unexpected output. After reading $FISH_VERSION,
check if it is empty; if so, fall back to running fish --version to get the
version string. This ensures consistent and reliable version detection across
different fish shell versions and environments.


def put_to_history(self, command):
Expand Down