Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

need a way to encode strings to valid var names or URLs #4150

krader1961 opened this issue Jun 20, 2017 · 0 comments

need a way to encode strings to valid var names or URLs #4150

krader1961 opened this issue Jun 20, 2017 · 0 comments


Copy link

One way to reimplement how abbreviations are stored requires a method to convert arbitrary strings to/from valid var names. See issue #4048. This need also recently arose in the context of git completions. See issue #4147. It turns out that converting strings to valid var names is only moderately difficult using fish script:

function encode_to_var
    set -l orig_str "$argv"
    set -l new_str ''
    for letter in (string split '' $orig_str)
        if string match -qr '\w' -- $letter
            if test $letter = '_'
                set new_str {$new_str}__
                set new_str "$new_str$letter"
            echo -n $letter | begin
                set -lx LC_ALL C
                read -lz utf8
                # string split '' -- $utf8 | od -tx1x >&2
                printf '_%02X' \'(string split '' -- $utf8)
            end | read letter
            set new_str {$new_str}$letter
    echo $new_str

Unfortunately that is ugly and slow. Doing the inverse operation in fish script will also be extremely difficult. So this issue is to track augmenting the string escape builtin by adding a --style=xxx flag. Where xxx would be var or url. The latter would allow us to eliminate the __fish_urlencode function. For completeness we would also allow the style to be script to explicitly request the current default behavior.

Note that we'll also need a string unescape that also supports the --style=xxx flag. But we'll do that work under issue #3543 since we don't currently have that string subcommand.

@krader1961 krader1961 added this to the fish 2.7.0 milestone Jun 20, 2017
@krader1961 krader1961 self-assigned this Jun 20, 2017
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 17, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet

No branches or pull requests

1 participant