fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
6eaad2cd8
master
1# localization: tier1 2function setenv 3# No arguments should cause the current env vars to be displayed. 4if not set -q argv[ 1 ] 5env 6return 7end 8 9# A single argument should set the named var to nothing. 10if not set -q argv[ 2 ] 11set -gx$argv [ 1 ] '' 12return 13end 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. 17if set -q argv[ 3 ] 18{ 19 printf( _ '%s: Too many arguments' ) setenv 20echo 21} >&2 22return 1 23end 24 25# We have exactly two arguments as required by the csh `setenv` command. 26set -l var$argv [ 1 ] 27set -l val$argv [ 2 ] 28 29# Validate the variable name. 30if 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. 34echo "setenv: Variable name must contain alphanumeric characters" >&2 35return 1 36end 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. 40if contains --$var PATH CDPATH MANPATH 41set -gx$var ( string split --':' $val ) 42else 43set -gx$var $val 44end 45end