During the process of porting __git_ps1 to Fish (see my previous email), I ran
into lots of issues (both design issues and missing functionality) with Fish
scripting. I've already filed issues for a lot of these, but I thought I would
just try to round them all up. These are in no particular order:

1. Fish seriously needs some facility for doing basic string manipulation.
Farming out to other processes is rather slow and complicated. In fact, when I
needed to replicate bash's functionality for "${somevar#strip/prefix}", it
turned out the easiest way to do that was in fact to use bash again, with
(/bin/sh -c 'echo ${1#strip/prefix}' -- $somevar). Farming out to other programs
to do work, as slow as it is, is at least understandable, but having to actually
farm out to bash itself seems completely wrongheaded.

2. Fish could really use an equivalent for bash's ${var:-value} syntax. It's
very awkward to turn what could be one expression into 4 lines is rather
awkward. And in fact in my __fish_git_prompt script, the lack of this
functionality ballooned into a lot more work because I didn't want to insert
those 4 lines everywhere I needed the simple characters. See the
__fish_git_prompt_validate_chars function from my __fish_git_prompt.fish script,
along with the extra event handler to invalidate those variables. This
functionality could have been used to simplify the color variable logic as well.

3. Fish needs a way to do command substitution within a double-quoted string.
The simplest solution is probably to support $() within double-quotes. The
reasoning is twofold: first, a command substitution that evaluates to no output
ends up being stripped entirely from the argument list of its surrounding
command. This has extremely bad implications when using it with, e.g. `test -n
(some command)`. Second, this would allow for storing the output with its
newlines in a variable, instead of having the output be split into multiple
elements. And as a bonus it would make it a lot easier to combine command
substitution output with other text in the same argument, e.g. "$somevar"(some
command)"$anothervar".

4. Fish needs basic math. Farming math out to `bc` is extremely slow.

5. Fish needs a way to do string testing with pattern matching, e.g. the ==
operator from bash's [[ builtin.

6. We need 'else if'. I can't figure out why that was omitted.

7. A command substitution should be allowed to modify the $status of its
surrounding context. It's currently documented as not touching $status, although
this documentation is fairly unnecessary because if it did modify $status, that
would simply be overwritten by the status of the command that it's being passed
as an argument to. However, once command substitution can modify $status, then
the next step is to modify the `set` builtin to not modify $status unless the
`-q` flag was provided. With both of these changes, I can then store the command
output into a variable and act on its status. In bash, this is trivial:

        if foo="$(some command)"; then
                # the command substitution exited 0
        fi

In Fish, I'd really like to be able to say

        if set foo (some command)
                # the command substitution exited 0
        end

Instead I have to use the awkward construct

        set -l oldStatus
        set foo (some command; set oldStatus $status)
        if test $oldStatus -ne 0
                # the command substitution exited 0
        end

-Kevin


------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to