fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Johannes AltmanningerRemove some redundant translation sources6eaad2cd8

master
1.4 KiB45 linesraw
1# localization: tier1
2function setenv
3    # No arguments should cause the current env vars to be displayed.
4    if not set -q argv[1]
5        env
6        return
7    end
8
9    # A single argument should set the named var to nothing.
10    if not set -q argv[2]
11        set -gx $argv[1] ''
12        return
13    end
14
15    # `setenv` accepts only two arguments: the var name and the value. If there are more than two
16    # args it is an error. The error message is verbatim from csh.
17    if set -q argv[3]
18        {
19            printf (_ '%s: Too many arguments') setenv
20            echo
21        } >&2
22        return 1
23    end
24
25    # We have exactly two arguments as required by the csh `setenv` command.
26    set -l var $argv[1]
27    set -l val $argv[2]
28
29    # Validate the variable name.
30    if not string match -qr '^\w+$' -- $var
31        # This message is verbatim from csh. We don't really need to do this but if we don't fish
32        # will display a different error message which might confuse someone expecting the csh
33        # message.
34        echo "setenv: Variable name must contain alphanumeric characters" >&2
35        return 1
36    end
37
38    # We need to special case some vars to be compatible with fish. In particular how they are
39    # treated as arrays split on colon characters. All other var values are treated literally.
40    if contains -- $var PATH CDPATH MANPATH
41        set -gx $var (string split -- ':' $val)
42    else
43        set -gx $var $val
44    end
45end