2Z7DEYRKYS5DMQMFIVYGJMKXZRSRPJZHELW4PD3GOOZYGZFEI46QC
function pyactivate --description 'activate a pyenv virtualenv by name'
set VENV_NAME
for arg in $argv
switch $arg
case --help
echo 'USAGE:'
echo " pyactivate [venv_name] activate a pyenv-virtualenv by name"
echo ' pyactivate ls list available pyenv-virtualenvs'
echo
echo ' options:'
echo ' --help display this message'
return 0
case ls list
pyenv versions
return 0
case '--*'
error_message --warn --bold "$arg is an unrecognized flag"
return 9
case '*'
if test -n $VENV_NAME
set VENV_NAME $arg
end
end
end
if not test -n "$VENV_NAME"
error_message --alert 'virtual environment name is a required arguemnt'
return 1
else
if echo (pyenv versions) | grep -qw "$VENV_NAME"
set VENV_DIR "$PYENV_ROOT/versions/$VENV_NAME"
source $VENV_DIR/bin/activate.fish
else
error_message 'virtual env does not exist'
return 2
end
end
end
function error_message
set ERR_STRING
set RING_ALERT_BELL False
set BOLD_OUTPUT False
set ERR_COLOR 'red'
set NO_COLOR False
for arg in $argv
switch $arg
case --alert -a
set RING_ALERT_BELL True
case --bold -b
set BOLD_OUTPUT True
case --warn -w
set ERR_COLOR 'yellow'
case --no-color
set NO_COLOR True
case '*'
set ERR_STRING $ERR_STRING $arg
end
end
set ERR_MSG $ERR_STRING
if not eval $NO_COLOR
set COLOR_FLAGS "--color-$ERR_COLOR"
if eval $BOLD_OUTPUT
set COLOR_FLAGS '--bold' $COLOR_FLAGS
end
set ERR_MSG (colorize $COLOR_FLAGS $ERR_STRING)
end
echo "$ERR_MSG" > /dev/stderr
if eval $RING_ALERT_BELL
echo -ne '\a'
end
end
function colorize
set STRING
set COLOR $normal
set BOLD_OUTPUT False
for arg in $argv
# echo 'arg' $arg
# echo
switch $arg
case ls list
set_color -c
case --bold -b
set BOLD_OUTPUT True
case '--color-*'
set COLOR (echo $arg | rg '(\-\-color\-)(\w+)' --replace '$2')
case '*'
set STRING $STRING $arg
end
end
if echo (set_color -c) | grep -qw "$COLOR"
set COLOR_ESC_SEQ (set_color $COLOR)
if eval $BOLD_OUTPUT
set COLOR_ESC_SEQ (set_color -o $COLOR)
end
echo $COLOR_ESC_SEQ $STRING (set_color $normal)
else
error_message "$COLOR is not an available color"
end
end