I defined several helper functions that I only use in one specific fish script. I put them inside the wrapper function but you can still find them via autocompletion.
How can I hide them from auto completion and limit their scope to private
?
function outer
function inner_func
echo "I still find this function via automplete"
end
end
Fish does not have private functions, but it is possible this feature will be available in future versions. In the meantime, try using the following technique, a naming convention, or both.
functions -e function_name
Very close to what you need. You can use functions -e function_name
before the end of the block to erase it from the global scope.
function outer
function inner_func
echo "I still find this function via automplete."
echo "Not anymore!!"
functions -e inner_func
end
# Let's test this!
inner_func
end
$ outer
I still find this function via automplete.
Not anymore!!
$ inner_func
fish: Unknown command 'inner_func'
_my_module_func_name
This does not erase the function from the global scope, but it is a general good practice to avoid overriding existing functions unintentionally.
Functions declared inside a main function file (or functions inside other functions like inner_func
) will be available only after its parent function is invoked at least once (this is fish lazy function autoloading), and exist only for the duration of that particular shell session.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With