这是indexloc提供的服务,不要输入任何密码
Skip to content

Preserve shebang and comments #28

@Neved4

Description

@Neved4

If the input contains a #!/bin/sh shebang, it currently outputs as #!/bin/sh, this populates fish scripts with the wrong shebangs. It'd be great if we could use #!/usr/bin/env fish instead.

In fish, shebangs are not strictly necessary in many scenarios:

The shebang line is only used when scripts are executed without specifying the interpreter. For functions inside fish or when executing a script with fish /path/to/script, a shebang is not required (but it doesn’t hurt!).
— See Introduction — Shebang Line — fish-shell documentation

Ideally, we'd only emit #!/usr/bin/env fish if the first line is a valid shebang (#!/bin/sh, #!/bin/bash, #!/usr/bin/env bash, etc.), and not emit said shebang if the input lacks one. Additionally, we could preserve the empty line after the shebang.

Examples

Currently, a file:

#!/bin/sh
f() {
    echo 'This is the f function'
}

Will emit:

#!/bin/sh
function f
    echo 'This is the f function'
end

Instead of the desired:

#!/usr/bin/env fish

function f
    echo 'This is the f function'
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions