Skip to content

Conversation

@clappedscant906
Copy link

Pull Request: Add shelldash Option to Disable -- Appending in Shell Commands

Summary

This PR adds a new shelldash option to control whether lf appends -- to shell command arguments. This fixes compatibility issues with shells like nushell that do not support the -- argument separator in the same way as traditional POSIX shells.

Problem Description

lf currently unconditionally appends -- to shell command arguments on Unix/Linux systems to prevent arguments from being interpreted as shell options. While this works correctly for POSIX-compliant shells (sh, bash, zsh), it causes errors with nushell.

Example Error with Nushell

lfrc configuration:

set shell nu
set shellflag "-c"
cmd open $echo test

Error when invoking the command:

Error: nu::parser::unknown_flag
× The `nu` command doesn't have flag named empty.
╭─[source:2:3]
" -- nu -c "echo test
·                   ─┬
·                    ╰── unknown flag
╰────
help: Use `--help` to see available flags

The issue is that nushell interprets the -- as a flag (or incorrectly parses it), whereas traditional shells use -- as a standard end-of-options marker.

Solution

Added a new boolean option shelldash that defaults to true (preserving current behavior for existing users). Users working with nushell or other incompatible shells can now disable the -- appending.

After Fix - Working Configuration

set shell nu
set shelldash false
set shellflag "-c"

cmd open $print test; input

This configuration now works correctly - it prints "test" and waits for user input.

Changes Made

File Change
opts.go Added shelldash bool field to gOpts struct
opts.go Set default value gOpts.shelldash = true in init()
eval.go Added option parsing for shelldash, noshelldash, shelldash!
os.go Modified shellCommand() to conditionally append -- based on gOpts.shelldash

Key Implementation Detail

Before (os.go):

args = append([]string{gOpts.shellflag, s, "--"}, args...)

After (os.go):

if gOpts.shelldash {
    args = append([]string{gOpts.shellflag, s, "--"}, args...)
} else {
    args = append([]string{gOpts.shellflag, s}, args...)
}

Usage

Users can control the behavior in their lfrc:

# Default behavior (append --)
set shelldash

# Disable the -- appending (for nushell, etc.)
set noshelldash
# or
set shelldash false

# Toggle with !
set shelldash!

Backward Compatibility

  • The option defaults to true, so existing configurations continue to work unchanged
  • No breaking changes to the API or existing behavior

Testing Environment

  • lf version: r40
  • nushell version: 0.109.1

Checklist

  • Default behavior unchanged (-- is still appended by default)
  • set shelldash enables -- appending
  • set noshelldash disables -- appending
  • set shelldash! toggles the behavior
  • Tested with nushell (the primary use case)
  • Verified compatibility with POSIX shells (sh, bash)

@CatsDeservePets
Copy link
Collaborator

CatsDeservePets commented Jan 2, 2026

So this is basically aims to fix

There has been an attempt to solve this problem, however the PR was never finished

I honestly do prefer the approach suggested by @joelim-work in the original issue as it seems more flexible and potentially also useful for other shells.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants