As said above in the comments, that is the best solution for this specific use case. But to answer the question in case someone wants to do something else.
You are right about contains
, that it does an exact match on list items. You could use the switch
function instead. Which supports wild-card matching.
function code
set -l result (dirh)
switch $result
case '*sfk*'
cd ~/rails
case '*afk*'
cd ~/code
case '*'
echo $result
end
end